diff --git a/.ci/AppImageBuilder.yml b/.ci/AppImageBuilder.yml index 11a41394a..86184518c 100644 --- a/.ci/AppImageBuilder.yml +++ b/.ci/AppImageBuilder.yml @@ -57,7 +57,7 @@ AppDir: - libqt5gui5 # if QT:BOOL=ON - libqt5widgets5 # if QT:BOOL=ON - libsixel1 # if CLI:BOOL=ON - - libslirp0 # if SLIRP_EXTERNAL:BOOL=ON + - libslirp0 - libsndio7.0 # if OPENAL:BOOL=ON - libvdeplug-dev # -dev also pulls in libvdeplug2. -dev is required to get the proper .so symlink to the library - libx11-6 # if QT:BOOL=ON diff --git a/.ci/build.sh b/.ci/build.sh index cf420d4dd..0aa6a499d 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -670,9 +670,6 @@ EOF else echo [-] Not installing dependencies again fi - - # Link against the system libslirp instead of compiling ours. - cmake_flags_extra="$cmake_flags_extra -D SLIRP_EXTERNAL=ON" fi # Point CMake to the toolchain file. diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5f703a65f..12d278e8f 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -263,7 +263,7 @@ jobs: build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Run sonar-scanner -# if: 0 + if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -445,7 +445,7 @@ jobs: build-wrapper-macosx-x86 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build - name: Run sonar-scanner -# if: 0 + if: 0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 8070ff263..8af57ca9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,10 +30,6 @@ if(NOT DEFINED OPENAL OR OPENAL) list(APPEND VCPKG_MANIFEST_FEATURES "openal") endif() -if(SLIRP_EXTERNAL) - list(APPEND VCPKG_MANIFEST_FEATURES "slirp") -endif() - if(MUNT_EXTERNAL) list(APPEND VCPKG_MANIFEST_FEATURES "munt") endif() diff --git a/README.md b/README.md index fb35f0218..a1e1b4432 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ 86Box ===== + [![Build Status](https://ci.86box.net/job/86Box/badge/icon)](https://ci.86box.net/job/86Box/) **86Box** is a low level x86 emulator that runs older operating systems and software designed for IBM PC systems and compatibles from 1981 through fairly recent system designs based on the PCI bus. Features -------- + * Easy to use interface inspired by mainstream hypervisor software -* Low level emulation of 8086-based processors up to the Pentium with focus on accuracy +* Low level emulation of 8086-based processors up to the Mendocino-era Celeron with focus on accuracy * Great range of customizability of virtual machines * Many available systems, such as the very first IBM PC 5150 from 1981, or the more obscure IBM PS/2 line of systems based on the Micro Channel Architecture * Lots of supported peripherals including video adapters, sound cards, network adapters, hard disk controllers, and SCSI adapters @@ -16,15 +18,17 @@ Features Minimum system requirements and recommendations ----------------------------------------------- -* Intel Core 2 or AMD Athlon 64 processor -* Windows version: Windows 7 Service Pack 1, Windows 8.1 or Windows 10 + +* Intel Core 2 or AMD Athlon 64 processor or newer +* Windows version: Windows 7 Service Pack 1 or later * Linux version: Ubuntu 16.04, Debian 9.0 or other distributions from 2016 onwards -* macOS version: macOS High Sierra 10.13 -* 4 GB of RAM +* macOS version: macOS High Sierra 10.13 or newer +* 4 GB of RAM or higher Performance may vary depending on both host and guest configuration. Most emulation logic is executed in a single thread; therefore, systems with better IPC (instructions per clock) generally should be able to emulate higher clock speeds. It is also recommended to use a manager application with 86Box for easier handling of multiple virtual machines. + * [86Box Manager](https://github.com/86Box/86BoxManager) by [Overdoze](https://github.com/daviunic) (Windows only) * [86Box Manager Lite](https://github.com/insanemal/86box_manager_py) by [Insanemal](https://github.com/insanemal) * [WinBox for 86Box](https://github.com/86Box/WinBox-for-86Box) by Laci bá' (Windows only) @@ -35,10 +39,12 @@ It is also possible to use 86Box on its own with the `--vmpath`/`-P` command lin Getting started --------------- + See [our documentation](https://86box.readthedocs.io/en/latest/index.html) for an overview of the emulator's features and user interface. Community --------- + We operate an IRC channel and a Discord server for discussing 86Box, its development and anything related to retro computing. We look forward to hearing from you! [![Visit our IRC channel](https://kiwiirc.com/buttons/irc.ringoflightning.net/86Box.png)](https://kiwiirc.com/client/irc.ringoflightning.net/?nick=86box|?#86Box) @@ -47,16 +53,19 @@ We operate an IRC channel and a Discord server for discussing 86Box, its develop Contributions --------- + We welcome all contributions to the project, as long as the [contribution guidelines](CONTRIBUTING.md) are followed. Licensing --------- + 86Box is released under the [GNU General Public License, version 2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) or later. For more information, see the `COPYING` file in the root of the repository. The emulator can also optionally make use of [munt](https://github.com/munt/munt), [FluidSynth](https://www.fluidsynth.org/), [Ghostscript](https://www.ghostscript.com/) and [Discord Game SDK](https://discord.com/developers/docs/game-sdk/sdk-starter-guide), which are distributed under their respective licenses. Donations --------- + We do not charge you for the emulator but donations are still welcome: https://paypal.me/86Box. diff --git a/debian/rules b/debian/rules index f01d81dcd..7b0605e72 100644 --- a/debian/rules +++ b/debian/rules @@ -25,7 +25,7 @@ endif dh $@ --buildsystem cmake+ninja override_dh_auto_configure: - dh_auto_configure --buildsystem cmake+ninja -- --preset regular --toolchain $(TOOLCHAIN) -DNEW_DYNAREC=$(NDR) -DSLIRP_EXTERNAL=on + dh_auto_configure --buildsystem cmake+ninja -- --preset regular --toolchain $(TOOLCHAIN) -DNEW_DYNAREC=$(NDR) override_dh_auto_test: diff --git a/src/86box.c b/src/86box.c index 8db2fc75a..3a1ad179b 100644 --- a/src/86box.c +++ b/src/86box.c @@ -408,18 +408,18 @@ pc_log(const char *fmt, ...) int pc_init(int argc, char *argv[]) { - char *ppath = NULL; - char *rpath = NULL; - char *cfg = NULL; - char *p; - char temp[2048]; - char *fn[FDD_NUM] = { NULL }; - char drive = 0; - char *temp2 = NULL; - struct tm *info; - time_t now; - int c; - int lvmp = 0; + char *ppath = NULL; + char *rpath = NULL; + char *cfg = NULL; + char *p; + char temp[2048]; + char *fn[FDD_NUM] = { NULL }; + char drive = 0; + char *temp2 = NULL; + const struct tm *info; + time_t now; + int c; + int lvmp = 0; #ifdef ENABLE_NG int ng = 0; #endif @@ -1144,9 +1144,9 @@ pc_reset_hard_init(void) void update_mouse_msg(void) { - wchar_t wcpufamily[2048]; - wchar_t wcpu[2048]; - wchar_t wmachine[2048]; + wchar_t wcpufamily[2048]; + wchar_t wcpu[2048]; + wchar_t wmachine[2048]; wchar_t *wcp; mbstowcs(wmachine, machine_getname(), strlen(machine_getname()) + 1); @@ -1185,7 +1185,7 @@ pc_reset_hard(void) } void -pc_close(thread_t *ptr) +pc_close(UNUSED(thread_t *ptr)) { /* Wait a while so things can shut down. */ plat_delay_ms(200); diff --git a/src/acpi.c b/src/acpi.c index 495419f4e..157e3cadd 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -226,10 +226,10 @@ acpi_reg_read_common_regs(UNUSED(int size), uint16_t addr, void *priv) static uint32_t acpi_reg_read_ali(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) priv; - uint32_t ret = 0x00000000; - int shift16; - int shift32; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; + int shift32; addr &= 0x3f; shift16 = (addr & 1) << 3; @@ -294,10 +294,10 @@ acpi_reg_read_ali(int size, uint16_t addr, void *priv) static uint32_t acpi_reg_read_intel(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) priv; - uint32_t ret = 0x00000000; - int shift16; - int shift32; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; + int shift32; addr &= 0x3f; shift16 = (addr & 1) << 3; @@ -391,10 +391,10 @@ acpi_reg_read_intel(int size, uint16_t addr, void *priv) static uint32_t acpi_reg_read_via_common(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) priv; - uint32_t ret = 0x00000000; - int shift16; - int shift32; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; + int shift32; addr &= 0xff; shift16 = (addr & 1) << 3; @@ -544,10 +544,10 @@ acpi_reg_read_via(int size, uint16_t addr, void *priv) static uint32_t acpi_reg_read_via_596b(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) priv; - uint32_t ret = 0x00000000; - int shift16; - int shift32; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; + int shift32; addr &= 0x7f; shift16 = (addr & 1) << 3; @@ -610,9 +610,9 @@ acpi_reg_read_smc(int size, uint16_t addr, void *priv) static uint32_t acpi_aux_reg_read_smc(UNUSED(int size), uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) priv; - uint32_t ret = 0x00000000; - int shift16; + const acpi_t *dev = (acpi_t *) priv; + uint32_t ret = 0x00000000; + int shift16; addr &= 0x07; shift16 = (addr & 1) << 3; @@ -1189,7 +1189,7 @@ acpi_aux_reg_write_smc(UNUSED(int size), uint16_t addr, uint8_t val, void *priv) static uint32_t acpi_reg_read_common(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) priv; + const acpi_t *dev = (acpi_t *) priv; uint8_t ret = 0xff; if (dev->vendor == VEN_ALI) @@ -1209,7 +1209,7 @@ acpi_reg_read_common(int size, uint16_t addr, void *priv) static void acpi_reg_write_common(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) priv; + const acpi_t *dev = (acpi_t *) priv; if (dev->vendor == VEN_ALI) acpi_reg_write_ali(size, addr, val, priv); @@ -1226,7 +1226,7 @@ acpi_reg_write_common(int size, uint16_t addr, uint8_t val, void *priv) static uint32_t acpi_aux_reg_read_common(int size, uint16_t addr, void *priv) { - acpi_t *dev = (acpi_t *) priv; + const acpi_t *dev = (acpi_t *) priv; uint8_t ret = 0xff; if (dev->vendor == VEN_SMC) @@ -1238,7 +1238,7 @@ acpi_aux_reg_read_common(int size, uint16_t addr, void *priv) static void acpi_aux_reg_write_common(int size, uint16_t addr, uint8_t val, void *priv) { - acpi_t *dev = (acpi_t *) priv; + const acpi_t *dev = (acpi_t *) priv; if (dev->vendor == VEN_SMC) acpi_aux_reg_write_smc(size, addr, val, priv); @@ -1591,8 +1591,8 @@ acpi_apm_out(uint16_t port, uint8_t val, void *priv) static uint8_t acpi_apm_in(uint16_t port, void *priv) { - acpi_t *dev = (acpi_t *) priv; - uint8_t ret = 0xff; + const acpi_t *dev = (acpi_t *) priv; + uint8_t ret = 0xff; port &= 0x0001; @@ -1694,7 +1694,7 @@ acpi_init(const device_t *info) dev = (acpi_t *) malloc(sizeof(acpi_t)); if (dev == NULL) - return (NULL); + return NULL; memset(dev, 0x00, sizeof(acpi_t)); cpu_to_acpi = ACPI_TIMER_FREQ / cpuclock; @@ -1723,6 +1723,7 @@ acpi_init(const device_t *info) dev->suspend_types[2] = SUS_SUSPEND | SUS_NVR | SUS_RESET_CPU | SUS_RESET_PCI; dev->suspend_types[3] = SUS_SUSPEND; dev->suspend_types[5] = SUS_POWER_OFF; /* undocumented, used for S4/S5 by ASUS P5A ACPI table */ + dev->suspend_types[7] = SUS_POWER_OFF; /* undocumented, used for S5 by Gigabyte GA-5AX ACPI table */ break; case VEN_VIA: diff --git a/src/apm.c b/src/apm.c index 8ea3f435d..d7ce262a3 100644 --- a/src/apm.c +++ b/src/apm.c @@ -71,8 +71,8 @@ apm_out(uint16_t port, uint8_t val, void *priv) static uint8_t apm_in(uint16_t port, void *priv) { - apm_t *dev = (apm_t *) priv; - uint8_t ret = 0xff; + const apm_t *dev = (apm_t *) priv; + uint8_t ret = 0xff; port &= 0x0001; @@ -102,9 +102,8 @@ apm_close(void *priv) free(dev); } -static void - * - apm_init(const device_t *info) +static void * +apm_init(const device_t *info) { apm_t *dev = (apm_t *) malloc(sizeof(apm_t)); memset(dev, 0, sizeof(apm_t)); diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index d7cd6f734..3ca7e6885 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -163,7 +163,7 @@ cdrom_interface_get_from_internal_name(char *s) int c = 0; while (controllers[c].device != NULL) { - if (!strcmp((char *) controllers[c].device->internal_name, s)) + if (!strcmp(controllers[c].device->internal_name, s)) return c; c++; } diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c index 7dae28bf4..e94668d75 100644 --- a/src/cdrom/cdrom_image_backend.c +++ b/src/cdrom/cdrom_image_backend.c @@ -202,7 +202,7 @@ track_file_close(track_t *trk) static void cdi_clear_tracks(cd_img_t *cdi) { - track_file_t *last = NULL; + const track_file_t *last = NULL; track_t *cur = NULL; if ((cdi->tracks == NULL) || (cdi->tracks_num == 0)) @@ -273,7 +273,7 @@ cdi_get_audio_tracks_lba(cd_img_t *cdi, int *st_track, int *end, uint32_t *lead_ int cdi_get_audio_track_pre(cd_img_t *cdi, int track) { - track_t *trk = &cdi->tracks[track - 1]; + const track_t *trk = &cdi->tracks[track - 1]; if ((track < 1) || (track > cdi->tracks_num)) return 0; @@ -285,7 +285,7 @@ cdi_get_audio_track_pre(cd_img_t *cdi, int track) int cdi_get_audio_track_info(cd_img_t *cdi, UNUSED(int end), int track, int *track_num, TMSF *start, uint8_t *attr) { - track_t *trk = &cdi->tracks[track - 1]; + const track_t *trk = &cdi->tracks[track - 1]; int pos = trk->start + 150; if ((track < 1) || (track > cdi->tracks_num)) @@ -304,7 +304,7 @@ cdi_get_audio_track_info(cd_img_t *cdi, UNUSED(int end), int track, int *track_n int cdi_get_audio_track_info_lba(cd_img_t *cdi, UNUSED(int end), int track, int *track_num, uint32_t *start, uint8_t *attr) { - track_t *trk = &cdi->tracks[track - 1]; + const track_t *trk = &cdi->tracks[track - 1]; if ((track < 1) || (track > cdi->tracks_num)) return 0; @@ -320,8 +320,8 @@ cdi_get_audio_track_info_lba(cd_img_t *cdi, UNUSED(int end), int track, int *tra int cdi_get_track(cd_img_t *cdi, uint32_t sector) { - track_t *cur; - track_t *next; + const track_t *cur; + const track_t *next; /* There must be at least two tracks - data and lead out. */ if (cdi->tracks_num < 2) @@ -343,8 +343,8 @@ cdi_get_track(cd_img_t *cdi, uint32_t sector) int cdi_get_audio_sub(cd_img_t *cdi, uint32_t sector, uint8_t *attr, uint8_t *track, uint8_t *index, TMSF *rel_pos, TMSF *abs_pos) { - int cur_track = cdi_get_track(cdi, sector); - track_t *trk; + int cur_track = cdi_get_track(cdi, sector); + const track_t *trk; if (cur_track < 1) return 0; @@ -483,8 +483,8 @@ cdi_read_sector_sub(cd_img_t *cdi, uint8_t *buffer, uint32_t sector) int cdi_get_sector_size(cd_img_t *cdi, uint32_t sector) { - int track = cdi_get_track(cdi, sector) - 1; - track_t *trk; + int track = cdi_get_track(cdi, sector) - 1; + const track_t *trk; if (track < 0) return 0; @@ -496,8 +496,8 @@ cdi_get_sector_size(cd_img_t *cdi, uint32_t sector) int cdi_is_mode2(cd_img_t *cdi, uint32_t sector) { - int track = cdi_get_track(cdi, sector) - 1; - track_t *trk; + int track = cdi_get_track(cdi, sector) - 1; + const track_t *trk; if (track < 0) return 0; @@ -510,8 +510,8 @@ cdi_is_mode2(cd_img_t *cdi, uint32_t sector) int cdi_get_mode2_form(cd_img_t *cdi, uint32_t sector) { - int track = cdi_get_track(cdi, sector) - 1; - track_t *trk; + int track = cdi_get_track(cdi, sector) - 1; + const track_t *trk; if (track < 0) return 0; @@ -652,7 +652,9 @@ cdi_cue_get_buffer(char *str, char **line, int up) done = 1; break; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif default: if (up && islower((int) *s)) @@ -787,7 +789,7 @@ cdi_add_track(cd_img_t *cdi, track_t *cur, uint64_t *shift, uint64_t prestart, u *total_pregap += cur_pregap; cur->start += *total_pregap; } else { - temp = prev->file->get_length(prev->file) - ((uint64_t) prev->skip); + temp = prev->file->get_length(prev->file) - (prev->skip); prev->length = temp / ((uint64_t) prev->sector_size); if ((temp % prev->sector_size) != 0) prev->length++; diff --git a/src/cdrom/cdrom_image_viso.c b/src/cdrom/cdrom_image_viso.c index e1625c5e3..45182481d 100644 --- a/src/cdrom/cdrom_image_viso.c +++ b/src/cdrom/cdrom_image_viso.c @@ -370,7 +370,7 @@ viso_fill_fn_rr(uint8_t *data, const viso_entry_t *entry, size_t max_len) /* Relocate extension if the original name exceeds the maximum length. */ if (!S_ISDIR(entry->stats.st_mode)) { /* do this on files only */ - char *ext = strrchr(entry->basename, '.'); + const char *ext = strrchr(entry->basename, '.'); if (ext > entry->basename) { len = strlen(ext); if (len >= max_len) @@ -401,7 +401,7 @@ viso_fill_fn_joliet(uint8_t *data, const viso_entry_t *entry, size_t max_len) /* /* Relocate extension if the original name exceeds the maximum length. */ if (!S_ISDIR(entry->stats.st_mode)) { /* do this on files only */ - wchar_t *ext = wcsrchr(utf8dec, L'.'); + const wchar_t *ext = wcsrchr(utf8dec, L'.'); if (ext > utf8dec) { len = wcslen(ext); if (len > max_len) @@ -725,8 +725,9 @@ viso_read(void *p, uint8_t *buffer, uint64_t seek, size_t count) uint64_t viso_get_length(void *p) { - track_file_t *tf = (track_file_t *) p; - viso_t *viso = (viso_t *) tf->priv; + track_file_t *tf = (track_file_t *) p; + const viso_t *viso = (viso_t *) tf->priv; + return ((uint64_t) viso->all_sectors) * viso->sector_size; } @@ -799,18 +800,18 @@ viso_init(const char *dirname, int *error) /* Set up directory traversal. */ cdrom_image_viso_log("VISO: Traversing directories:\n"); - viso_entry_t *entry; - viso_entry_t *last_entry; - viso_entry_t *dir; - viso_entry_t *last_dir; - viso_entry_t *eltorito_dir = NULL; - viso_entry_t *eltorito_entry = NULL; - struct dirent *readdir_entry; - int len; - int eltorito_others_present = 0; - size_t dir_path_len; - uint64_t eltorito_offset = 0; - uint8_t eltorito_type = 0; + viso_entry_t *entry; + viso_entry_t *last_entry; + viso_entry_t *dir; + viso_entry_t *last_dir; + const viso_entry_t *eltorito_dir = NULL; + const viso_entry_t *eltorito_entry = NULL; + struct dirent *readdir_entry; + int len; + int eltorito_others_present = 0; + size_t dir_path_len; + uint64_t eltorito_offset = 0; + uint8_t eltorito_type = 0; /* Fill root directory entry. */ dir_path_len = strlen(dirname); diff --git a/src/cdrom/cdrom_mitsumi.c b/src/cdrom/cdrom_mitsumi.c index 079ae3556..6c015fa9d 100644 --- a/src/cdrom/cdrom_mitsumi.c +++ b/src/cdrom/cdrom_mitsumi.c @@ -324,6 +324,9 @@ mitsumi_cdrom_out(uint16_t port, uint8_t val, void *priv) break; case 5: dev->readmsf = 0; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 4: case 3: dev->readmsf |= CD_DCB(val) << ((dev->cmdrd_count - 3) << 3); diff --git a/src/chipset/82c100.c b/src/chipset/82c100.c index abac4b618..689234ebb 100644 --- a/src/chipset/82c100.c +++ b/src/chipset/82c100.c @@ -109,7 +109,7 @@ ct_82c100_ems_out(uint16_t port, uint8_t val, void *priv) static uint8_t ct_82c100_ems_in(uint16_t port, void *priv) { - ct_82c100_t *dev = (ct_82c100_t *) priv; + const ct_82c100_t *dev = (ct_82c100_t *) priv; uint8_t ret = 0xff; ret = dev->ems_page_regs[port >> 14]; @@ -278,15 +278,15 @@ ct_82c100_in(uint16_t port, void *priv) static uint8_t mem_read_emsb(uint32_t addr, void *priv) { - ems_page_t *page = (ems_page_t *) priv; - uint8_t ret = 0xff; + const ems_page_t *page = (ems_page_t *) priv; + uint8_t ret = 0xff; #ifdef ENABLE_CT_82C100_LOG uint32_t old_addr = addr; #endif addr = addr - page->virt + page->phys; - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = ram[addr]; ct_82c100_log("mem_read_emsb(%08X = %08X): %02X\n", old_addr, addr, ret); @@ -297,7 +297,7 @@ mem_read_emsb(uint32_t addr, void *priv) static uint16_t mem_read_emsw(uint32_t addr, void *priv) { - ems_page_t *page = (ems_page_t *) priv; + const ems_page_t *page = (ems_page_t *) priv; uint16_t ret = 0xffff; #ifdef ENABLE_CT_82C100_LOG uint32_t old_addr = addr; @@ -305,7 +305,7 @@ mem_read_emsw(uint32_t addr, void *priv) addr = addr - page->virt + page->phys; - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = *(uint16_t *) &ram[addr]; ct_82c100_log("mem_read_emsw(%08X = %08X): %04X\n", old_addr, addr, ret); @@ -316,14 +316,14 @@ mem_read_emsw(uint32_t addr, void *priv) static void mem_write_emsb(uint32_t addr, uint8_t val, void *priv) { - ems_page_t *page = (ems_page_t *) priv; + const ems_page_t *page = (ems_page_t *) priv; #ifdef ENABLE_CT_82C100_LOG uint32_t old_addr = addr; #endif addr = addr - page->virt + page->phys; - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ram[addr] = val; ct_82c100_log("mem_write_emsb(%08X = %08X, %02X)\n", old_addr, addr, val); @@ -332,14 +332,14 @@ mem_write_emsb(uint32_t addr, uint8_t val, void *priv) static void mem_write_emsw(uint32_t addr, uint16_t val, void *priv) { - ems_page_t *page = (ems_page_t *) priv; + const ems_page_t *page = (ems_page_t *) priv; #ifdef ENABLE_CT_82C100_LOG uint32_t old_addr = addr; #endif addr = addr - page->virt + page->phys; - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) *(uint16_t *) &ram[addr] = val; ct_82c100_log("mem_write_emsw(%08X = %08X, %04X)\n", old_addr, addr, val); diff --git a/src/chipset/acc2168.c b/src/chipset/acc2168.c index 6f58cd8c2..9ce29bdff 100644 --- a/src/chipset/acc2168.c +++ b/src/chipset/acc2168.c @@ -168,7 +168,7 @@ acc2168_write(uint16_t addr, uint8_t val, void *priv) static uint8_t acc2168_read(uint16_t addr, void *priv) { - acc2168_t *dev = (acc2168_t *) priv; + const acc2168_t *dev = (acc2168_t *) priv; return (addr == 0xf3) ? dev->regs[dev->reg_idx] : dev->reg_idx; } diff --git a/src/chipset/ali1429.c b/src/chipset/ali1429.c index c91e2dd4b..34c3e18c2 100644 --- a/src/chipset/ali1429.c +++ b/src/chipset/ali1429.c @@ -280,8 +280,8 @@ ali1429_write(uint16_t addr, uint8_t val, void *priv) static uint8_t ali1429_read(uint16_t addr, void *priv) { - ali1429_t *dev = (ali1429_t *) priv; - uint8_t ret = 0xff; + const ali1429_t *dev = (ali1429_t *) priv; + uint8_t ret = 0xff; if ((addr == 0x23) && (dev->index >= 0x10) && (dev->index <= 0x4a)) ret = dev->regs[dev->index]; diff --git a/src/chipset/ali1435.c b/src/chipset/ali1435.c index c2ff89abb..72595cf84 100644 --- a/src/chipset/ali1435.c +++ b/src/chipset/ali1435.c @@ -166,8 +166,8 @@ ali1435_pci_write(int func, int addr, uint8_t val, void *priv) static uint8_t ali1435_pci_read(int func, int addr, void *priv) { - ali1435_t *dev = (ali1435_t *) priv; - uint8_t ret; + const ali1435_t *dev = (ali1435_t *) priv; + uint8_t ret; ret = 0xff; @@ -233,8 +233,8 @@ ali1435_write(uint16_t addr, uint8_t val, void *priv) static uint8_t ali1435_read(uint16_t addr, void *priv) { - ali1435_t *dev = (ali1435_t *) priv; - uint8_t ret = 0xff; + const ali1435_t *dev = (ali1435_t *) priv; + uint8_t ret = 0xff; if ((addr == 0x23) && (dev->index < 0x10)) ret = dev->regs[dev->index]; diff --git a/src/chipset/ali1489.c b/src/chipset/ali1489.c index c4488ffd6..1b2087e4d 100644 --- a/src/chipset/ali1489.c +++ b/src/chipset/ali1489.c @@ -213,7 +213,7 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) ali1489_t *dev = (ali1489_t *) priv; uint8_t old; uint8_t irq; - const uint8_t irq_array[16] = { 0, 3, 4, 7, 0, 0, 0, 0, 9, 10, 5, 6, 11, 12, 14, 15 }; + const uint8_t irq_array[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 0, 11, 0, 12, 0, 14, 0, 15 }; switch (addr) { case 0x22: @@ -408,8 +408,8 @@ ali1489_write(uint16_t addr, uint8_t val, void *priv) static uint8_t ali1489_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - ali1489_t *dev = (ali1489_t *) priv; + uint8_t ret = 0xff; + const ali1489_t *dev = (ali1489_t *) priv; switch (addr) { case 0x23: @@ -456,8 +456,8 @@ ali1489_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) static uint8_t ali1489_pci_read(UNUSED(int func), int addr, void *priv) { - ali1489_t *dev = (ali1489_t *) priv; - uint8_t ret = 0xff; + const ali1489_t *dev = (ali1489_t *) priv; + uint8_t ret = 0xff; ret = dev->pci_conf[addr]; ali1489_log("M1489-PCI: dev->pci_conf[%02x] (%02x)\n", addr, ret); @@ -560,8 +560,8 @@ ali1489_ide_write(uint16_t addr, uint8_t val, void *priv) static uint8_t ali1489_ide_read(uint16_t addr, void *priv) { - ali1489_t *dev = (ali1489_t *) priv; - uint8_t ret = 0xff; + const ali1489_t *dev = (ali1489_t *) priv; + uint8_t ret = 0xff; switch (addr) { case 0xf4: diff --git a/src/chipset/ali1531.c b/src/chipset/ali1531.c index 20be9857c..3812e4ca4 100644 --- a/src/chipset/ali1531.c +++ b/src/chipset/ali1531.c @@ -303,8 +303,8 @@ ali1531_write(UNUSED(int func), int addr, uint8_t val, void *priv) static uint8_t ali1531_read(UNUSED(int func), int addr, void *priv) { - ali1531_t *dev = (ali1531_t *) priv; - uint8_t ret = 0xff; + const ali1531_t *dev = (ali1531_t *) priv; + uint8_t ret = 0xff; ret = dev->pci_conf[addr]; diff --git a/src/chipset/ali1541.c b/src/chipset/ali1541.c index 5d8db1547..55cf5d25d 100644 --- a/src/chipset/ali1541.c +++ b/src/chipset/ali1541.c @@ -560,8 +560,8 @@ ali1541_write(UNUSED(int func), int addr, uint8_t val, void *priv) static uint8_t ali1541_read(UNUSED(int func), int addr, void *priv) { - ali1541_t *dev = (ali1541_t *) priv; - uint8_t ret = 0xff; + const ali1541_t *dev = (ali1541_t *) priv; + uint8_t ret = 0xff; ret = dev->pci_conf[addr]; diff --git a/src/chipset/ali1543.c b/src/chipset/ali1543.c index f0c1347db..cefaa4f0d 100644 --- a/src/chipset/ali1543.c +++ b/src/chipset/ali1543.c @@ -895,7 +895,7 @@ ali5229_write(int func, int addr, uint8_t val, void *priv) static uint8_t ali5229_read(int func, int addr, void *priv) { - ali1543_t *dev = (ali1543_t *) priv; + const ali1543_t *dev = (ali1543_t *) priv; uint8_t ret = 0xff; if (dev->ide_dev_enable && (func == 0)) { @@ -983,7 +983,7 @@ ali5237_write(int func, int addr, uint8_t val, void *priv) static uint8_t ali5237_read(int func, int addr, void *priv) { - ali1543_t *dev = (ali1543_t *) priv; + const ali1543_t *dev = (ali1543_t *) priv; uint8_t ret = 0xff; if (dev->usb_dev_enable && (func == 0)) @@ -1474,7 +1474,7 @@ ali7101_read(int func, int addr, void *priv) static void ali5237_usb_update_interrupt(usb_t* usb, void *priv) { - ali1543_t *dev = (ali1543_t *) priv; + const ali1543_t *dev = (ali1543_t *) priv; if (usb->irq_level) pci_set_mirq(4, !!(dev->pci_conf[0x74] & 0x10)); diff --git a/src/chipset/ali1621.c b/src/chipset/ali1621.c index 73b65d801..b927d3e34 100644 --- a/src/chipset/ali1621.c +++ b/src/chipset/ali1621.c @@ -28,6 +28,7 @@ #include <86box/io.h> #include <86box/mem.h> #include <86box/pci.h> +#include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> #include <86box/smram.h> #include <86box/spd.h> @@ -108,7 +109,9 @@ ali1621_smram_recalc(uint8_t val, ali1621_t *dev) switch (val & 0x30) { case 0x10: /* Open. */ access_normal = ACCESS_SMRAM_RX; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x30: /* Protect. */ access_smm |= ACCESS_SMRAM_R; break; @@ -121,7 +124,9 @@ ali1621_smram_recalc(uint8_t val, ali1621_t *dev) switch (val & 0x30) { case 0x10: /* Open. */ access_normal |= ACCESS_SMRAM_W; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x30: /* Protect. */ access_smm |= ACCESS_SMRAM_W; break; @@ -579,8 +584,8 @@ ali1621_write(UNUSED(int func), int addr, uint8_t val, void *priv) static uint8_t ali1621_read(UNUSED(int func), int addr, void *priv) { - ali1621_t *dev = (ali1621_t *) priv; - uint8_t ret = 0xff; + const ali1621_t *dev = (ali1621_t *) priv; + uint8_t ret = 0xff; ret = dev->pci_conf[addr]; diff --git a/src/chipset/ali6117.c b/src/chipset/ali6117.c index 433316c50..78705ee26 100644 --- a/src/chipset/ali6117.c +++ b/src/chipset/ali6117.c @@ -33,6 +33,7 @@ #include <86box/hdc.h> #include <86box/hdc_ide.h> #include <86box/chipset.h> +#include <86box/plat_fallthrough.h> typedef struct ali6117_t { uint32_t local; @@ -233,7 +234,9 @@ ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) case 0x12: val &= 0xf7; - /* FALL-THROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x14: case 0x15: @@ -388,7 +391,7 @@ ali6117_reg_write(uint16_t addr, uint8_t val, void *priv) static uint8_t ali6117_reg_read(uint16_t addr, void *priv) { - ali6117_t *dev = (ali6117_t *) priv; + const ali6117_t *dev = (ali6117_t *) priv; uint8_t ret; if (addr == 0x22) diff --git a/src/chipset/cs4031.c b/src/chipset/cs4031.c index b4e62b8f5..fb439ec3a 100644 --- a/src/chipset/cs4031.c +++ b/src/chipset/cs4031.c @@ -148,7 +148,7 @@ cs4031_write(uint16_t addr, uint8_t val, void *priv) static uint8_t cs4031_read(uint16_t addr, void *priv) { - cs4031_t *dev = (cs4031_t *) priv; + const cs4031_t *dev = (cs4031_t *) priv; return (addr == 0x23) ? dev->regs[dev->index] : 0xff; } diff --git a/src/chipset/cs8230.c b/src/chipset/cs8230.c index 8e5377ed2..93a7f1bba 100644 --- a/src/chipset/cs8230.c +++ b/src/chipset/cs8230.c @@ -81,8 +81,8 @@ rethink_shadow_mappings(cs8230_t *cs8230) static uint8_t cs8230_read(uint16_t port, void *priv) { - cs8230_t *cs8230 = (cs8230_t *) priv; - uint8_t ret = 0xff; + const cs8230_t *cs8230 = (cs8230_t *) priv; + uint8_t ret = 0xff; if (port & 1) { switch (cs8230->idx) { diff --git a/src/chipset/et6000.c b/src/chipset/et6000.c index 44739c698..f2cffd7f7 100644 --- a/src/chipset/et6000.c +++ b/src/chipset/et6000.c @@ -121,7 +121,7 @@ et6000_write(uint16_t addr, uint8_t val, void *priv) static uint8_t et6000_read(uint16_t addr, void *priv) { - et6000_t *dev = (et6000_t *) priv; + const et6000_t *dev = (et6000_t *) priv; return ((addr == 0x23) && (INDEX >= 0) && (INDEX <= 5)) ? dev->regs[INDEX] : 0xff; } diff --git a/src/chipset/gc100.c b/src/chipset/gc100.c index a6616ea29..0b4717903 100644 --- a/src/chipset/gc100.c +++ b/src/chipset/gc100.c @@ -145,9 +145,9 @@ gc100_write(uint16_t port, uint8_t val, void *priv) static uint8_t gc100_read(uint16_t port, void *priv) { - gc100_t *dev = (gc100_t *) priv; - uint8_t ret = 0xff; - uint16_t addr = port & 0xf; + const gc100_t *dev = (gc100_t *) priv; + uint8_t ret = 0xff; + uint16_t addr = port & 0xf; ret = dev->reg[addr]; diff --git a/src/chipset/headland.c b/src/chipset/headland.c index 30ee44b0f..db5922470 100644 --- a/src/chipset/headland.c +++ b/src/chipset/headland.c @@ -165,7 +165,7 @@ get_addr(headland_t *dev, uint32_t addr, headland_mr_t *mr) static void hl_ems_disable(headland_t *dev, uint8_t mar, uint32_t base_addr, uint8_t indx) { - if (base_addr < ((uint32_t) mem_size << 10)) + if (base_addr < (mem_size << 10)) mem_mapping_set_exec(&dev->ems_mapping[mar & 0x3f], ram + base_addr); else mem_mapping_set_exec(&dev->ems_mapping[mar & 0x3f], NULL); @@ -197,7 +197,7 @@ hl_ems_update(headland_t *dev, uint8_t mar) dev->ems_mr[mar & 0x3f].virt_base = virt_addr; if (indx < 24) mem_mapping_disable(&dev->upper_mapping[indx]); - if (virt_addr < ((uint32_t) mem_size << 10)) + if (virt_addr < (mem_size << 10)) mem_mapping_set_exec(&dev->ems_mapping[mar & 0x3f], ram + virt_addr); else mem_mapping_set_exec(&dev->ems_mapping[mar & 0x3f], NULL); @@ -244,7 +244,7 @@ memmap_state_update(headland_t *dev) for (uint8_t i = 0; i < 24; i++) { addr = get_addr(dev, 0x40000 + (i << 14), NULL); - mem_mapping_set_exec(&dev->upper_mapping[i], addr < ((uint32_t) mem_size << 10) ? ram + addr : NULL); + mem_mapping_set_exec(&dev->upper_mapping[i], addr < (mem_size << 10) ? ram + addr : NULL); } memmap_state_default(dev, ht_romcs); @@ -513,7 +513,7 @@ mem_read_b(uint32_t addr, void *priv) uint8_t ret = 0xff; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = ram[addr]; return ret; @@ -527,7 +527,7 @@ mem_read_w(uint32_t addr, void *priv) uint16_t ret = 0xffff; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = *(uint16_t *) &ram[addr]; return ret; @@ -541,7 +541,7 @@ mem_read_l(uint32_t addr, void *priv) uint32_t ret = 0xffffffff; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ret = *(uint32_t *) &ram[addr]; return ret; @@ -554,7 +554,7 @@ mem_write_b(uint32_t addr, uint8_t val, void *priv) headland_t *dev = mr->headland; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) ram[addr] = val; } @@ -565,7 +565,7 @@ mem_write_w(uint32_t addr, uint16_t val, void *priv) headland_t *dev = mr->headland; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) *(uint16_t *) &ram[addr] = val; } @@ -576,7 +576,7 @@ mem_write_l(uint32_t addr, uint32_t val, void *priv) headland_t *dev = mr->headland; addr = get_addr(dev, addr, mr); - if (addr < ((uint32_t) mem_size << 10)) + if (addr < (mem_size << 10)) *(uint32_t *) &ram[addr] = val; } diff --git a/src/chipset/ims8848.c b/src/chipset/ims8848.c index 0da686d49..f84eb5706 100644 --- a/src/chipset/ims8848.c +++ b/src/chipset/ims8848.c @@ -327,8 +327,8 @@ ims8849_pci_write(int func, int addr, uint8_t val, void *priv) static uint8_t ims8849_pci_read(int func, int addr, void *priv) { - ims8848_t *dev = (ims8848_t *) priv; - uint8_t ret = 0xff; + const ims8848_t *dev = (ims8848_t *) priv; + uint8_t ret = 0xff; if (func == 0) ret = dev->pci_conf[addr]; diff --git a/src/chipset/intel_420ex.c b/src/chipset/intel_420ex.c index 9ab21e449..5200d8834 100644 --- a/src/chipset/intel_420ex.c +++ b/src/chipset/intel_420ex.c @@ -118,7 +118,7 @@ i420ex_smram_handler_phase0(void) static void i420ex_smram_handler_phase1(i420ex_t *dev) { - uint8_t *regs = (uint8_t *) dev->regs; + const uint8_t *regs = (uint8_t *) dev->regs; uint32_t host_base = 0x000a0000; uint32_t ram_base = 0x000a0000; @@ -165,15 +165,14 @@ i420ex_smram_handler_phase1(i420ex_t *dev) static void i420ex_drb_recalc(i420ex_t *dev) { - int i; uint32_t boundary; - for (i = 4; i >= 0; i--) + for (int8_t i = 4; i >= 0; i--) row_disable(i); - for (i = 0; i <= 4; i++) { - boundary = ((uint32_t) dev->regs[0x60 + i]) & 0xff; - row_set_boundary(i, boundary); + for (uint8_t i = 0; i <= 4; i++) { + boundary = ((uint32_t) dev->regs[0x60 + i]) & 0xff; + row_set_boundary(i, boundary); } flushmmucache(); @@ -398,8 +397,8 @@ i420ex_write(int func, int addr, uint8_t val, void *priv) static uint8_t i420ex_read(int func, int addr, void *priv) { - i420ex_t *dev = (i420ex_t *) priv; - uint8_t ret; + const i420ex_t *dev = (i420ex_t *) priv; + uint8_t ret; ret = 0xff; diff --git a/src/chipset/intel_4x0.c b/src/chipset/intel_4x0.c index 0d07914b2..c68f6218c 100644 --- a/src/chipset/intel_4x0.c +++ b/src/chipset/intel_4x0.c @@ -118,10 +118,10 @@ static void i4x0_smram_handler_phase1(i4x0_t *dev) { - uint8_t *regs = (uint8_t *) dev->regs; - uint32_t tom = (mem_size << 10); - uint8_t *reg = (dev->type >= INTEL_430LX) ? &(regs[0x72]) : &(regs[0x57]); - uint8_t *ext_reg = (dev->type >= INTEL_440BX) ? &(regs[0x73]) : &(regs[0x71]); + const uint8_t *regs = (uint8_t *) dev->regs; + uint32_t tom = (mem_size << 10); + const uint8_t *reg = (dev->type >= INTEL_430LX) ? &(regs[0x72]) : &(regs[0x57]); + const uint8_t *ext_reg = (dev->type >= INTEL_440BX) ? &(regs[0x73]) : &(regs[0x71]); uint32_t s; uint32_t base[2] = { 0x000a0000, 0x00000000 }; @@ -228,7 +228,7 @@ i4x0_mask_bar(uint8_t *regs, void *agpgart) static uint8_t pm2_cntrl_read(UNUSED(uint16_t addr), void *priv) { - i4x0_t *dev = (i4x0_t *) priv; + const i4x0_t *dev = (i4x0_t *) priv; return dev->pm2_cntrl & 0x01; } @@ -1068,6 +1068,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440ZX: case INTEL_440GX: regs[addr] = val; + break; + default: break; } @@ -1077,6 +1079,8 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) case INTEL_440BX: case INTEL_440ZX: regs[0x77] = val & 0x03; + break; + default: break; } @@ -1505,9 +1509,9 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) static uint8_t i4x0_read(int func, int addr, void *priv) { - i4x0_t *dev = (i4x0_t *) priv; - uint8_t ret = 0xff; - uint8_t *regs = (uint8_t *) dev->regs; + i4x0_t *dev = (i4x0_t *) priv; + uint8_t ret = 0xff; + const uint8_t *regs = (uint8_t *) dev->regs; if (func == 0) { ret = regs[addr]; diff --git a/src/chipset/intel_82335.c b/src/chipset/intel_82335.c index d4e62dd71..da0cc30f6 100644 --- a/src/chipset/intel_82335.c +++ b/src/chipset/intel_82335.c @@ -153,7 +153,7 @@ intel_82335_write(uint16_t addr, uint16_t val, void *priv) static uint16_t intel_82335_read(uint16_t addr, void *priv) { - intel_82335_t *dev = (intel_82335_t *) priv; + const intel_82335_t *dev = (intel_82335_t *) priv; intel_82335_log("Register %02x: Read %04x\n", addr, dev->regs[addr]); diff --git a/src/chipset/intel_i450kx.c b/src/chipset/intel_i450kx.c index eb126c80a..b81c3dde4 100644 --- a/src/chipset/intel_i450kx.c +++ b/src/chipset/intel_i450kx.c @@ -90,9 +90,9 @@ i450kx_map(i450kx_t *dev, int bus, uint32_t addr, uint32_t size, int state) static void i450kx_smram_recalc(i450kx_t *dev, int bus) { - uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; - uint32_t addr; - uint32_t size; + const uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; + uint32_t addr; + uint32_t size; smram_disable(dev->smram[bus]); @@ -112,7 +112,7 @@ i450kx_smram_recalc(i450kx_t *dev, int bus) static void i450kx_vid_buf_recalc(i450kx_t *dev, int bus) { - uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; + const uint8_t *regs = bus ? dev->pb_pci_conf : dev->mc_pci_conf; #if 0 // int state = (regs[0x58] & 0x02) ? (MEM_READ_EXTANY | MEM_WRITE_EXTANY) : (MEM_READ_DISABLED | MEM_WRITE_DISABLED); @@ -374,7 +374,7 @@ pb_write(int func, int addr, uint8_t val, void *priv) static uint8_t pb_read(int func, int addr, void *priv) { - i450kx_t *dev = (i450kx_t *) priv; + const i450kx_t *dev = (i450kx_t *) priv; uint8_t ret = 0xff; if (func == 0) @@ -601,7 +601,7 @@ mc_write(int func, int addr, uint8_t val, void *priv) static uint8_t mc_read(int func, int addr, void *priv) { - i450kx_t *dev = (i450kx_t *) priv; + const i450kx_t *dev = (i450kx_t *) priv; uint8_t ret = 0xff; if (func == 0) diff --git a/src/chipset/intel_piix.c b/src/chipset/intel_piix.c index 7ee28030c..038f35f97 100644 --- a/src/chipset/intel_piix.c +++ b/src/chipset/intel_piix.c @@ -289,7 +289,7 @@ piix_trap_io(UNUSED(int size), UNUSED(uint16_t addr), UNUSED(uint8_t write), UNU static void piix_trap_io_ide(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) { - piix_io_trap_t *trap = (piix_io_trap_t *) priv; + const piix_io_trap_t *trap = (piix_io_trap_t *) priv; /* IDE traps are per drive, not per channel. */ if (ide_drives[trap->dev_id]->selected) @@ -327,10 +327,10 @@ piix_trap_update_devctl(piix_t *dev, uint8_t trap_id, uint8_t dev_id, static void piix_trap_update(void *priv) { - piix_t *dev = (piix_t *) priv; - uint8_t trap_id = 0; - uint8_t *fregs = dev->regs[3]; - uint16_t temp; + piix_t *dev = (piix_t *) priv; + uint8_t trap_id = 0; + const uint8_t *fregs = dev->regs[3]; + uint16_t temp; piix_trap_update_devctl(dev, trap_id++, 0, 0x00000002, 1, 0x1f0, 8); piix_trap_update_devctl(dev, trap_id++, 0, 0x00000002, 1, 0x3f6, 1); @@ -1166,9 +1166,9 @@ piix_write(int func, int addr, uint8_t val, void *priv) static uint8_t piix_read(int func, int addr, void *priv) { - piix_t *dev = (piix_t *) priv; - uint8_t ret = 0xff; - uint8_t *fregs; + piix_t *dev = (piix_t *) priv; + uint8_t ret = 0xff; + const uint8_t *fregs; if ((dev->type == 3) && (func == 2) && (dev->max_func == 1) && (addr >= 0x40)) ret = 0x00; @@ -1202,8 +1202,8 @@ board_write(uint16_t port, uint8_t val, void *priv) static uint8_t board_read(uint16_t port, void *priv) { - piix_t *dev = (piix_t *) priv; - uint8_t ret = 0x64; + const piix_t *dev = (piix_t *) priv; + uint8_t ret = 0x64; if (port == 0x0078) ret = dev->board_config[0]; @@ -1446,7 +1446,7 @@ piix_fast_off_count(void *priv) static void piix_usb_update_interrupt(usb_t* usb, void *priv) { - piix_t *dev = (piix_t *) priv; + const piix_t *dev = (piix_t *) priv; if (usb->irq_level) pci_set_irq(dev->pci_slot, PCI_INTD); @@ -1457,7 +1457,7 @@ piix_usb_update_interrupt(usb_t* usb, void *priv) static void piix_reset(void *priv) { - piix_t *dev = (piix_t *) priv; + const piix_t *dev = (piix_t *) priv; if (dev->type > 3) { piix_write(3, 0x04, 0x00, priv); diff --git a/src/chipset/intel_sio.c b/src/chipset/intel_sio.c index fbfdb90fd..1dcbafe5a 100644 --- a/src/chipset/intel_sio.c +++ b/src/chipset/intel_sio.c @@ -324,8 +324,8 @@ sio_write(int func, int addr, uint8_t val, void *priv) static uint8_t sio_read(int func, int addr, void *priv) { - sio_t *dev = (sio_t *) priv; - uint8_t ret; + const sio_t *dev = (sio_t *) priv; + uint8_t ret; ret = 0xff; @@ -452,7 +452,7 @@ sio_fast_off_count(void *priv) static void sio_reset(void *priv) { - sio_t *dev = (sio_t *) priv; + const sio_t *dev = (sio_t *) priv; /* Disable the PIC mouse latch. */ sio_write(0, 0x4d, 0x40, priv); diff --git a/src/chipset/neat.c b/src/chipset/neat.c index bb13f23da..a54fc312e 100644 --- a/src/chipset/neat.c +++ b/src/chipset/neat.c @@ -349,9 +349,9 @@ ems_write(uint16_t port, uint8_t val, void *priv) static uint8_t ems_read(uint16_t port, void *priv) { - neat_t *dev = (neat_t *) priv; - uint8_t ret = 0xff; - int vpage; + const neat_t *dev = (neat_t *) priv; + uint8_t ret = 0xff; + int vpage; /* Get the viewport page number. */ vpage = (port / EMS_PGSIZE); @@ -637,8 +637,8 @@ neat_write(uint16_t port, uint8_t val, void *priv) static uint8_t neat_read(uint16_t port, void *priv) { - neat_t *dev = (neat_t *) priv; - uint8_t ret = 0xff; + const neat_t *dev = (neat_t *) priv; + uint8_t ret = 0xff; switch (port) { case 0x22: diff --git a/src/chipset/opti283.c b/src/chipset/opti283.c index 1a6b21221..865ec6ff5 100644 --- a/src/chipset/opti283.c +++ b/src/chipset/opti283.c @@ -29,6 +29,7 @@ #include <86box/io.h> #include <86box/device.h> #include <86box/mem.h> +#include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> #include <86box/chipset.h> @@ -66,7 +67,7 @@ typedef struct opti283_t { static uint8_t opti283_read_remapped_ram(uint32_t addr, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; return mem_read_ram((addr - dev->virt) + dev->phys, priv); } @@ -74,7 +75,7 @@ opti283_read_remapped_ram(uint32_t addr, void *priv) static uint16_t opti283_read_remapped_ramw(uint32_t addr, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; return mem_read_ramw((addr - dev->virt) + dev->phys, priv); } @@ -82,7 +83,7 @@ opti283_read_remapped_ramw(uint32_t addr, void *priv) static uint32_t opti283_read_remapped_raml(uint32_t addr, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; return mem_read_raml((addr - dev->virt) + dev->phys, priv); } @@ -90,7 +91,7 @@ opti283_read_remapped_raml(uint32_t addr, void *priv) static void opti283_write_remapped_ram(uint32_t addr, uint8_t val, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; mem_write_ram((addr - dev->virt) + dev->phys, val, priv); } @@ -98,7 +99,7 @@ opti283_write_remapped_ram(uint32_t addr, uint8_t val, void *priv) static void opti283_write_remapped_ramw(uint32_t addr, uint16_t val, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; mem_write_ramw((addr - dev->virt) + dev->phys, val, priv); } @@ -106,7 +107,7 @@ opti283_write_remapped_ramw(uint32_t addr, uint16_t val, void *priv) static void opti283_write_remapped_raml(uint32_t addr, uint32_t val, void *priv) { - mem_remapping_t *dev = (mem_remapping_t *) priv; + const mem_remapping_t *dev = (mem_remapping_t *) priv; mem_write_raml((addr - dev->virt) + dev->phys, val, priv); } @@ -228,7 +229,9 @@ opti283_write(uint16_t addr, uint8_t val, void *priv) case 0x14: reset_on_hlt = !!(val & 0x40); - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x11: case 0x12: case 0x13: @@ -249,8 +252,8 @@ opti283_write(uint16_t addr, uint8_t val, void *priv) static uint8_t opti283_read(uint16_t addr, void *priv) { - opti283_t *dev = (opti283_t *) priv; - uint8_t ret = 0xff; + const opti283_t *dev = (opti283_t *) priv; + uint8_t ret = 0xff; if (addr == 0x24) ret = dev->regs[dev->index]; diff --git a/src/chipset/opti291.c b/src/chipset/opti291.c index b13ceab89..6d2256974 100644 --- a/src/chipset/opti291.c +++ b/src/chipset/opti291.c @@ -122,7 +122,7 @@ opti291_write(uint16_t addr, uint8_t val, void *priv) static uint8_t opti291_read(uint16_t addr, void *priv) { - opti291_t *dev = (opti291_t *) priv; + const opti291_t *dev = (opti291_t *) priv; return (addr == 0x24) ? dev->regs[dev->index] : 0xff; } diff --git a/src/chipset/opti391.c b/src/chipset/opti391.c index 4c774a654..03cbb2ea7 100644 --- a/src/chipset/opti391.c +++ b/src/chipset/opti391.c @@ -178,8 +178,8 @@ opti391_write(uint16_t addr, uint8_t val, void *priv) static uint8_t opti391_read(uint16_t addr, void *priv) { - opti391_t *dev = (opti391_t *) priv; - uint8_t ret = 0xff; + const opti391_t *dev = (opti391_t *) priv; + uint8_t ret = 0xff; if (addr == 0x24) ret = dev->regs[dev->index]; diff --git a/src/chipset/opti495.c b/src/chipset/opti495.c index 608a4eea5..13bc2a124 100644 --- a/src/chipset/opti495.c +++ b/src/chipset/opti495.c @@ -157,8 +157,8 @@ opti495_write(uint16_t addr, uint8_t val, void *priv) static uint8_t opti495_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - opti495_t *dev = (opti495_t *) priv; + uint8_t ret = 0xff; + const opti495_t *dev = (opti495_t *) priv; switch (addr) { case 0x22: diff --git a/src/chipset/opti5x7.c b/src/chipset/opti5x7.c index 240be8241..64adacde4 100644 --- a/src/chipset/opti5x7.c +++ b/src/chipset/opti5x7.c @@ -156,7 +156,7 @@ opti5x7_write(uint16_t addr, uint8_t val, void *priv) static uint8_t opti5x7_read(uint16_t addr, void *priv) { - opti5x7_t *dev = (opti5x7_t *) priv; + const opti5x7_t *dev = (opti5x7_t *) priv; return (addr == 0x24) ? dev->regs[dev->idx] : 0xff; } diff --git a/src/chipset/opti822.c b/src/chipset/opti822.c index 6f63e55ab..73548adab 100644 --- a/src/chipset/opti822.c +++ b/src/chipset/opti822.c @@ -336,8 +336,8 @@ opti822_pci_write(int func, int addr, uint8_t val, void *priv) static uint8_t opti822_pci_read(int func, int addr, void *priv) { - opti822_t *dev = (opti822_t *) priv; - uint8_t ret; + const opti822_t *dev = (opti822_t *) priv; + uint8_t ret; ret = 0xff; diff --git a/src/chipset/opti895.c b/src/chipset/opti895.c index 9c01e2ddf..8bc93702f 100644 --- a/src/chipset/opti895.c +++ b/src/chipset/opti895.c @@ -204,8 +204,8 @@ opti895_write(uint16_t addr, uint8_t val, void *priv) static uint8_t opti895_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - opti895_t *dev = (opti895_t *) priv; + uint8_t ret = 0xff; + const opti895_t *dev = (opti895_t *) priv; switch (addr) { case 0x23: diff --git a/src/chipset/scamp.c b/src/chipset/scamp.c index 469450d4e..122318862 100644 --- a/src/chipset/scamp.c +++ b/src/chipset/scamp.c @@ -152,12 +152,12 @@ static const struct { static uint8_t ram_mirrored_256k_in_4mi_read(uint32_t addr, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank; - int byte; - int row; - int column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -183,12 +183,12 @@ ram_mirrored_256k_in_4mi_read(uint32_t addr, void *priv) static void ram_mirrored_256k_in_4mi_write(uint32_t addr, uint8_t val, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank; - int byte; - int row; - int column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -216,12 +216,12 @@ ram_mirrored_256k_in_4mi_write(uint32_t addr, uint8_t val, void *priv) static uint8_t ram_mirrored_interleaved_read(uint32_t addr, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank; - int byte; - int row; - int column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -247,12 +247,12 @@ ram_mirrored_interleaved_read(uint32_t addr, void *priv) static void ram_mirrored_interleaved_write(uint32_t addr, uint8_t val, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank; - int byte; - int row; - int column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -278,12 +278,12 @@ ram_mirrored_interleaved_write(uint32_t addr, uint8_t val, void *priv) static uint8_t ram_mirrored_read(uint32_t addr, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank; - int byte; - int row; - int column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -297,12 +297,12 @@ ram_mirrored_read(uint32_t addr, void *priv) static void ram_mirrored_write(uint32_t addr, uint8_t val, void *priv) { - ram_struct_t *rs = (ram_struct_t *) priv; - scamp_t *dev = rs->parent; - int bank = rs->bank; - int byte; - int row; - int column; + const ram_struct_t *rs = (ram_struct_t *) priv; + const scamp_t *dev = rs->parent; + int bank = rs->bank; + int byte; + int row; + int column; addr -= dev->ram_virt_base[bank]; byte = addr & 1; @@ -574,9 +574,9 @@ recalc_sltptr(scamp_t *dev) static uint8_t scamp_ems_read(uint32_t addr, void *priv) { - ems_struct_t *ems = (ems_struct_t *) priv; - scamp_t *dev = ems->parent; - int segment = ems->segment; + const ems_struct_t *ems = (ems_struct_t *) priv; + const scamp_t *dev = ems->parent; + int segment = ems->segment; addr = (addr & 0x3fff) | dev->mappings[segment]; return ram[addr]; @@ -585,9 +585,9 @@ scamp_ems_read(uint32_t addr, void *priv) static void scamp_ems_write(uint32_t addr, uint8_t val, void *priv) { - ems_struct_t *ems = (ems_struct_t *) priv; - scamp_t *dev = ems->parent; - int segment = ems->segment; + const ems_struct_t *ems = (ems_struct_t *) priv; + const scamp_t *dev = ems->parent; + int segment = ems->segment; addr = (addr & 0x3fff) | dev->mappings[segment]; ram[addr] = val; diff --git a/src/chipset/scat.c b/src/chipset/scat.c index d6c620fd1..aa0c5511a 100644 --- a/src/chipset/scat.c +++ b/src/chipset/scat.c @@ -1204,9 +1204,9 @@ scat_out(uint16_t port, uint8_t val, void *priv) static uint8_t scat_in(uint16_t port, void *priv) { - scat_t *dev = (scat_t *) priv; - uint8_t ret = 0xff; - uint8_t indx; + const scat_t *dev = (scat_t *) priv; + uint8_t ret = 0xff; + uint8_t indx; switch (port) { case 0x23: diff --git a/src/chipset/sis_5511.c b/src/chipset/sis_5511.c index d2010198a..dc2ef42e4 100644 --- a/src/chipset/sis_5511.c +++ b/src/chipset/sis_5511.c @@ -348,7 +348,8 @@ sis_5511_write(UNUSED(int func), int addr, uint8_t val, void *priv) static uint8_t sis_5511_read(UNUSED(int func), int addr, void *priv) { - sis_5511_t *dev = (sis_5511_t *) priv; + const sis_5511_t *dev = (sis_5511_t *) priv; + sis_5511_log("SiS 5511: dev->pci_conf[%02x] (%02x) POST %02x\n", addr, dev->pci_conf[addr], inb(0x80)); return dev->pci_conf[addr]; } @@ -554,7 +555,7 @@ sis_5513_write(int func, int addr, uint8_t val, void *priv) static uint8_t sis_5513_read(int func, int addr, void *priv) { - sis_5511_t *dev = (sis_5511_t *) priv; + const sis_5511_t *dev = (sis_5511_t *) priv; sis_5511_log("SiS 5513: dev->pci_conf[%02x][%02x] = %02x POST %02x\n", func, addr, dev->pci_conf_sb[func][addr], inb(0x80)); if ((func >= 0) && (func <= 1)) @@ -624,7 +625,7 @@ sis_5513_isa_write(uint16_t addr, uint8_t val, void *priv) static uint8_t sis_5513_isa_read(uint16_t addr, void *priv) { - sis_5511_t *dev = (sis_5511_t *) priv; + const sis_5511_t *dev = (sis_5511_t *) priv; if (addr == 0x23) { sis_5511_log("SiS 5513-ISA: dev->regs[%02x] (%02x) POST: %02x\n", dev->index + 0x50, dev->regs[dev->index], inb(0x80)); diff --git a/src/chipset/sis_5571.c b/src/chipset/sis_5571.c index 950146ed4..0e09de199 100644 --- a/src/chipset/sis_5571.c +++ b/src/chipset/sis_5571.c @@ -340,7 +340,8 @@ memory_pci_bridge_write(UNUSED(int func), int addr, uint8_t val, void *priv) static uint8_t memory_pci_bridge_read(UNUSED(int func), int addr, void *priv) { - sis_5571_t *dev = (sis_5571_t *) priv; + const sis_5571_t *dev = (sis_5571_t *) priv; + sis_5571_log("SiS5571: dev->pci_conf[%02x] (%02x)\n", addr, dev->pci_conf[addr]); return dev->pci_conf[addr]; } @@ -638,6 +639,7 @@ pci_isa_bridge_write(int func, int addr, uint8_t val, void *priv) break; } sis_5571_log("SiS5571-USB: dev->pci_conf[%02x] = %02x\n", addr, val); + break; default: break; @@ -647,7 +649,7 @@ pci_isa_bridge_write(int func, int addr, uint8_t val, void *priv) static uint8_t pci_isa_bridge_read(int func, int addr, void *priv) { - sis_5571_t *dev = (sis_5571_t *) priv; + const sis_5571_t *dev = (sis_5571_t *) priv; switch (func) { case 0: @@ -668,7 +670,7 @@ pci_isa_bridge_read(int func, int addr, void *priv) static void sis_5571_usb_update_interrupt(usb_t* usb, void* priv) { - sis_5571_t *dev = (sis_5571_t *) priv; + const sis_5571_t *dev = (sis_5571_t *) priv; if (dev->pci_conf_sb[0][0x68] & 0x80) { /* TODO: Is the normal PCI interrupt inhibited when USB IRQ remapping is enabled? */ diff --git a/src/chipset/sis_85c496.c b/src/chipset/sis_85c496.c index 106d5f793..8aac6ecd5 100644 --- a/src/chipset/sis_85c496.c +++ b/src/chipset/sis_85c496.c @@ -115,8 +115,8 @@ sis_85c497_isa_write(uint16_t port, uint8_t val, void *priv) static uint8_t sis_85c497_isa_read(uint16_t port, void *priv) { - sis_85c496_t *dev = (sis_85c496_t *) priv; - uint8_t ret = 0xff; + const sis_85c496_t *dev = (sis_85c496_t *) priv; + uint8_t ret = 0xff; if (port == 0x23) ret = dev->regs[dev->cur_reg]; @@ -505,8 +505,8 @@ sis_85c49x_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) static uint8_t sis_85c49x_pci_read(UNUSED(int func), int addr, void *priv) { - sis_85c496_t *dev = (sis_85c496_t *) priv; - uint8_t ret = dev->pci_conf[addr]; + const sis_85c496_t *dev = (sis_85c496_t *) priv; + uint8_t ret = dev->pci_conf[addr]; switch (addr) { case 0xa0: @@ -673,7 +673,7 @@ static void timer_add(&dev->rmsmiblk_timer, sis_85c496_rmsmiblk_count, dev, 0); #ifndef USE_DRB_HACK - row_device.local = 7 | (1 << 8) | (0x02 << 16) | (7 << 24); + row_device.local = 7 | (1 << 8) | (0x02 << 16) | (8 << 24); device_add((const device_t *) &row_device); #endif diff --git a/src/chipset/sis_85c50x.c b/src/chipset/sis_85c50x.c index 8375c44c3..00556c6f0 100644 --- a/src/chipset/sis_85c50x.c +++ b/src/chipset/sis_85c50x.c @@ -228,8 +228,8 @@ sis_85c50x_write(int func, int addr, uint8_t val, void *priv) static uint8_t sis_85c50x_read(int func, int addr, void *priv) { - sis_85c50x_t *dev = (sis_85c50x_t *) priv; - uint8_t ret = 0xff; + const sis_85c50x_t *dev = (sis_85c50x_t *) priv; + uint8_t ret = 0xff; if (func == 0x00) ret = dev->pci_conf[addr]; @@ -283,8 +283,8 @@ sis_85c50x_sb_write(int func, int addr, uint8_t val, void *priv) static uint8_t sis_85c50x_sb_read(int func, int addr, void *priv) { - sis_85c50x_t *dev = (sis_85c50x_t *) priv; - uint8_t ret = 0xff; + const sis_85c50x_t *dev = (sis_85c50x_t *) priv; + uint8_t ret = 0xff; if (func == 0x00) ret = dev->pci_conf_sb[addr]; @@ -338,8 +338,8 @@ sis_85c50x_isa_write(uint16_t addr, uint8_t val, void *priv) static uint8_t sis_85c50x_isa_read(uint16_t addr, void *priv) { - sis_85c50x_t *dev = (sis_85c50x_t *) priv; - uint8_t ret = 0xff; + const sis_85c50x_t *dev = (sis_85c50x_t *) priv; + uint8_t ret = 0xff; switch (addr) { case 0x22: diff --git a/src/chipset/stpc.c b/src/chipset/stpc.c index 6964e4221..092c0ae32 100644 --- a/src/chipset/stpc.c +++ b/src/chipset/stpc.c @@ -166,8 +166,8 @@ stpc_host_write(uint16_t addr, uint8_t val, void *priv) static uint8_t stpc_host_read(uint16_t addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (addr == dev->host_base) ret = dev->host_offset; @@ -196,8 +196,8 @@ stpc_localbus_write(uint16_t addr, uint8_t val, void *priv) static uint8_t stpc_localbus_read(uint16_t addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (addr == dev->localbus_base) ret = dev->localbus_offset; @@ -260,8 +260,8 @@ stpc_nb_write(int func, int addr, uint8_t val, void *priv) static uint8_t stpc_nb_read(int func, int addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (func > 0) ret = 0xff; @@ -445,8 +445,8 @@ stpc_ide_write(int func, int addr, uint8_t val, void *priv) static uint8_t stpc_ide_read(int func, int addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (func > 0) ret = 0xff; @@ -507,8 +507,8 @@ stpc_isab_write(int func, int addr, uint8_t val, void *priv) static uint8_t stpc_isab_read(int func, int addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if ((func == 1) && (dev->local != STPC_ATLAS)) ret = stpc_ide_read(0, addr, priv); @@ -571,8 +571,8 @@ stpc_usb_write(int func, int addr, uint8_t val, void *priv) static uint8_t stpc_usb_read(int func, int addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (func > 0) ret = 0xff; @@ -614,7 +614,8 @@ stpc_remap_localbus(stpc_t *dev, uint16_t localbus_base) static uint8_t stpc_serial_handlers(uint8_t val) { - stpc_serial_t *dev = device_get_priv(&stpc_serial_device); + const stpc_serial_t *dev = device_get_priv(&stpc_serial_device); + if (!dev) { stpc_log("STPC: Not remapping UARTs, disabled by strap (raw %02X)\n", val); return 0; @@ -744,8 +745,8 @@ stpc_reg_write(uint16_t addr, uint8_t val, void *priv) static uint8_t stpc_reg_read(uint16_t addr, void *priv) { - stpc_t *dev = (stpc_t *) priv; - uint8_t ret; + const stpc_t *dev = (stpc_t *) priv; + uint8_t ret; if (addr == 0x22) ret = dev->reg_offset; @@ -895,7 +896,7 @@ stpc_setup(stpc_t *dev) static void stpc_usb_update_interrupt(usb_t* usb, void* priv) { - stpc_t *dev = (stpc_t *) priv; + const stpc_t *dev = (stpc_t *) priv; if (usb->irq_level) pci_set_irq(dev->usb_slot, PCI_INTA); diff --git a/src/chipset/umc_8886.c b/src/chipset/umc_8886.c index 40d21ba2d..ded9c7e56 100644 --- a/src/chipset/umc_8886.c +++ b/src/chipset/umc_8886.c @@ -202,7 +202,7 @@ umc_8886_write(int func, int addr, uint8_t val, void *priv) case 0x56: dev->pci_conf_sb[func][addr] = val; - switch (val & 2) { + switch (val & 3) { case 0: cpu_set_isa_pci_div(3); break; @@ -289,8 +289,8 @@ umc_8886_write(int func, int addr, uint8_t val, void *priv) static uint8_t umc_8886_read(int func, int addr, void *priv) { - umc_8886_t *dev = (umc_8886_t *) priv; - uint8_t ret = 0xff; + const umc_8886_t *dev = (umc_8886_t *) priv; + uint8_t ret = 0xff; if (func <= dev->max_func) ret = dev->pci_conf_sb[func][addr]; diff --git a/src/chipset/umc_hb4.c b/src/chipset/umc_hb4.c index 04f10200f..60b070f0b 100644 --- a/src/chipset/umc_hb4.c +++ b/src/chipset/umc_hb4.c @@ -333,8 +333,8 @@ hb4_write(UNUSED(int func), int addr, uint8_t val, void *priv) static uint8_t hb4_read(int func, int addr, void *priv) { - hb4_t *dev = (hb4_t *) priv; - uint8_t ret = 0xff; + const hb4_t *dev = (hb4_t *) priv; + uint8_t ret = 0xff; if (func == 0) ret = dev->pci_conf[addr]; diff --git a/src/chipset/via_apollo.c b/src/chipset/via_apollo.c index 0a6013a93..bd4445521 100644 --- a/src/chipset/via_apollo.c +++ b/src/chipset/via_apollo.c @@ -671,8 +671,8 @@ via_apollo_host_bridge_write(int func, int addr, uint8_t val, void *priv) static uint8_t via_apollo_read(int func, int addr, void *priv) { - via_apollo_t *dev = (via_apollo_t *) priv; - uint8_t ret = 0xff; + const via_apollo_t *dev = (via_apollo_t *) priv; + uint8_t ret = 0xff; switch (func) { case 0: diff --git a/src/chipset/via_pipc.c b/src/chipset/via_pipc.c index b39c21a1d..04bcd5576 100644 --- a/src/chipset/via_pipc.c +++ b/src/chipset/via_pipc.c @@ -41,6 +41,7 @@ #include <86box/ddma.h> #include <86box/pci.h> #include <86box/pic.h> +#include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> #include <86box/port_92.h> #include <86box/hdc.h> @@ -750,8 +751,8 @@ pipc_codec_handlers(pipc_t *dev, uint8_t modem) static uint8_t pipc_fmnmi_read(uint16_t addr, void *priv) { - pipc_t *dev = (pipc_t *) priv; - uint8_t ret = dev->fmnmi_regs[addr & 0x03]; + const pipc_t *dev = (pipc_t *) priv; + uint8_t ret = dev->fmnmi_regs[addr & 0x03]; pipc_log("PIPC: fmnmi_read(%02X) = %02X\n", addr & 0x03, ret); @@ -786,7 +787,7 @@ pipc_fmnmi_handlers(pipc_t *dev, uint8_t modem) static uint8_t pipc_fm_read(uint16_t addr, void *priv) { - pipc_t *dev = (pipc_t *) priv; + const pipc_t *dev = (pipc_t *) priv; #ifdef VIA_PIPC_FM_EMULATION uint8_t ret = ((addr & 0x03) == 0x00) ? dev->fmnmi_status : 0x00; #else @@ -1474,7 +1475,9 @@ pipc_write(int func, int addr, uint8_t val, void *priv) case 0xd2: if (dev->local == VIA_PIPC_686B) smbus_piix4_setclock(dev->smbus, (val & 0x04) ? 65536 : 16384); - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x90: case 0x91: diff --git a/src/chipset/via_vt82c49x.c b/src/chipset/via_vt82c49x.c index 2da72032b..e25fdbfa0 100644 --- a/src/chipset/via_vt82c49x.c +++ b/src/chipset/via_vt82c49x.c @@ -296,8 +296,8 @@ vt82c49x_write(uint16_t addr, uint8_t val, void *priv) static uint8_t vt82c49x_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - vt82c49x_t *dev = (vt82c49x_t *) priv; + uint8_t ret = 0xff; + const vt82c49x_t *dev = (vt82c49x_t *) priv; switch (addr) { case 0xa9: diff --git a/src/chipset/via_vt82c505.c b/src/chipset/via_vt82c505.c index a45638c33..136d335c7 100644 --- a/src/chipset/via_vt82c505.c +++ b/src/chipset/via_vt82c505.c @@ -126,8 +126,8 @@ vt82c505_write(int func, int addr, uint8_t val, void *priv) static uint8_t vt82c505_read(int func, int addr, void *priv) { - vt82c505_t *dev = (vt82c505_t *) priv; - uint8_t ret = 0xff; + const vt82c505_t *dev = (vt82c505_t *) priv; + uint8_t ret = 0xff; if (func != 0) return ret; @@ -151,8 +151,8 @@ vt82c505_out(uint16_t addr, uint8_t val, void *priv) static uint8_t vt82c505_in(uint16_t addr, void *priv) { - vt82c505_t *dev = (vt82c505_t *) priv; - uint8_t ret = 0xff; + const vt82c505_t *dev = (vt82c505_t *) priv; + uint8_t ret = 0xff; if ((addr == 0xa9) && (dev->index >= 0x80) && (dev->index <= 0x9f)) ret = vt82c505_read(0, dev->index, priv); diff --git a/src/chipset/vl82c480.c b/src/chipset/vl82c480.c index 055d91183..00adcc2a4 100644 --- a/src/chipset/vl82c480.c +++ b/src/chipset/vl82c480.c @@ -137,8 +137,8 @@ vl82c480_write(uint16_t addr, uint8_t val, void *priv) static uint8_t vl82c480_read(uint16_t addr, void *priv) { - vl82c480_t *dev = (vl82c480_t *) priv; - uint8_t ret = 0xff; + const vl82c480_t *dev = (vl82c480_t *) priv; + uint8_t ret = 0xff; switch (addr) { case 0xec: diff --git a/src/chipset/wd76c10.c b/src/chipset/wd76c10.c index 8d3f77d0c..ae4b30228 100644 --- a/src/chipset/wd76c10.c +++ b/src/chipset/wd76c10.c @@ -368,7 +368,8 @@ wd76c10_write(uint16_t addr, uint16_t val, void *priv) static uint16_t wd76c10_read(uint16_t addr, void *priv) { - wd76c10_t *dev = (wd76c10_t *) priv; + const wd76c10_t *dev = (wd76c10_t *) priv; + wd76c10_log("WD76C10: R dev->regs[%04x]\n", addr); switch (addr) { case 0x1072: diff --git a/src/config.c b/src/config.c index 32824c2d4..d917d4548 100644 --- a/src/config.c +++ b/src/config.c @@ -228,7 +228,7 @@ load_monitor(int monitor_index) ini_section_t cat; char name[512]; char temp[512]; - char *p = NULL; + const char *p = NULL; sprintf(name, "Monitor #%i", monitor_index + 1); sprintf(temp, "%i, %i, %i, %i", cx, cy, cw, ch); @@ -256,7 +256,7 @@ load_machine(void) { ini_section_t cat = ini_find_section(config, "Machine"); char *p; - char *migrate_from = NULL; + const char *migrate_from = NULL; int c; int i; int j; @@ -448,7 +448,7 @@ load_machine(void) cpu_f = cpu_get_family(legacy_table_entry->family); if (cpu_f) { /* Save the new values. */ - ini_section_set_string(cat, "cpu_family", (char *) legacy_table_entry->family); + ini_section_set_string(cat, "cpu_family", legacy_table_entry->family); ini_section_set_int(cat, "cpu_speed", legacy_table_entry->rspeed); ini_section_set_double(cat, "cpu_multi", legacy_table_entry->multi); } @@ -500,7 +500,7 @@ load_machine(void) cpu_waitstates = ini_section_get_int(cat, "cpu_waitstates", 0); - p = (char *) ini_section_get_string(cat, "fpu_type", "none"); + p = ini_section_get_string(cat, "fpu_type", "none"); fpu_type = fpu_get_type(cpu_f, cpu, p); mem_size = ini_section_get_int(cat, "mem_size", 64); @@ -911,7 +911,7 @@ load_ports(void) lpt_ports[c].enabled = !!ini_section_get_int(cat, temp, (c == 0) ? 1 : 0); sprintf(temp, "lpt%d_device", c + 1); - p = (char *) ini_section_get_string(cat, temp, "none"); + p = ini_section_get_string(cat, temp, "none"); lpt_ports[c].device = lpt_device_get_from_internal_name(p); } @@ -1557,7 +1557,7 @@ load_other_removable_devices(void) ini_section_t cat = ini_find_section(config, "Other removable devices"); char temp[512]; char tmp2[512]; - char *p; + const char *p; char s[512]; unsigned int board = 0; unsigned int dev = 0; @@ -2017,7 +2017,7 @@ save_general(void) char temp[512]; char buffer[512] = { 0 }; - char *va_name; + const char *va_name = NULL; ini_section_set_int(cat, "vid_resize", vid_resize); if (vid_resize == 0) @@ -2216,7 +2216,7 @@ static void save_machine(void) { ini_section_t cat = ini_find_or_create_section(config, "Machine"); - char *p; + const char *p; int c; int i = 0; int legacy_mfg; @@ -2226,7 +2226,7 @@ save_machine(void) p = machine_get_internal_name(); ini_section_set_string(cat, "machine", p); - ini_section_set_string(cat, "cpu_family", (char *) cpu_f->internal_name); + ini_section_set_string(cat, "cpu_family", cpu_f->internal_name); ini_section_set_int(cat, "cpu_speed", cpu_f->cpus[cpu].rspeed); ini_section_set_double(cat, "cpu_multi", cpu_f->cpus[cpu].multi); if (cpu_override) @@ -2247,14 +2247,14 @@ save_machine(void) } if (cpu_legacy_table[c].machine) { /* Look for a corresponding CPU entry. */ - cpu_legacy_table_t *legacy_table_entry; + const cpu_legacy_table_t *legacy_table_entry; for (legacy_mfg = 0; legacy_mfg < 4; legacy_mfg++) { if (!cpu_legacy_table[c].tables[legacy_mfg]) continue; i = 0; while (cpu_legacy_table[c].tables[legacy_mfg][i].family) { - legacy_table_entry = (cpu_legacy_table_t *) &cpu_legacy_table[c].tables[legacy_mfg][i]; + legacy_table_entry = &cpu_legacy_table[c].tables[legacy_mfg][i]; /* Match the family name, speed and multiplier. */ if (!strcmp(cpu_f->internal_name, legacy_table_entry->family)) { @@ -2294,7 +2294,7 @@ save_machine(void) if (fpu_type == 0) ini_section_delete_var(cat, "fpu_type"); else - ini_section_set_string(cat, "fpu_type", (char *) fpu_get_internal_name(cpu_f, cpu, fpu_type)); + ini_section_set_string(cat, "fpu_type", fpu_get_internal_name(cpu_f, cpu, fpu_type)); // Write the mem_size explicitly to the setttings in order to help managers to display it without having the actual machine table ini_section_delete_var(cat, "mem_size"); @@ -2613,7 +2613,7 @@ save_ports(void) ini_section_delete_var(cat, temp); else ini_section_set_string(cat, temp, - (char *) lpt_device_get_internal_name(lpt_ports[c].device)); + lpt_device_get_internal_name(lpt_ports[c].device)); } ini_delete_section_if_empty(config, cat); @@ -2738,7 +2738,7 @@ save_other_peripherals(void) ini_section_delete_var(cat, temp); else ini_section_set_string(cat, temp, - (char *) isamem_get_internal_name(isamem_type[c])); + isamem_get_internal_name(isamem_type[c])); } if (isartc_type == 0) @@ -2836,7 +2836,7 @@ save_hard_disks(void) if (!hdd_is_valid(c) || (hdd[c].bus != HDD_BUS_IDE && hdd[c].bus != HDD_BUS_ESDI)) ini_section_delete_var(cat, temp); else - ini_section_set_string(cat, temp, (char *) hdd_preset_get_internal_name(hdd[c].speed_preset)); + ini_section_set_string(cat, temp, hdd_preset_get_internal_name(hdd[c].speed_preset)); } ini_delete_section_if_empty(config, cat); diff --git a/src/cpu/386_ops.h b/src/cpu/386_ops.h index e345ee8d8..91449efeb 100644 --- a/src/cpu/386_ops.h +++ b/src/cpu/386_ops.h @@ -223,10 +223,11 @@ extern void x386_dynarec_log(const char *fmt, ...); static int opVPCEXT(uint32_t fetchdat) { - uint8_t b1, b2; + uint8_t b1; + uint8_t b2; uint16_t cent; time_t now; - struct tm *tm; + struct tm *tm = NULL; if (!is_vpc) /* only emulate this on Virtual PC machines */ return ILLEGAL(fetchdat); diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index 894f60358..32155491e 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -133,13 +133,13 @@ enum { # define LOOKUP_INV -1 #endif -typedef struct { +typedef struct fpu_t { const char *name; const char *internal_name; const int type; } FPU; -typedef struct { +typedef struct cpu_t { const char *name; uint64_t cpu_type; const FPU *fpus; diff --git a/src/cpu/x86_ops_misc.h b/src/cpu/x86_ops_misc.h index 8fa30471c..e49076388 100644 --- a/src/cpu/x86_ops_misc.h +++ b/src/cpu/x86_ops_misc.h @@ -51,8 +51,10 @@ opSETALC(uint32_t fetchdat) static int opF6_a16(uint32_t fetchdat) { - int tempws, tempws2 = 0; - uint16_t tempw, src16; + int tempws = 0; + int tempws2 = 0; + uint16_t tempw = 0; + uint16_t src16; uint8_t src, dst; int8_t temps; @@ -167,8 +169,10 @@ opF6_a16(uint32_t fetchdat) static int opF6_a32(uint32_t fetchdat) { - int tempws, tempws2 = 0; - uint16_t tempw, src16; + int tempws = 0; + int tempws2 = 0; + uint16_t tempw = 0; + uint16_t src16; uint8_t src, dst; int8_t temps; @@ -282,10 +286,13 @@ opF6_a32(uint32_t fetchdat) static int opF7_w_a16(uint32_t fetchdat) { - uint32_t templ, templ2 = 0; - int tempws, tempws2 = 0; + uint32_t templ; + uint32_t templ2 = 0; + int tempws; + int tempws2 = 0; int16_t temps16; - uint16_t src, dst; + uint16_t src; + uint16_t dst; fetch_ea_16(fetchdat); if (cpu_mod != 3) @@ -392,8 +399,10 @@ opF7_w_a16(uint32_t fetchdat) static int opF7_w_a32(uint32_t fetchdat) { - uint32_t templ, templ2 = 0; - int tempws, tempws2 = 1; + uint32_t templ; + uint32_t templ2 = 0; + int tempws; + int tempws2 = 1; int16_t temps16; uint16_t src, dst; diff --git a/src/cpu/x87_ops.h b/src/cpu/x87_ops.h index e321df959..b01547314 100644 --- a/src/cpu/x87_ops.h +++ b/src/cpu/x87_ops.h @@ -481,6 +481,8 @@ typedef union { # define FP_TAG_VALID_N cpu_state.tag[(cpu_state.TOP + 1) & 7] &= ~TAG_UINT64 #endif +#include "softfloat/softfloat-specialize.h" + #include "x87_ops_sf_arith.h" #include "x87_ops_sf_compare.h" #include "x87_ops_sf_const.h" diff --git a/src/ddma.c b/src/ddma.c index 098b1c573..7cbe2831e 100644 --- a/src/ddma.c +++ b/src/ddma.c @@ -57,10 +57,10 @@ ddma_log(const char *fmt, ...) static uint8_t ddma_reg_read(uint16_t addr, void *priv) { - ddma_channel_t *dev = (ddma_channel_t *) priv; - uint8_t ret = 0xff; - int ch = dev->channel; - int dmab = (ch >= 4) ? 0xc0 : 0x00; + const ddma_channel_t *dev = (ddma_channel_t *) priv; + uint8_t ret = 0xff; + int ch = dev->channel; + uint8_t dmab = (ch >= 4) ? 0xc0 : 0x00; switch (addr & 0x0f) { case 0x00: @@ -92,10 +92,10 @@ ddma_reg_read(uint16_t addr, void *priv) static void ddma_reg_write(uint16_t addr, uint8_t val, void *priv) { - ddma_channel_t *dev = (ddma_channel_t *) priv; - int ch = dev->channel; - int page_regs[4] = { 7, 3, 1, 2 }; - int dmab = (ch >= 4) ? 0xc0 : 0x00; + const ddma_channel_t *dev = (ddma_channel_t *) priv; + int ch = dev->channel; + uint8_t page_regs[4] = { 7, 3, 1, 2 }; + uint8_t dmab = (ch >= 4) ? 0xc0 : 0x00; switch (addr & 0x0f) { case 0x00: diff --git a/src/device.c b/src/device.c index 47dae84cf..e9d0a094a 100644 --- a/src/device.c +++ b/src/device.c @@ -90,8 +90,8 @@ device_init(void) void device_set_context(device_context_t *c, const device_t *dev, int inst) { - void *sec; - void *single_sec; + const void *sec; + void *single_sec; memset(c, 0, sizeof(device_context_t)); c->dev = dev; @@ -143,7 +143,7 @@ device_add_common(const device_t *dev, const device_t *cd, void *p, void *params int c; for (c = 0; c < 256; c++) { - if (!inst && (devices[c] == (device_t *) dev)) { + if (!inst && (devices[c] == dev)) { device_log("DEVICE: device already exists!\n"); return (NULL); } @@ -343,23 +343,23 @@ device_get_priv(const device_t *dev) int device_available(const device_t *dev) { - device_config_t *config = NULL; - device_config_bios_t *bios = NULL; - int roms_present = 0; - int i = 0; + const device_config_t *config = NULL; + const device_config_bios_t *bios = NULL; + int roms_present = 0; + int i = 0; if (dev != NULL) { - config = (device_config_t *) dev->config; + config = dev->config; if (config != NULL) { while (config->type != -1) { if (config->type == CONFIG_BIOS) { - bios = (device_config_bios_t *) config->bios; + bios = (const device_config_bios_t *) config->bios; /* Go through the ROM's in the device configuration. */ while (bios->files_no != 0) { i = 0; for (int bf = 0; bf < bios->files_no; bf++) - i += !!rom_present((char *) bios->files[bf]); + i += !!rom_present(bios->files[bf]); if (i == bios->files_no) roms_present++; bios++; @@ -385,15 +385,15 @@ device_available(const device_t *dev) const char * device_get_bios_file(const device_t *dev, const char *internal_name, int file_no) { - device_config_t *config = NULL; - device_config_bios_t *bios = NULL; + const device_config_t *config = NULL; + const device_config_bios_t *bios = NULL; if (dev != NULL) { - config = (device_config_t *) dev->config; + config = dev->config; if (config != NULL) { while (config->type != -1) { if (config->type == CONFIG_BIOS) { - bios = (device_config_bios_t *) config->bios; + bios = config->bios; /* Go through the ROM's in the device configuration. */ while (bios->files_no != 0) { @@ -418,8 +418,8 @@ device_get_bios_file(const device_t *dev, const char *internal_name, int file_no int device_has_config(const device_t *dev) { - int c = 0; - device_config_t *config; + int c = 0; + const device_config_t *config; if (dev == NULL) return 0; @@ -427,7 +427,7 @@ device_has_config(const device_t *dev) if (dev->config == NULL) return 0; - config = (device_config_t *) dev->config; + config = dev->config; while (config->type != -1) { if (config->type != CONFIG_MAC) @@ -472,10 +472,10 @@ device_register_pci_slot(const device_t *dev, int device, int type, int inta, in void device_get_name(const device_t *dev, int bus, char *name) { - char *sbus = NULL; - char *fbus; - char *tname; - char pbus[8] = { 0 }; + const char *sbus = NULL; + const char *fbus; + char *tname; + char pbus[8] = { 0 }; if (dev == NULL) return; diff --git a/src/device/cartridge.c b/src/device/cartridge.c index 6e399cd33..5d8e6cc4c 100644 --- a/src/device/cartridge.c +++ b/src/device/cartridge.c @@ -61,7 +61,7 @@ cartridge_log(const char *fmt, ...) static uint8_t cart_read(uint32_t addr, void *priv) { - cart_t *dev = (cart_t *) priv; + const cart_t *dev = (cart_t *) priv; return dev->buf[addr - dev->base]; } diff --git a/src/device/hwm_lm78.c b/src/device/hwm_lm78.c index 5fe05bb6d..74752a089 100644 --- a/src/device/hwm_lm78.c +++ b/src/device/hwm_lm78.c @@ -421,8 +421,8 @@ lm78_i2c_read(UNUSED(void *bus), UNUSED(uint8_t addr), void *priv) uint8_t lm78_as99127f_read(void *priv, uint8_t reg) { - lm78_t *dev = (lm78_t *) priv; - uint8_t ret = dev->as99127f.regs[1][reg & 0x7f]; + const lm78_t *dev = (lm78_t *) priv; + uint8_t ret = dev->as99127f.regs[1][reg & 0x7f]; lm78_log("LM78: read(%02X, AS99127F) = %02X\n", reg, ret); diff --git a/src/device/hwm_vt82c686.c b/src/device/hwm_vt82c686.c index bdd560b23..b6a0dddda 100644 --- a/src/device/hwm_vt82c686.c +++ b/src/device/hwm_vt82c686.c @@ -48,8 +48,8 @@ static void vt82c686_reset(vt82c686_t *dev, uint8_t initialization); static uint8_t vt82c686_read(uint16_t addr, void *priv) { - vt82c686_t *dev = (vt82c686_t *) priv; - uint8_t ret; + const vt82c686_t *dev = (vt82c686_t *) priv; + uint8_t ret; addr -= dev->io_base; diff --git a/src/device/i2c.c b/src/device/i2c.c index 63494cac7..56e6f8f4c 100644 --- a/src/device/i2c.c +++ b/src/device/i2c.c @@ -205,9 +205,9 @@ i2c_handler(int set, void *bus_handle, uint8_t base, int size, uint8_t i2c_start(void *bus_handle, uint8_t addr, uint8_t read) { - uint8_t ret = 0; - i2c_bus_t *bus = (i2c_bus_t *) bus_handle; - i2c_t *p; + uint8_t ret = 0; + const i2c_bus_t *bus = (i2c_bus_t *) bus_handle; + i2c_t *p; if (!bus) return ret; @@ -230,9 +230,9 @@ i2c_start(void *bus_handle, uint8_t addr, uint8_t read) uint8_t i2c_read(void *bus_handle, uint8_t addr) { - uint8_t ret = 0; - i2c_bus_t *bus = (i2c_bus_t *) bus_handle; - i2c_t *p; + uint8_t ret = 0; + const i2c_bus_t *bus = (i2c_bus_t *) bus_handle; + i2c_t *p; if (!bus) return ret; @@ -256,9 +256,9 @@ i2c_read(void *bus_handle, uint8_t addr) uint8_t i2c_write(void *bus_handle, uint8_t addr, uint8_t data) { - uint8_t ret = 0; - i2c_t *p; - i2c_bus_t *bus = (i2c_bus_t *) bus_handle; + uint8_t ret = 0; + i2c_t *p; + const i2c_bus_t *bus = (i2c_bus_t *) bus_handle; if (!bus) return ret; @@ -281,8 +281,8 @@ i2c_write(void *bus_handle, uint8_t addr, uint8_t data) void i2c_stop(void *bus_handle, uint8_t addr) { - i2c_bus_t *bus = (i2c_bus_t *) bus_handle; - i2c_t *p; + const i2c_bus_t *bus = (i2c_bus_t *) bus_handle; + i2c_t *p; if (!bus) return; diff --git a/src/device/i2c_gpio.c b/src/device/i2c_gpio.c index 3eda0c4f7..22bdaffd3 100644 --- a/src/device/i2c_gpio.c +++ b/src/device/i2c_gpio.c @@ -171,14 +171,16 @@ i2c_gpio_set(void *dev_handle, uint8_t scl, uint8_t sda) uint8_t i2c_gpio_get_scl(void *dev_handle) { - i2c_gpio_t *dev = (i2c_gpio_t *) dev_handle; + const i2c_gpio_t *dev = (i2c_gpio_t *) dev_handle; + return dev->prev_scl; } uint8_t i2c_gpio_get_sda(void *dev_handle) { - i2c_gpio_t *dev = (i2c_gpio_t *) dev_handle; + const i2c_gpio_t *dev = (i2c_gpio_t *) dev_handle; + i2c_gpio_log(3, "I2C GPIO %s: read myscl=%d mysda=%d slavesda=%d\n", dev->bus_name, dev->prev_scl, dev->prev_sda, dev->slave_sda); return dev->prev_sda && dev->slave_sda; } diff --git a/src/device/ibm_5161.c b/src/device/ibm_5161.c index cc9d54936..07083873e 100644 --- a/src/device/ibm_5161.c +++ b/src/device/ibm_5161.c @@ -45,8 +45,8 @@ ibm_5161_out(uint16_t port, uint8_t val, void *priv) static uint8_t ibm_5161_in(uint16_t port, void *priv) { - ibm_5161_t *dev = (ibm_5161_t *) priv; - uint8_t ret = 0xff; + const ibm_5161_t *dev = (ibm_5161_t *) priv; + uint8_t ret = 0xff; ret = dev->regs[port & 0x0007]; diff --git a/src/device/isamem.c b/src/device/isamem.c index 7e9126e85..5b880d6eb 100644 --- a/src/device/isamem.c +++ b/src/device/isamem.c @@ -288,9 +288,9 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) static uint8_t ems_read(uint16_t port, void *priv) { - memdev_t *dev = (memdev_t *) priv; - uint8_t ret = 0xff; - int vpage; + const memdev_t *dev = (memdev_t *) priv; + uint8_t ret = 0xff; + int vpage; /* Get the viewport page number. */ vpage = (port / EMS_PGSIZE); diff --git a/src/device/isapnp.c b/src/device/isapnp.c index 33d5e7192..22b22dfcc 100644 --- a/src/device/isapnp.c +++ b/src/device/isapnp.c @@ -259,7 +259,8 @@ isapnp_reset_ld_regs(isapnp_device_t *ld) static uint8_t isapnp_read_rangecheck(UNUSED(uint16_t addr), void *priv) { - isapnp_device_t *dev = (isapnp_device_t *) priv; + const isapnp_device_t *dev = (isapnp_device_t *) priv; + return (dev->regs[0x31] & 0x01) ? 0x55 : 0xaa; } diff --git a/src/device/isartc.c b/src/device/isartc.c index 280c6210a..ce0fcd7c6 100644 --- a/src/device/isartc.c +++ b/src/device/isartc.c @@ -191,11 +191,11 @@ mm67_chkalrm(nvr_t *nvr, int8_t addr) static void mm67_tick(nvr_t *nvr) { - rtcdev_t *dev = (rtcdev_t *) nvr->data; - uint8_t *regs = nvr->regs; - int mon; - int year; - int f = 0; + const rtcdev_t *dev = (rtcdev_t *) nvr->data; + uint8_t *regs = nvr->regs; + int mon; + int year; + int f = 0; /* Update and set interrupt if needed. */ regs[MM67_SEC] = RTC_BCDINC(nvr->regs[MM67_SEC], 1); @@ -295,8 +295,8 @@ mm67_tick(nvr_t *nvr) static void mm67_time_get(nvr_t *nvr, struct tm *tm) { - rtcdev_t *dev = (rtcdev_t *) nvr->data; - uint8_t *regs = nvr->regs; + const rtcdev_t *dev = (rtcdev_t *) nvr->data; + const uint8_t *regs = nvr->regs; /* NVR is in BCD data mode. */ tm->tm_sec = RTC_DCB(regs[MM67_SEC]); @@ -325,9 +325,9 @@ mm67_time_get(nvr_t *nvr, struct tm *tm) static void mm67_time_set(nvr_t *nvr, struct tm *tm) { - rtcdev_t *dev = (rtcdev_t *) nvr->data; - uint8_t *regs = nvr->regs; - int year; + const rtcdev_t *dev = (rtcdev_t *) nvr->data; + uint8_t *regs = nvr->regs; + int year; /* NVR is in BCD data mode. */ regs[MM67_SEC] = RTC_BCD(tm->tm_sec); @@ -608,9 +608,6 @@ isartc_close(void *priv) io_removehandler(dev->base_addr, dev->base_addrsz, dev->f_rd, NULL, NULL, dev->f_wr, NULL, NULL, dev); - if (dev->nvr.fn != NULL) - free(dev->nvr.fn); - free(dev); } diff --git a/src/device/kbc_at.c b/src/device/kbc_at.c index ee5a6d17e..39398f996 100644 --- a/src/device/kbc_at.c +++ b/src/device/kbc_at.c @@ -29,6 +29,7 @@ #include <86box/io.h> #include <86box/pic.h> #include <86box/pit.h> +#include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> #include <86box/ppi.h> #include <86box/mem.h> @@ -463,7 +464,9 @@ kbc_at_poll_at(atkbc_t *dev) case STATE_KBC_AMI_OUT: if (dev->status & STAT_OFULL) break; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_MAIN_IBF: default: at_main_ibf: @@ -586,7 +589,9 @@ kbc_at_poll_ps2(atkbc_t *dev) case STATE_KBC_AMI_OUT: if (dev->status & STAT_OFULL) break; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_MAIN_IBF: default: ps2_main_ibf: @@ -1027,6 +1032,9 @@ write64_generic(void *priv, uint8_t val) 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); @@ -1328,12 +1336,13 @@ write64_siemens(void *priv, uint8_t val) static uint8_t write60_quadtel(void *priv, UNUSED(uint8_t val)) { - atkbc_t *dev = (atkbc_t *) priv; + 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; } @@ -1392,7 +1401,7 @@ write64_quadtel(void *priv, uint8_t val) static uint8_t write60_toshiba(void *priv, uint8_t val) { - atkbc_t *dev = (atkbc_t *) priv; + const atkbc_t *dev = (atkbc_t *) priv; switch (dev->command) { case 0xb6: /* T3100e - set color/mono switch */ diff --git a/src/device/kbc_at_dev.c b/src/device/kbc_at_dev.c index 32323ceeb..894b5f08a 100644 --- a/src/device/kbc_at_dev.c +++ b/src/device/kbc_at_dev.c @@ -38,6 +38,7 @@ #include <86box/snd_speaker.h> #include <86box/video.h> #include <86box/keyboard.h> +#include <86box/plat_fallthrough.h> #ifdef ENABLE_KBC_AT_DEV_LOG int kbc_at_dev_do_log = ENABLE_KBC_AT_DEV_LOG; @@ -135,7 +136,9 @@ kbc_at_dev_poll(void *priv) dev->port->wantcmd = 0; break; } - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case DEV_STATE_MAIN_WANT_IN: /* Output command response and then return to main loop #2. */ if ((dev->port->out_new == -1) && (dev->cmd_queue_start != dev->cmd_queue_end)) { diff --git a/src/device/keyboard.c b/src/device/keyboard.c index 10d127c77..e788ff23f 100644 --- a/src/device/keyboard.c +++ b/src/device/keyboard.c @@ -87,8 +87,8 @@ fake_shift_needed(uint16_t scan) void key_process(uint16_t scan, int down) { - scancode *codes = scan_table; - int c; + const scancode *codes = scan_table; + int c; if (!codes) return; @@ -222,7 +222,7 @@ keyboard_input(int down, uint16_t scan) static uint8_t keyboard_do_break(uint16_t scan) { - scancode *codes = scan_table; + const scancode *codes = scan_table; /* TODO: The keyboard controller needs to report the AT flag to us here. */ if (is286 && ((keyboard_mode & 3) == 3)) { @@ -266,7 +266,7 @@ keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl) void keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl) { - scancode *codes = scan_table; + const scancode *codes = scan_table; int i; @@ -320,7 +320,7 @@ keyboard_isfsenter(void) } int -keyboard_isfsenter_down(void) +keyboard_isfsenter_up(void) { return (!recv_key[0x01d] && !recv_key[0x11d] && !recv_key[0x038] && !recv_key[0x138] && !recv_key[0x049] && !recv_key[0x149]); } @@ -333,7 +333,7 @@ keyboard_isfsexit(void) } int -keyboard_isfsexit_down(void) +keyboard_isfsexit_up(void) { return (!recv_key[0x01d] && !recv_key[0x11d] && !recv_key[0x038] && !recv_key[0x138] && !recv_key[0x051] && !recv_key[0x151]); } diff --git a/src/device/keyboard_xt.c b/src/device/keyboard_xt.c index f24d53f0e..a5b5579a6 100644 --- a/src/device/keyboard_xt.c +++ b/src/device/keyboard_xt.c @@ -594,8 +594,8 @@ kbd_write(uint16_t port, uint8_t val, void *priv) static uint8_t kbd_read(uint16_t port, void *priv) { - xtkbd_t *kbd = (xtkbd_t *) priv; - uint8_t ret = 0xff; + const xtkbd_t *kbd = (xtkbd_t *) priv; + uint8_t ret = 0xff; switch (port) { case 0x60: /* Keyboard Data Register (aka Port A) */ diff --git a/src/device/mouse_bus.c b/src/device/mouse_bus.c index 675686280..0537c0cb4 100644 --- a/src/device/mouse_bus.c +++ b/src/device/mouse_bus.c @@ -226,7 +226,6 @@ lt_read(uint16_t port, void *priv) return (dev->control_val | 0x0F) & ~IRQ_MASK; else return 0xff; - break; default: break; diff --git a/src/device/mouse_serial.c b/src/device/mouse_serial.c index 7e50bd49d..c74e5216b 100644 --- a/src/device/mouse_serial.c +++ b/src/device/mouse_serial.c @@ -26,6 +26,7 @@ #include <86box/timer.h> #include <86box/serial.h> #include <86box/mouse.h> +#include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> #define SERMOUSE_PORT 0 /* attach to Serial0 */ @@ -507,7 +508,9 @@ sermouse_command_timer(void *priv) break; case PHASE_ACK: serial_write_fifo(dev->serial, 0x06); - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case PHASE_BAUD_RATE: sermouse_command_phase_idle(dev); sermouse_timer_on(dev, dev->report_period, 1); @@ -645,7 +648,9 @@ ltsermouse_write(UNUSED(struct serial_s *serial), void *priv, uint8_t data) switch (data) { default: mouse_serial_log("Serial mouse: Invalid period %02X, using 1200 bps\n", data); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x6E: dev->transmit_period = sermouse_transmit_period(dev, 1200, -1); break; diff --git a/src/device/pci_bridge.c b/src/device/pci_bridge.c index 3901d266b..eb0c734aa 100644 --- a/src/device/pci_bridge.c +++ b/src/device/pci_bridge.c @@ -363,8 +363,8 @@ pci_bridge_write(int func, int addr, uint8_t val, void *priv) static uint8_t pci_bridge_read(int func, int addr, void *priv) { - pci_bridge_t *dev = (pci_bridge_t *) priv; - uint8_t ret; + const pci_bridge_t *dev = (pci_bridge_t *) priv; + uint8_t ret; if (func > 0) ret = 0xff; diff --git a/src/device/phoenix_486_jumper.c b/src/device/phoenix_486_jumper.c index 7151872e9..dbdfbe946 100644 --- a/src/device/phoenix_486_jumper.c +++ b/src/device/phoenix_486_jumper.c @@ -78,7 +78,8 @@ phoenix_486_jumper_write(UNUSED(uint16_t addr), uint8_t val, void *priv) static uint8_t phoenix_486_jumper_read(UNUSED(uint16_t addr), void *priv) { - phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; + const phoenix_486_jumper_t *dev = (phoenix_486_jumper_t *) priv; + phoenix_486_jumper_log("Phoenix 486 Jumper: Read %02x\n", dev->jumper); return dev->jumper; } diff --git a/src/device/smbus_ali7101.c b/src/device/smbus_ali7101.c index d48749d28..855f0c270 100644 --- a/src/device/smbus_ali7101.c +++ b/src/device/smbus_ali7101.c @@ -28,6 +28,7 @@ #include <86box/timer.h> #include <86box/i2c.h> #include <86box/smbus.h> +#include <86box/plat_fallthrough.h> #ifdef ENABLE_SMBUS_ALI7101_LOG int smbus_ali7101_do_log = ENABLE_SMBUS_ALI7101_LOG; @@ -193,7 +194,9 @@ smbus_ali7101_write(uint16_t addr, uint8_t val, void *priv) case 0x4: /* block R/W */ timer_bytes++; /* count the SMBus length byte now */ - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif default: /* unknown */ dev->next_stat = 0x20; /* raise DEV_ERR */ diff --git a/src/device/smbus_piix4.c b/src/device/smbus_piix4.c index 48a04451e..bad49b957 100644 --- a/src/device/smbus_piix4.c +++ b/src/device/smbus_piix4.c @@ -27,6 +27,7 @@ #include <86box/timer.h> #include <86box/i2c.h> #include <86box/smbus.h> +#include <86box/plat_fallthrough.h> #ifdef ENABLE_SMBUS_PIIX4_LOG int smbus_piix4_do_log = ENABLE_SMBUS_PIIX4_LOG; @@ -195,7 +196,9 @@ smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) timer_bytes++; } - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xc: /* I2C process call */ if (!read) { /* word write (only when writing) */ @@ -214,7 +217,9 @@ smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) case 0x5: /* block R/W */ timer_bytes++; /* count the SMBus length byte now */ - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xd: /* I2C block R/W */ i2c_write(i2c_smbus, smbus_addr, dev->cmd); @@ -247,7 +252,9 @@ smbus_piix4_write(uint16_t addr, uint8_t val, void *priv) i2c_write(i2c_smbus, smbus_addr, dev->cmd); timer_bytes++; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xe: /* I2C with 7-bit address */ if (!read) { /* word write (only when writing) */ diff --git a/src/disk/hdc_esdi_at.c b/src/disk/hdc_esdi_at.c index 014212b1d..258ea9d0f 100644 --- a/src/disk/hdc_esdi_at.c +++ b/src/disk/hdc_esdi_at.c @@ -173,13 +173,13 @@ esdi_get_xfer_time(UNUSED(esdi_t *esdi), int size) static int get_sector(esdi_t *esdi, off64_t *addr) { - drive_t *drive = &esdi->drives[esdi->drive_sel]; - int heads = drive->cfg_hpc; - int sectors = drive->cfg_spt; - int c; - int h; - int s; - int sector; + const drive_t *drive = &esdi->drives[esdi->drive_sel]; + int heads = drive->cfg_hpc; + int sectors = drive->cfg_spt; + int c; + int h; + int s; + int sector; if (esdi->head > heads) { esdi_at_log("esdi_get_sector: past end of configured heads\n"); @@ -338,7 +338,9 @@ esdi_write(uint16_t port, uint8_t val, void *priv) esdi->command &= ~0x03; if (val & 0x02) fatal("Read with ECC\n"); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xa0: esdi->status = STAT_BUSY; @@ -397,7 +399,9 @@ esdi_write(uint16_t port, uint8_t val, void *priv) default: esdi_at_log("WD1007: bad command %02X\n", val); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xe8: /*???*/ esdi->status = STAT_BUSY; esdi_set_callback(esdi, 200 * HDC_TIME); @@ -878,8 +882,8 @@ wd1007vse1_init(UNUSED(const device_t *info)) static void wd1007vse1_close(void *priv) { - esdi_t *esdi = (esdi_t *) priv; - drive_t *drive; + esdi_t *esdi = (esdi_t *) priv; + const drive_t *drive; for (uint8_t d = 0; d < 2; d++) { drive = &esdi->drives[d]; diff --git a/src/disk/hdc_esdi_mca.c b/src/disk/hdc_esdi_mca.c index 712ab900b..02f054ca2 100644 --- a/src/disk/hdc_esdi_mca.c +++ b/src/disk/hdc_esdi_mca.c @@ -352,10 +352,10 @@ complete_command_status(esdi_t *dev) static void esdi_callback(void *priv) { - esdi_t *dev = (esdi_t *) priv; - drive_t *drive; - int val; - double cmd_time = 0.0; + esdi_t *dev = (esdi_t *) priv; + const drive_t *drive; + int val; + double cmd_time = 0.0; esdi_mca_set_callback(dev, 0); @@ -1059,7 +1059,7 @@ esdi_writew(uint16_t port, uint16_t val, void *priv) static uint8_t esdi_mca_read(int port, void *priv) { - esdi_t *dev = (esdi_t *) priv; + const esdi_t *dev = (esdi_t *) priv; esdi_mca_log("ESDI: mcard(%04x)\n", port); @@ -1132,7 +1132,7 @@ esdi_mca_write(int port, uint8_t val, void *priv) static uint8_t esdi_mca_feedb(void *priv) { - esdi_t *dev = (esdi_t *) priv; + const esdi_t *dev = (esdi_t *) priv; return (dev->pos_regs[2] & 1); } @@ -1210,8 +1210,8 @@ esdi_init(UNUSED(const device_t *info)) static void esdi_close(void *priv) { - esdi_t *dev = (esdi_t *) priv; - drive_t *drive; + esdi_t *dev = (esdi_t *) priv; + const drive_t *drive; dev->drives[0].present = dev->drives[1].present = 0; diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index 041d8ffc4..ace646328 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -597,13 +597,13 @@ ide_hd_identify(ide_t *ide) static void ide_identify(ide_t *ide) { - int d; - int i; - int max_pio; - int max_sdma; - int max_mdma; - int max_udma; - ide_t *ide_other = ide_drives[ide->channel ^ 1]; + int d; + int i; + int max_pio; + int max_sdma; + int max_mdma; + int max_udma; + const ide_t *ide_other = ide_drives[ide->channel ^ 1]; ide_log("IDE IDENTIFY or IDENTIFY PACKET DEVICE on board %i (channel %i)\n", ide->board, ide->channel); @@ -1114,8 +1114,8 @@ ide_atapi_packet_read(ide_t *ide, int length) { scsi_common_t *dev = ide->sc; - uint16_t *bufferw; - uint32_t *bufferl; + const uint16_t *bufferw; + const uint32_t *bufferl; uint32_t temp = 0; @@ -1311,7 +1311,7 @@ ide_writew(uint16_t addr, uint16_t val, void *priv) static void ide_writel(uint16_t addr, uint32_t val, void *priv) { - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; ide_t *ide; int ch; @@ -1655,7 +1655,9 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) disabled, the Read Multiple operation is rejected with an Aborted Com- mand error. */ ide->blockcount = 0; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case WIN_READ: case WIN_READ_NORETRY: @@ -1704,7 +1706,9 @@ ide_writeb(uint16_t addr, uint8_t val, void *priv) /* Turn on the activity indicator *here* so that it gets turned on less times. */ ui_sb_update_icon(SB_HDD | hdd[ide->hdd_num].bus, 1); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case WIN_WRITE: case WIN_WRITE_NORETRY: @@ -1843,6 +1847,9 @@ ide_bad_command: return; } return; + + default: + break; } } @@ -1864,9 +1871,9 @@ ide_read_data(ide_t *ide, int length) } } - uint8_t *idebufferb = (uint8_t *) ide->buffer; - uint16_t *idebufferw = ide->buffer; - uint32_t *idebufferl = (uint32_t *) ide->buffer; + const uint8_t *idebufferb = (uint8_t *) ide->buffer; + const uint16_t *idebufferw = ide->buffer; + const uint32_t *idebufferl = (uint32_t *) ide->buffer; if (ide->command == WIN_PACKETCMD) { ide->pos = 0; @@ -1946,7 +1953,7 @@ ide_status(ide_t *ide, ide_t *ide_other, int ch) uint8_t ide_readb(uint16_t addr, void *priv) { - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; int ch; int absent = 0; @@ -2062,6 +2069,9 @@ ide_readb(uint16_t addr, void *priv) ide_irq_lower(ide); temp = ide_status(ide, ide_drives[ch ^ 1], ch); break; + + default: + break; } ide_log("ide_readb(%04X, %08X) = %02X\n", addr, priv, temp); @@ -2073,7 +2083,7 @@ ide_read_alt_status(UNUSED(uint16_t addr), void *priv) { uint8_t temp = 0xff; - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; ide_t *ide; int ch; @@ -2094,7 +2104,7 @@ ide_readw(uint16_t addr, void *priv) { uint16_t temp = 0xffff; - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; ide_t *ide; int ch; @@ -2124,7 +2134,7 @@ ide_readl(uint16_t addr, void *priv) uint16_t temp2; uint32_t temp = 0xffffffff; - ide_board_t *dev = (ide_board_t *) priv; + const ide_board_t *dev = (ide_board_t *) priv; ide_t *ide; int ch; @@ -2620,11 +2630,11 @@ id_not_found: uint8_t ide_read_ali_75(void) { - ide_t *ide0; - ide_t *ide1; - int ch0; - int ch1; - uint8_t ret = 0x00; + const ide_t *ide0; + const ide_t *ide1; + int ch0; + int ch1; + uint8_t ret = 0x00; ch0 = ide_boards[0]->cur_dev; ch1 = ide_boards[1]->cur_dev; @@ -2646,11 +2656,11 @@ ide_read_ali_75(void) uint8_t ide_read_ali_76(void) { - ide_t *ide0; - ide_t *ide1; - int ch0; - int ch1; - uint8_t ret = 0x00; + const ide_t *ide0; + const ide_t *ide1; + int ch0; + int ch1; + uint8_t ret = 0x00; ch0 = ide_boards[0]->cur_dev; ch1 = ide_boards[1]->cur_dev; diff --git a/src/disk/hdc_ide_cmd640.c b/src/disk/hdc_ide_cmd640.c index 6299bf7f4..6cb54aea5 100644 --- a/src/disk/hdc_ide_cmd640.c +++ b/src/disk/hdc_ide_cmd640.c @@ -41,7 +41,7 @@ typedef struct cmd640_t { uint8_t vlb_idx; uint8_t id; uint8_t in_cfg; - uint8_t single_channel; + uint8_t channels; uint8_t pci, regs[256]; uint32_t local; int slot; @@ -89,6 +89,10 @@ cmd640_set_irq(int channel, void *priv) } channel &= 0x01; + + if (!(dev->channels & (1 << channel))) + return; + if (irq) { if (dev->irq_mode[channel] == 1) pci_set_irq(dev->slot, dev->irq_pin); @@ -108,40 +112,41 @@ cmd640_ide_handlers(cmd640_t *dev) uint16_t main; uint16_t side; - ide_pri_disable(); + if (dev->channels & 0x01) { + ide_pri_disable(); - if ((dev->regs[0x09] & 0x01) && (dev->regs[0x50] & 0x40)) { - main = (dev->regs[0x11] << 8) | (dev->regs[0x10] & 0xf8); - side = ((dev->regs[0x15] << 8) | (dev->regs[0x14] & 0xfc)) + 2; - } else { - main = 0x1f0; - side = 0x3f6; + if ((dev->regs[0x09] & 0x01) && (dev->regs[0x50] & 0x40)) { + main = (dev->regs[0x11] << 8) | (dev->regs[0x10] & 0xf8); + side = ((dev->regs[0x15] << 8) | (dev->regs[0x14] & 0xfc)) + 2; + } else { + main = 0x1f0; + side = 0x3f6; + } + + ide_set_base(0, main); + ide_set_side(0, side); + + if (dev->regs[0x04] & 0x01) + ide_pri_enable(); } - ide_set_base(0, main); - ide_set_side(0, side); + if (dev->channels & 0x02) { + ide_sec_disable(); - if (dev->regs[0x04] & 0x01) - ide_pri_enable(); + if ((dev->regs[0x09] & 0x04) && (dev->regs[0x50] & 0x40)) { + main = (dev->regs[0x19] << 8) | (dev->regs[0x18] & 0xf8); + side = ((dev->regs[0x1d] << 8) | (dev->regs[0x1c] & 0xfc)) + 2; + } else { + main = 0x170; + side = 0x376; + } - if (dev->single_channel) - return; + ide_set_base(1, main); + ide_set_side(1, side); - ide_sec_disable(); - - if ((dev->regs[0x09] & 0x04) && (dev->regs[0x50] & 0x40)) { - main = (dev->regs[0x19] << 8) | (dev->regs[0x18] & 0xf8); - side = ((dev->regs[0x1d] << 8) | (dev->regs[0x1c] & 0xfc)) + 2; - } else { - main = 0x170; - side = 0x376; + if ((dev->regs[0x04] & 0x01) && (dev->regs[0x51] & 0x08)) + ide_sec_enable(); } - - ide_set_base(1, main); - ide_set_side(1, side); - - if ((dev->regs[0x04] & 0x01) && (dev->regs[0x51] & 0x08)) - ide_sec_enable(); } static void @@ -368,22 +373,49 @@ cmd640_reset(void *priv) { cmd640_t *dev = (cmd640_t *) priv; int i = 0; + int min_channel; + int max_channel; + + switch (dev->channels) { + default: + case 0x00: + min_channel = max_channel = 0; + break; + case 0x01: + min_channel = 0; + max_channel = 1; + break; + case 0x02: + min_channel = 2; + max_channel = 3; + break; + case 0x03: + min_channel = 0; + max_channel = 3; + break; + } for (i = 0; i < CDROM_NUM; i++) { - if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && (cdrom[i].ide_channel < 4) && cdrom[i].priv) + if ((cdrom[i].bus_type == CDROM_BUS_ATAPI) && (cdrom[i].ide_channel >= min_channel) && + (cdrom[i].ide_channel <= max_channel) && cdrom[i].priv) scsi_cdrom_reset((scsi_common_t *) cdrom[i].priv); } for (i = 0; i < ZIP_NUM; i++) { - if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel < 4) && zip_drives[i].priv) + if ((zip_drives[i].bus_type == ZIP_BUS_ATAPI) && (zip_drives[i].ide_channel >= min_channel) && + (zip_drives[i].ide_channel <= max_channel) && zip_drives[i].priv) zip_reset((scsi_common_t *) zip_drives[i].priv); } for (i = 0; i < MO_NUM; i++) { - if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel < 4) && mo_drives[i].priv) + if ((mo_drives[i].bus_type == MO_BUS_ATAPI) && (mo_drives[i].ide_channel >= min_channel) && + (mo_drives[i].ide_channel <= max_channel) && mo_drives[i].priv) mo_reset((scsi_common_t *) mo_drives[i].priv); } - cmd640_set_irq(0x00, priv); - cmd640_set_irq(0x01, priv); + if (dev->channels & 0x01) + cmd640_set_irq(0x00, priv); + + if (dev->channels & 0x02) + cmd640_set_irq(0x01, priv); memset(dev->regs, 0x00, sizeof(dev->regs)); @@ -429,6 +461,8 @@ cmd640_reset(void *priv) dev->irq_pin = PCI_INTA; dev->irq_line = 14; } else { + dev->regs[0x04] = 0x01; /* To make sure the two channels get enabled. */ + if ((dev->local & 0xffff) == 0x0078) dev->regs[0x50] |= 0x20; /* 0 = 178h, 17Ch; 1 = 078h, 07Ch */ @@ -461,18 +495,26 @@ cmd640_init(const device_t *info) dev->pci = !!(info->flags & DEVICE_PCI); dev->local = info->local; + dev->channels = ((info->local & 0x60000) >> 17) & 0x03; + if (info->flags & DEVICE_PCI) { device_add(&ide_pci_2ch_device); dev->slot = pci_add_card(PCI_ADD_IDE, cmd640_pci_read, cmd640_pci_write, dev); - ide_set_bus_master(0, NULL, cmd640_set_irq, dev); - ide_set_bus_master(1, NULL, cmd640_set_irq, dev); + if (dev->channels & 0x01) + ide_set_bus_master(0, NULL, cmd640_set_irq, dev); + + if (dev->channels & 0x02) + ide_set_bus_master(1, NULL, cmd640_set_irq, dev); /* The CMD PCI-0640B IDE controller has no DMA capability, so set our devices IDE devices to force ATA-3 (no DMA). */ - ide_board_set_force_ata3(0, 1); - ide_board_set_force_ata3(1, 1); + if (dev->channels & 0x01) + ide_board_set_force_ata3(0, 1); + + if (dev->channels & 0x02) + ide_board_set_force_ata3(1, 1); #if 0 ide_pri_disable(); @@ -486,8 +528,6 @@ cmd640_init(const device_t *info) dev); } - dev->single_channel = !!(info->local & 0x20000); - next_id++; cmd640_reset(dev); @@ -499,7 +539,7 @@ const device_t ide_cmd640_vlb_device = { .name = "CMD PCI-0640B VLB", .internal_name = "ide_cmd640_vlb", .flags = DEVICE_VLB, - .local = 0x0078, + .local = 0x60078, .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, @@ -513,7 +553,63 @@ const device_t ide_cmd640_vlb_178_device = { .name = "CMD PCI-0640B VLB (Port 178h)", .internal_name = "ide_cmd640_vlb_178", .flags = DEVICE_VLB, - .local = 0x0178, + .local = 0x60178, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_cmd640_vlb_pri_device = { + .name = "CMD PCI-0640B VLB", + .internal_name = "ide_cmd640_vlb", + .flags = DEVICE_VLB, + .local = 0x20078, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_cmd640_vlb_pri_178_device = { + .name = "CMD PCI-0640B VLB (Port 178h)", + .internal_name = "ide_cmd640_vlb_178", + .flags = DEVICE_VLB, + .local = 0x20178, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_cmd640_vlb_sec_device = { + .name = "CMD PCI-0640B VLB", + .internal_name = "ide_cmd640_vlb", + .flags = DEVICE_VLB, + .local = 0x40078, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + +const device_t ide_cmd640_vlb_sec_178_device = { + .name = "CMD PCI-0640B VLB (Port 178h)", + .internal_name = "ide_cmd640_vlb_178", + .flags = DEVICE_VLB, + .local = 0x40178, .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, @@ -527,7 +623,7 @@ const device_t ide_cmd640_pci_device = { .name = "CMD PCI-0640B PCI", .internal_name = "ide_cmd640_pci", .flags = DEVICE_PCI, - .local = 0x0a, + .local = 0x6000a, .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, @@ -541,7 +637,7 @@ const device_t ide_cmd640_pci_legacy_only_device = { .name = "CMD PCI-0640B PCI (Legacy Mode Only)", .internal_name = "ide_cmd640_pci_legacy_only", .flags = DEVICE_PCI, - .local = 0x00, + .local = 0x60000, .init = cmd640_init, .close = cmd640_close, .reset = cmd640_reset, @@ -564,3 +660,17 @@ const device_t ide_cmd640_pci_single_channel_device = { .force_redraw = NULL, .config = NULL }; + +const device_t ide_cmd640_pci_single_channel_sec_device = { + .name = "CMD PCI-0640B PCI", + .internal_name = "ide_cmd640_pci_single_channel_sec", + .flags = DEVICE_PCI, + .local = 0x4000a, + .init = cmd640_init, + .close = cmd640_close, + .reset = cmd640_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/disk/hdc_ide_cmd646.c b/src/disk/hdc_ide_cmd646.c index 00f765bf7..1f727bf6b 100644 --- a/src/disk/hdc_ide_cmd646.c +++ b/src/disk/hdc_ide_cmd646.c @@ -90,7 +90,7 @@ cmd646_set_irq(int channel, void *priv) static int cmd646_bus_master_dma(int channel, uint8_t *data, int transfer_length, int out, void *priv) { - cmd646_t *dev = (cmd646_t *) priv; + const cmd646_t *dev = (cmd646_t *) priv; return sff_bus_master_dma(channel, data, transfer_length, out, dev->bm[channel & 0x01]); } diff --git a/src/disk/hdc_ide_opti611.c b/src/disk/hdc_ide_opti611.c index 4e44c55f8..480331201 100644 --- a/src/disk/hdc_ide_opti611.c +++ b/src/disk/hdc_ide_opti611.c @@ -31,6 +31,7 @@ #include <86box/plat_unused.h> typedef struct opti611_t { + uint8_t is_sec; uint8_t tries; uint8_t in_cfg; uint8_t cfg_locked; @@ -92,8 +93,8 @@ opti611_cfg_writel(uint16_t addr, uint32_t val, void *priv) static uint8_t opti611_cfg_read(uint16_t addr, void *priv) { - uint8_t ret = 0xff; - opti611_t *dev = (opti611_t *) priv; + uint8_t ret = 0xff; + const opti611_t *dev = (opti611_t *) priv; addr &= 0x0007; @@ -254,28 +255,54 @@ opti611_ide_readl(uint16_t addr, void *priv) static void opti611_ide_handler(opti611_t *dev) { - ide_pri_disable(); - io_removehandler(0x01f0, 0x0007, - opti611_ide_read, opti611_ide_readw, opti611_ide_readl, - opti611_ide_write, opti611_ide_writew, opti611_ide_writel, - dev); - io_removehandler(0x01f0, 0x0007, - opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, - opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, - dev); + if (dev->is_sec) { + ide_sec_disable(); + io_removehandler(0x0170, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + io_removehandler(0x0170, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); - if (dev->in_cfg && !dev->cfg_locked) { - io_sethandler(0x01f0, 0x0007, - opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, - opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, - dev); + if (dev->in_cfg && !dev->cfg_locked) { + io_sethandler(0x0170, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + } else { + if (dev->regs[0x03] & 0x01) + ide_sec_enable(); + io_sethandler(0x0170, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + } } else { - if (dev->regs[0x03] & 0x01) - ide_pri_enable(); - io_sethandler(0x01f0, 0x0007, - opti611_ide_read, opti611_ide_readw, opti611_ide_readl, - opti611_ide_write, opti611_ide_writew, opti611_ide_writel, - dev); + ide_pri_disable(); + io_removehandler(0x01f0, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + io_removehandler(0x01f0, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + + if (dev->in_cfg && !dev->cfg_locked) { + io_sethandler(0x01f0, 0x0007, + opti611_cfg_read, opti611_cfg_readw, opti611_cfg_readl, + opti611_cfg_write, opti611_cfg_writew, opti611_cfg_writel, + dev); + } else { + if (dev->regs[0x03] & 0x01) + ide_pri_enable(); + io_sethandler(0x01f0, 0x0007, + opti611_ide_read, opti611_ide_readw, opti611_ide_readl, + opti611_ide_write, opti611_ide_writew, opti611_ide_writel, + dev); + } } } @@ -293,6 +320,8 @@ opti611_init(UNUSED(const device_t *info)) opti611_t *dev = (opti611_t *) malloc(sizeof(opti611_t)); memset(dev, 0, sizeof(opti611_t)); + dev->is_sec = info->local; + dev->regs[0x12] = 0x80; dev->regs[0x03] = 0x01; dev->regs[0x05] = 0x20; @@ -317,3 +346,17 @@ const device_t ide_opti611_vlb_device = { .force_redraw = NULL, .config = NULL }; + +const device_t ide_opti611_vlb_sec_device = { + .name = "OPTi 82C611/82C611A VLB (Secondary)", + .internal_name = "ide_opti611_vlb", + .flags = DEVICE_VLB, + .local = 1, + .init = opti611_init, + .close = opti611_close, + .reset = NULL, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; diff --git a/src/disk/hdc_ide_sff8038i.c b/src/disk/hdc_ide_sff8038i.c index fb16c8788..5e8e4e987 100644 --- a/src/disk/hdc_ide_sff8038i.c +++ b/src/disk/hdc_ide_sff8038i.c @@ -222,7 +222,7 @@ sff_bus_master_writel(uint16_t port, uint32_t val, void *priv) uint8_t sff_bus_master_read(uint16_t port, void *priv) { - sff8038i_t *dev = (sff8038i_t *) priv; + const sff8038i_t *dev = (sff8038i_t *) priv; uint8_t ret = 0xff; @@ -261,7 +261,7 @@ sff_bus_master_read(uint16_t port, void *priv) static uint16_t sff_bus_master_readw(uint16_t port, void *priv) { - sff8038i_t *dev = (sff8038i_t *) priv; + const sff8038i_t *dev = (sff8038i_t *) priv; uint16_t ret = 0xffff; @@ -290,7 +290,7 @@ sff_bus_master_readw(uint16_t port, void *priv) static uint32_t sff_bus_master_readl(uint16_t port, void *priv) { - sff8038i_t *dev = (sff8038i_t *) priv; + const sff8038i_t *dev = (sff8038i_t *) priv; uint32_t ret = 0xffffffff; diff --git a/src/disk/hdc_st506_at.c b/src/disk/hdc_st506_at.c index b202ebe47..41499591d 100644 --- a/src/disk/hdc_st506_at.c +++ b/src/disk/hdc_st506_at.c @@ -171,7 +171,7 @@ irq_update(mfm_t *mfm) static int get_sector(mfm_t *mfm, off64_t *addr) { - drive_t *drive = &mfm->drives[mfm->drvsel]; + const drive_t *drive = &mfm->drives[mfm->drvsel]; /* FIXME: See if this is even needed - if the code is present, IBM AT diagnostics v2.07 will error with: ERROR 152 - SYSTEM BOARD. */ @@ -734,7 +734,7 @@ mfm_close(void *priv) mfm_t *mfm = (mfm_t *) priv; for (uint8_t d = 0; d < 2; d++) { - drive_t *drive = &mfm->drives[d]; + const drive_t *drive = &mfm->drives[d]; hdd_image_close(drive->hdd_num); } diff --git a/src/disk/hdc_st506_xt.c b/src/disk/hdc_st506_xt.c index c895aab45..766d70145 100644 --- a/src/disk/hdc_st506_xt.c +++ b/src/disk/hdc_st506_xt.c @@ -623,6 +623,10 @@ st506_callback(void *priv) st506_complete(dev); break; } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case CMD_FORMAT_TRACK: case CMD_FORMAT_BAD_TRACK: switch (dev->state) { @@ -1377,10 +1381,10 @@ mem_write(uint32_t addr, uint8_t val, void *priv) static uint8_t mem_read(uint32_t addr, void *priv) { - hdc_t *dev = (hdc_t *) priv; - uint32_t ptr; - uint32_t mask = 0; - uint8_t ret = 0xff; + const hdc_t *dev = (hdc_t *) priv; + uint32_t ptr; + uint32_t mask = 0; + uint8_t ret = 0xff; /* Ignore accesses to anything below the configured address, needed because of the emulator's 4k mapping granularity. */ @@ -1529,8 +1533,8 @@ loadhd(hdc_t *dev, int c, int d, UNUSED(const char *fn)) static void set_switches(hdc_t *dev, hd_type_t *hdt, int num) { - drive_t *drive; - int e; + const drive_t *drive; + int e; dev->switches = 0x00; @@ -1604,7 +1608,9 @@ st506_init(const device_t *info) case ST506_XT_TYPE_ST11R: /* Seagate ST-11R (RLL) */ dev->spt = RLL_SECTORS; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case ST506_XT_TYPE_ST11M: /* Seagate ST-11M (MFM) */ dev->nr_err = ERR_NOT_AVAILABLE; @@ -1778,8 +1784,8 @@ st506_init(const device_t *info) static void st506_close(void *priv) { - hdc_t *dev = (hdc_t *) priv; - drive_t *drive; + hdc_t *dev = (hdc_t *) priv; + const drive_t *drive; for (uint8_t d = 0; d < MFM_NUM; d++) { drive = &dev->drives[d]; diff --git a/src/disk/hdc_xta.c b/src/disk/hdc_xta.c index 99e638335..b27648eca 100644 --- a/src/disk/hdc_xta.c +++ b/src/disk/hdc_xta.c @@ -509,7 +509,9 @@ hdc_callback(void *priv) case CMD_READ_VERIFY: no_data = 1; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case CMD_READ_SECTORS: if (!drive->present) { @@ -534,7 +536,9 @@ hdc_callback(void *priv) dev->buf_len = 512; dev->state = STATE_SEND; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_SEND: /* Activate the status icon. */ @@ -642,7 +646,9 @@ do_send: dev->buf_len = 512; dev->state = STATE_RECV; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_RECV: /* Activate the status icon. */ @@ -1098,8 +1104,8 @@ xta_init(const device_t *info) static void xta_close(void *priv) { - hdc_t *dev = (hdc_t *) priv; - drive_t *drive; + hdc_t *dev = (hdc_t *) priv; + const drive_t *drive; /* Remove the I/O handler. */ io_removehandler(dev->base, 4, diff --git a/src/disk/hdd.c b/src/disk/hdd.c index a4b8a6f73..685eec9d0 100644 --- a/src/disk/hdd.c +++ b/src/disk/hdd.c @@ -160,7 +160,7 @@ hdd_seek_get_time(hard_disk_t *hdd, uint32_t dst_addr, uint8_t operation, uint8_ if (!hdd->speed_preset) return HDD_OVERHEAD_TIME; - hdd_zone_t *zone = NULL; + const hdd_zone_t *zone = NULL; if (hdd->num_zones <= 0) { fatal("hdd_seek_get_time(): hdd->num_zones < 0)\n"); return 0.0; @@ -486,7 +486,7 @@ hdd_preset_apply(int hdd_id) if (hd->speed_preset >= hdd_preset_get_num()) hd->speed_preset = 0; - hdd_preset_t *preset = &hdd_speed_presets[hd->speed_preset]; + const hdd_preset_t *preset = &hdd_speed_presets[hd->speed_preset]; hd->cache.num_segments = preset->rcache_num_seg; hd->cache.segment_size = preset->rcache_seg_size; diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index 4d3e354f2..a9b013205 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -450,7 +450,7 @@ retry_vhd: else fatal("hdd_image_load(): VHD: Error opening VHD file '%s': %s\n", fn, mvhd_strerr(vhd_error)); } else if (vhd_error == MVHD_ERR_TIMESTAMP) { - fatal("hdd_image_load(): VHD: Parent/child timestamp mismatch for VHD file '%s'\n", fn); + pclog("hdd_image_load(): VHD: Parent/child timestamp mismatch for VHD file '%s'\n", fn); } hdd[id].tracks = hdd_images[id].vhd->footer.geom.cyl; diff --git a/src/disk/mo.c b/src/disk/mo.c index d7dbba895..eef83ec3a 100644 --- a/src/disk/mo.c +++ b/src/disk/mo.c @@ -655,7 +655,9 @@ mo_update_request_length(mo_t *dev, int len, int block_len) break; } } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif default: dev->packet_len = len; break; @@ -1342,7 +1344,9 @@ mo_command(scsi_common_t *sc, uint8_t *cdb) mo_invalid_field(dev); return; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_SCSI_RESERVE: case GPCMD_SCSI_RELEASE: case GPCMD_TEST_UNIT_READY: @@ -2051,7 +2055,7 @@ mo_do_identify(ide_t *ide, int ide_has_dma) { char model[40]; - mo_t *mo = (mo_t *) ide->sc; + const mo_t *mo = (mo_t *) ide->sc; memset(model, 0, 40); diff --git a/src/disk/zip.c b/src/disk/zip.c index 648182cc3..cd7359c05 100644 --- a/src/disk/zip.c +++ b/src/disk/zip.c @@ -821,7 +821,10 @@ zip_update_request_length(zip_t *dev, int len, int block_len) break; } } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + default: dev->packet_len = len; break; @@ -1408,7 +1411,9 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_invalid_field(dev); return; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_SCSI_RESERVE: case GPCMD_SCSI_RELEASE: case GPCMD_TEST_UNIT_READY: @@ -1571,6 +1576,9 @@ zip_command(scsi_common_t *sc, uint8_t *cdb) zip_command_complete(dev); break; } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_WRITE_6: case GPCMD_WRITE_10: case GPCMD_WRITE_AND_VERIFY_10: @@ -2280,7 +2288,7 @@ zip_250_identify(ide_t *ide, int ide_has_dma) static void zip_identify(ide_t *ide, int ide_has_dma) { - zip_t *zip; + const zip_t *zip; zip = (zip_t *) ide->sc; diff --git a/src/dma.c b/src/dma.c index 9dc984125..a8ba1c1a9 100644 --- a/src/dma.c +++ b/src/dma.c @@ -118,7 +118,7 @@ dma_sg_next_addr(dma_t *dev) dev->eot = dev->count >> 31; dev->count &= 0xfffe; dev->cb = (uint16_t) dev->count; - dev->cc = (int) dev->count; + dev->cc = dev->count; if (!dev->count) dev->count = 65536; if (ts == 2) @@ -133,9 +133,7 @@ dma_sg_next_addr(dma_t *dev) static void dma_block_transfer(int channel) { - int bit16; - - bit16 = (channel >= 4); + int bit16 = (channel >= 4); if (dma_advanced) bit16 = !!(dma_transfer_size(&(dma[channel])) == 2); @@ -300,7 +298,7 @@ dma_sg_writel(uint16_t port, uint32_t val, void *priv) static uint8_t dma_sg_read(uint16_t port, void *priv) { - dma_t *dev = (dma_t *) priv; + const dma_t *dev = (dma_t *) priv; uint8_t ret = 0xff; @@ -348,7 +346,7 @@ dma_sg_read(uint16_t port, void *priv) static uint16_t dma_sg_readw(uint16_t port, void *priv) { - dma_t *dev = (dma_t *) priv; + const dma_t *dev = (dma_t *) priv; uint16_t ret = 0xffff; @@ -382,7 +380,7 @@ dma_sg_readw(uint16_t port, void *priv) static uint32_t dma_sg_readl(uint16_t port, void *priv) { - dma_t *dev = (dma_t *) priv; + const dma_t *dev = (dma_t *) priv; uint32_t ret = 0xffffffff; @@ -596,7 +594,7 @@ dma_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) static uint8_t dma_ps2_read(uint16_t addr, UNUSED(void *priv)) { - dma_t *dma_c = &dma[dma_ps2.xfr_channel]; + const dma_t *dma_c = &dma[dma_ps2.xfr_channel]; uint8_t temp = 0xff; switch (addr) { @@ -1280,7 +1278,7 @@ dma_sg(uint8_t *data, int transfer_length, int out, void *priv) uint8_t _dma_read(uint32_t addr, dma_t *dma_c) { - uint8_t temp; + uint8_t temp = 0; if (dma_advanced) { if (dma_c->sg_status & 1) @@ -1296,7 +1294,7 @@ _dma_read(uint32_t addr, dma_t *dma_c) static uint16_t _dma_readw(uint32_t addr, dma_t *dma_c) { - uint16_t temp; + uint16_t temp = 0; if (dma_advanced) { if (dma_c->sg_status & 1) diff --git a/src/fifo8.c b/src/fifo8.c index 683c44671..feef0deb2 100644 --- a/src/fifo8.c +++ b/src/fifo8.c @@ -84,7 +84,7 @@ fifo8_pop(Fifo8 *fifo) const uint8_t * fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num) { - uint8_t *ret; + const uint8_t *ret; assert(max > 0 && max <= fifo->num); *num = MIN(fifo->capacity - fifo->head, max); diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 99767d857..37e078b76 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -36,6 +36,7 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/fdc_ext.h> +#include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> extern uint64_t motoron[FDD_NUM]; @@ -916,7 +917,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc_bad_command(fdc); break; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x07: /*Recalibrate*/ fdc->pnum = 0; fdc->ptot = 1; @@ -959,7 +962,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc_bad_command(fdc); break; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x10: /*Get version*/ case 0x14: /*Unlock*/ case 0x94: /*Lock*/ @@ -1081,7 +1086,9 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) case 0x16: /* Verify */ if (fdc->params[0] & 0x80) fdc->sc = fdc->params[7]; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x06: /* Read data */ case 0x0c: /* Read deleted data */ fdc_io_command_phase1(fdc, 0); diff --git a/src/floppy/fdd.c b/src/floppy/fdd.c index 16d414af3..2d6892623 100644 --- a/src/floppy/fdd.c +++ b/src/floppy/fdd.c @@ -64,7 +64,7 @@ #define FLAG_IGNORE_DENSEL 512 #define FLAG_PS2 1024 -typedef struct { +typedef struct fdd_t { int type; int track; int densel; @@ -451,10 +451,10 @@ fdd_get_densel(int drive) void fdd_load(int drive, char *fn) { - int c = 0; - int size; - char *p; - FILE *f; + int c = 0; + int size; + const char *p; + FILE * f; fdd_log("FDD: loading drive %d with '%s'\n", drive, fn); @@ -548,8 +548,8 @@ fdd_set_motor_enable(int drive, int motor_enable) static void fdd_poll(void *priv) { - int drive; - DRIVE *drv = (DRIVE *) priv; + int drive; + const DRIVE *drv = (DRIVE *) priv; drive = drv->id; @@ -586,6 +586,9 @@ fdd_get_bitcell_period(int rate) case 3: /*Extended density*/ bit_rate = 1000; break; + + default: + break; } return 1000000 / bit_rate * 2; /*Bitcell period in ns*/ diff --git a/src/floppy/fdd_86f.c b/src/floppy/fdd_86f.c index f2c0ffbbc..0e8085a71 100644 --- a/src/floppy/fdd_86f.c +++ b/src/floppy/fdd_86f.c @@ -180,7 +180,7 @@ typedef struct sector_t { * specifies the entire bitcell count */ typedef struct d86f_t { - FILE *f; + FILE *fp; uint8_t state; uint8_t fill; uint8_t sector_count; @@ -355,7 +355,7 @@ d86f_reverse_bytes(int drive) uint16_t d86f_disk_flags(int drive) { - d86f_t *dev = d86f[drive]; + const d86f_t *dev = d86f[drive]; return dev->disk_flags; } @@ -363,7 +363,7 @@ d86f_disk_flags(int drive) uint32_t d86f_index_hole_pos(int drive, int side) { - d86f_t *dev = d86f[drive]; + const d86f_t *dev = d86f[drive]; return dev->index_hole_pos[side]; } @@ -413,7 +413,7 @@ null_format_conditions(UNUSED(int drive)) int32_t d86f_extra_bit_cells(int drive, int side) { - d86f_t *dev = d86f[drive]; + const d86f_t *dev = d86f[drive]; return dev->extra_bit_cells[side]; } @@ -441,8 +441,8 @@ common_read_revolution(UNUSED(int drive)) uint16_t d86f_side_flags(int drive) { - d86f_t *dev = d86f[drive]; - int side; + const d86f_t *dev = d86f[drive]; + int side; side = fdd_get_head(drive); @@ -811,9 +811,9 @@ d86f_is_mfm(int drive) uint32_t d86f_get_data_len(int drive) { - d86f_t *dev = d86f[drive]; - uint32_t i; - uint32_t ret = 128; + const d86f_t *dev = d86f[drive]; + uint32_t i; + uint32_t ret = 128; if (dev->req_sector.id.n) ret = (uint32_t) 128 << dev->req_sector.id.n; @@ -1243,8 +1243,8 @@ d86f_calccrc(d86f_t *dev, uint8_t byte) int d86f_word_is_aligned(int drive, int side, uint32_t base_pos) { - d86f_t *dev = d86f[drive]; - uint32_t adjusted_track_pos = dev->track_pos; + const d86f_t *dev = d86f[drive]; + uint32_t adjusted_track_pos = dev->track_pos; if (base_pos == 0xFFFFFFFF) return 0; @@ -1659,7 +1659,7 @@ d86f_write_sector_data(int drive, int side, int mfm, uint16_t am) d86f_handler[drive].write_data(drive, side, dev->data_find.bytes_obtained - 1, dev->current_byte[side]); } else { /* We're in the data field of the sector, use a CRC byte. */ - dev->current_byte[side] = dev->calc_crc.bytes[(dev->data_find.bytes_obtained & 1)]; + dev->current_byte[side] = dev->calc_crc.bytes[dev->data_find.bytes_obtained & 1]; } dev->current_bit[side] = (15 - (dev->data_find.bits_obtained & 15)) >> 1; @@ -1841,7 +1841,7 @@ d86f_write_direct_common(int drive, int side, uint16_t byte, uint8_t type, uint3 void d86f_write_direct(int drive, int side, uint16_t byte, uint8_t type) { - d86f_t *dev = d86f[drive]; + const d86f_t *dev = d86f[drive]; d86f_write_direct_common(drive, side, byte, type, dev->track_pos >> 4); } @@ -1951,7 +1951,9 @@ d86f_format_track(int drive, int side, int do_write) if (dev->datac == 3) fdc_stop_id_request(d86f_fdc); } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case FMT_PRETRK_SYNC: case FMT_SECTOR_DATA_SYNC: @@ -2106,9 +2108,9 @@ d86f_initialize_last_sector_id(int drive, int c, int h, int r, int n) static uint8_t d86f_sector_flags(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { - d86f_t *dev = d86f[drive]; - sector_t *s; - sector_t *t; + const d86f_t *dev = d86f[drive]; + sector_t *s; + sector_t *t; if (dev->last_side_sector[side]) { s = dev->last_side_sector[side]; @@ -2257,9 +2259,9 @@ d86f_turbo_format(int drive, int side, int nop) int d86f_sector_is_present(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { - d86f_t *dev = d86f[drive]; - sector_t *s; - sector_t *t; + const d86f_t *dev = d86f[drive]; + sector_t *s; + sector_t *t; if (dev->last_side_sector[side]) { s = dev->last_side_sector[side]; @@ -2294,7 +2296,9 @@ d86f_turbo_poll(int drive, int side) case STATE_0D_SPIN_TO_INDEX: dev->sector_count = 0; dev->datac = 5; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_02_SPIN_TO_INDEX: dev->state++; @@ -2339,7 +2343,9 @@ d86f_turbo_poll(int drive, int side) dev->last_sector.id.r = dev->req_sector.id.r; dev->last_sector.id.n = dev->req_sector.id.n; d86f_handler[drive].set_sector(drive, side, dev->last_sector.id.c, dev->last_sector.id.h, dev->last_sector.id.r, dev->last_sector.id.n); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_0A_FIND_ID: dev->turbo_pos = 0; @@ -2800,22 +2806,22 @@ d86f_construct_encoded_buffer(int drive, int side) /* *_fuzm are fuzzy bit masks, *_holm are hole masks, dst_neim are masks is mask for bits that are neither fuzzy nor holes in both, and src1_d and src2_d are filtered source data. */ - uint16_t src1_fuzm; - uint16_t src2_fuzm; - uint16_t dst_fuzm; - uint16_t src1_holm; - uint16_t src2_holm; - uint16_t dst_holm; - uint16_t dst_neim; - uint16_t src1_d; - uint16_t src2_d; - uint32_t len; - uint16_t *dst = dev->track_encoded_data[side]; - uint16_t *dst_s = dev->track_surface_data[side]; - uint16_t *src1 = dev->thin_track_encoded_data[0][side]; - uint16_t *src1_s = dev->thin_track_surface_data[0][side]; - uint16_t *src2 = dev->thin_track_encoded_data[1][side]; - uint16_t *src2_s = dev->thin_track_surface_data[1][side]; + uint16_t src1_fuzm; + uint16_t src2_fuzm; + uint16_t dst_fuzm; + uint16_t src1_holm; + uint16_t src2_holm; + uint16_t dst_holm; + uint16_t dst_neim; + uint16_t src1_d; + uint16_t src2_d; + uint32_t len; + uint16_t *dst = dev->track_encoded_data[side]; + uint16_t *dst_s = dev->track_surface_data[side]; + const uint16_t *src1 = dev->thin_track_encoded_data[0][side]; + const uint16_t *src1_s = dev->thin_track_surface_data[0][side]; + const uint16_t *src2 = dev->thin_track_encoded_data[1][side]; + const uint16_t *src2_s = dev->thin_track_surface_data[1][side]; len = d86f_get_array_size(drive, side, 1); for (uint32_t i = 0; i < len; i++) { @@ -2852,17 +2858,17 @@ d86f_construct_encoded_buffer(int drive, int side) void d86f_decompose_encoded_buffer(int drive, int side) { - d86f_t *dev = d86f[drive]; - uint16_t temp; - uint16_t temp2; - uint32_t len; - uint16_t *dst = dev->track_encoded_data[side]; - uint16_t *src1 = dev->thin_track_encoded_data[0][side]; - uint16_t *src1_s = dev->thin_track_surface_data[0][side]; - uint16_t *src2 = dev->thin_track_encoded_data[1][side]; - uint16_t *src2_s = dev->thin_track_surface_data[1][side]; - dst = d86f_handler[drive].encoded_data(drive, side); - len = d86f_get_array_size(drive, side, 1); + d86f_t *dev = d86f[drive]; + uint16_t temp; + uint16_t temp2; + uint32_t len; + const uint16_t *dst = dev->track_encoded_data[side]; + uint16_t *src1 = dev->thin_track_encoded_data[0][side]; + uint16_t *src1_s = dev->thin_track_surface_data[0][side]; + uint16_t *src2 = dev->thin_track_encoded_data[1][side]; + uint16_t *src2_s = dev->thin_track_surface_data[1][side]; + dst = d86f_handler[drive].encoded_data(drive, side); + len = d86f_get_array_size(drive, side, 1); for (uint32_t i = 0; i < len; i++) { if (d86f_has_surface_desc(drive)) { @@ -2905,12 +2911,12 @@ d86f_read_track(int drive, int track, int thin_track, int side, uint16_t *da, ui if (dev->track_offset[logical_track]) { if (!thin_track) { - if (fseek(dev->f, dev->track_offset[logical_track], SEEK_SET) == -1) + if (fseek(dev->fp, dev->track_offset[logical_track], SEEK_SET) == -1) fatal("d86f_read_track(): Error seeking to offset dev->track_offset[logical_track]\n"); - if (fread(&(dev->side_flags[side]), 1, 2, dev->f) != 2) + if (fread(&(dev->side_flags[side]), 1, 2, dev->fp) != 2) fatal("d86f_read_track(): Error reading side flags\n"); if (d86f_has_extra_bit_cells(drive)) { - if (fread(&(dev->extra_bit_cells[side]), 1, 4, dev->f) != 4) + if (fread(&(dev->extra_bit_cells[side]), 1, 4, dev->fp) != 4) fatal("d86f_read_track(): Error reading number of extra bit cells\n"); /* If RPM shift is 0% and direction is 1, do not adjust extra bit cells, as that is the whole track length. */ @@ -2922,13 +2928,13 @@ d86f_read_track(int drive, int track, int thin_track, int side, uint16_t *da, ui } } else dev->extra_bit_cells[side] = 0; - (void) !fread(&(dev->index_hole_pos[side]), 4, 1, dev->f); + (void) !fread(&(dev->index_hole_pos[side]), 4, 1, dev->fp); } else - fseek(dev->f, dev->track_offset[logical_track] + d86f_track_header_size(drive), SEEK_SET); + fseek(dev->fp, dev->track_offset[logical_track] + d86f_track_header_size(drive), SEEK_SET); array_size = d86f_get_array_size(drive, side, 0); - (void) !fread(da, 1, array_size, dev->f); + (void) !fread(da, 1, array_size, dev->fp); if (d86f_has_surface_desc(drive)) - (void) !fread(sa, 1, array_size, dev->f); + (void) !fread(sa, 1, array_size, dev->fp); } else { if (!thin_track) { switch ((dev->disk_flags >> 1) & 3) { @@ -3125,22 +3131,22 @@ d86f_writeback(int drive) #endif header_size = d86f_header_size(drive); - if (!dev->f) + if (!dev->fp) return; /* First write the track offsets table. */ - if (fseek(dev->f, 0, SEEK_SET) == -1) + if (fseek(dev->fp, 0, SEEK_SET) == -1) fatal("86F write_back(): Error seeking to the beginning of the file\n"); - if (fread(header, 1, header_size, dev->f) != header_size) + if (fread(header, 1, header_size, dev->fp) != header_size) fatal("86F write_back(): Error reading header size\n"); - if (fseek(dev->f, 8, SEEK_SET) == -1) + if (fseek(dev->fp, 8, SEEK_SET) == -1) fatal("86F write_back(): Error seeking\n"); size = d86f_get_track_table_size(drive); - if (fwrite(dev->track_offset, 1, size, dev->f) != size) + if (fwrite(dev->track_offset, 1, size, dev->fp) != size) fatal("86F write_back(): Error writing data\n"); - d86f_write_tracks(drive, &dev->f, NULL); + d86f_write_tracks(drive, &dev->fp, NULL); #ifdef D86F_COMPRESS if (dev->is_compressed) { @@ -3152,16 +3158,16 @@ d86f_writeback(int drive) /* Write the header to the original file. */ fwrite(header, 1, header_size, cf); - fseek(dev->f, 0, SEEK_END); - len = ftell(dev->f); + fseek(dev->fp, 0, SEEK_END); + len = ftell(dev->fp); len -= header_size; - fseek(dev->f, header_size, SEEK_SET); + fseek(dev->fp, header_size, SEEK_SET); /* Compress data from the temporary uncompressed file to the original, compressed file. */ dev->filebuf = (uint8_t *) malloc(len); dev->outbuf = (uint8_t *) malloc(len - 1); - fread(dev->filebuf, 1, len, dev->f); + fread(dev->filebuf, 1, len, dev->fp); ret = lzf_compress(dev->filebuf, len, dev->outbuf, len - 1); if (!ret) @@ -3421,7 +3427,7 @@ d86f_export(int drive, char *fn) uint32_t tt[512]; d86f_t *dev = d86f[drive]; d86f_t *temp86; - FILE *f; + FILE *fp; int tracks = 86; int inc = 1; uint32_t magic = 0x46423638; @@ -3430,19 +3436,19 @@ d86f_export(int drive, char *fn) memset(tt, 0, 512 * sizeof(uint32_t)); - f = plat_fopen(fn, "wb"); - if (!f) + fp = plat_fopen(fn, "wb"); + if (!fp) return 0; /* Allocate a temporary drive for conversion. */ temp86 = (d86f_t *) malloc(sizeof(d86f_t)); memcpy(temp86, dev, sizeof(d86f_t)); - fwrite(&magic, 4, 1, f); - fwrite(&version, 2, 1, f); - fwrite(&disk_flags, 2, 1, f); + fwrite(&magic, 4, 1, fp); + fwrite(&version, 2, 1, fp); + fwrite(&disk_flags, 2, 1, fp); - fwrite(tt, 1, ((d86f_get_sides(drive) == 2) ? 2048 : 1024), f); + fwrite(tt, 1, ((d86f_get_sides(drive) == 2) ? 2048 : 1024), fp); /* In the case of a thick track drive, always increment track by two, since two tracks are going to get output at once. */ @@ -3455,17 +3461,17 @@ d86f_export(int drive, char *fn) else fdd_do_seek(drive, i); dev->cur_track = i; - d86f_write_tracks(drive, &f, tt); + d86f_write_tracks(drive, &fp, tt); } - fclose(f); + fclose(fp); - f = plat_fopen(fn, "rb+"); + fp = plat_fopen(fn, "rb+"); - fseek(f, 8, SEEK_SET); - fwrite(tt, 1, ((d86f_get_sides(drive) == 2) ? 2048 : 1024), f); + fseek(fp, 8, SEEK_SET); + fwrite(tt, 1, ((d86f_get_sides(drive) == 2) ? 2048 : 1024), fp); - fclose(f); + fclose(fp); fdd_do_seek(drive, fdd_current_track(drive)); @@ -3492,10 +3498,10 @@ d86f_load(int drive, char *fn) writeprot[drive] = 0; - dev->f = plat_fopen(fn, "rb+"); - if (!dev->f) { - dev->f = plat_fopen(fn, "rb"); - if (!dev->f) { + dev->fp = plat_fopen(fn, "rb+"); + if (!dev->fp) { + dev->fp = plat_fopen(fn, "rb"); + if (!dev->fp) { memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -3508,16 +3514,16 @@ d86f_load(int drive, char *fn) } fwriteprot[drive] = writeprot[drive]; - fseek(dev->f, 0, SEEK_END); - len = ftell(dev->f); - fseek(dev->f, 0, SEEK_SET); + fseek(dev->fp, 0, SEEK_END); + len = ftell(dev->fp); + fseek(dev->fp, 0, SEEK_SET); - (void) !fread(&magic, 4, 1, dev->f); + (void) !fread(&magic, 4, 1, dev->fp); if (len < 16) { /* File is WAY too small, abort. */ - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -3526,13 +3532,13 @@ d86f_load(int drive, char *fn) if ((magic != 0x46423638) && (magic != 0x66623638)) { /* File is not of the valid format, abort. */ d86f_log("86F: Unrecognized magic bytes: %08X\n", magic); - fclose(dev->f); + fclose(dev->fp); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; } - if (fread(&(dev->version), 1, 2, dev->f) != 2) + if (fread(&(dev->version), 1, 2, dev->fp) != 2) fatal("d86f_load(): Error reading format version\n"); if (dev->version != D86FVER) { @@ -3544,8 +3550,8 @@ d86f_load(int drive, char *fn) } else { d86f_log("86F: Unrecognized file version: %i.%02i\n", dev->version >> 8, dev->version & 0xff); } - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -3553,7 +3559,7 @@ d86f_load(int drive, char *fn) d86f_log("86F: Recognized file version: %i.%02i\n", dev->version >> 8, dev->version & 0xff); } - (void) !fread(&(dev->disk_flags), 2, 1, dev->f); + (void) !fread(&(dev->disk_flags), 2, 1, dev->fp); if (d86f_has_surface_desc(drive)) { for (uint8_t i = 0; i < 2; i++) @@ -3572,31 +3578,31 @@ d86f_load(int drive, char *fn) if (len < 51052) { #endif /* File too small, abort. */ - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; } #ifdef DO_CRC64 - fseek(dev->f, 8, SEEK_SET); - fread(&read_crc64, 1, 8, dev->f); + fseek(dev->fp, 8, SEEK_SET); + fread(&read_crc64, 1, 8, dev->fp); - fseek(dev->f, 0, SEEK_SET); + fseek(dev->fp, 0, SEEK_SET); crc64 = 0xffffffffffffffff; dev->filebuf = malloc(len); - fread(dev->filebuf, 1, len, dev->f); + fread(dev->filebuf, 1, len, dev->fp); *(uint64_t *) &(dev->filebuf[8]) = 0xffffffffffffffff; crc64 = (uint64_t) crc64speed(0, dev->filebuf, len); free(dev->filebuf); if (crc64 != read_crc64) { d86f_log("86F: CRC64 error\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -3608,11 +3614,11 @@ d86f_load(int drive, char *fn) memcpy(temp_file_name, drive ? nvr_path("TEMP$$$1.$$$") : nvr_path("TEMP$$$0.$$$"), 256); memcpy(dev->original_file_name, fn, strlen(fn) + 1); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; - dev->f = plat_fopen(temp_file_name, "wb"); - if (!dev->f) { + dev->fp = plat_fopen(temp_file_name, "wb"); + if (!dev->fp) { d86f_log("86F: Unable to create temporary decompressed file\n"); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); @@ -3621,9 +3627,9 @@ d86f_load(int drive, char *fn) tf = plat_fopen(fn, "rb"); - for (i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { fread(&temp, 1, 2, tf); - fwrite(&temp, 1, 2, dev->f); + fwrite(&temp, 1, 2, dev->fp); } dev->filebuf = (uint8_t *) malloc(len); @@ -3631,14 +3637,14 @@ d86f_load(int drive, char *fn) fread(dev->filebuf, 1, len, tf); temp = lzf_decompress(dev->filebuf, len, dev->outbuf, 67108864); if (temp) { - fwrite(dev->outbuf, 1, temp, dev->f); + fwrite(dev->outbuf, 1, temp, dev->fp); } free(dev->outbuf); free(dev->filebuf); fclose(tf); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; if (!temp) { d86f_log("86F: Error decompressing file\n"); @@ -3648,15 +3654,15 @@ d86f_load(int drive, char *fn) return; } - dev->f = plat_fopen(temp_file_name, "rb+"); + dev->fp = plat_fopen(temp_file_name, "rb+"); } #endif if (dev->disk_flags & 0x100) { /* Zoned disk. */ d86f_log("86F: Disk is zoned (Apple or Sony)\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; #ifdef D86F_COMPRESS if (dev->is_compressed) plat_remove(temp_file_name); @@ -3669,8 +3675,8 @@ d86f_load(int drive, char *fn) if (dev->disk_flags & 0x600) { /* Zone type is not 0 but the disk is fixed-RPM. */ d86f_log("86F: Disk is fixed-RPM but zone type is not 0\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; #ifdef D86F_COMPRESS if (dev->is_compressed) plat_remove(temp_file_name); @@ -3686,29 +3692,29 @@ d86f_load(int drive, char *fn) } if (writeprot[drive]) { - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; #ifdef D86F_COMPRESS if (dev->is_compressed) - dev->f = plat_fopen(temp_file_name, "rb"); + dev->fp = plat_fopen(temp_file_name, "rb"); else #endif - dev->f = plat_fopen(fn, "rb"); + dev->fp = plat_fopen(fn, "rb"); } /* OK, set the drive data, other code needs it. */ d86f[drive] = dev; - fseek(dev->f, 8, SEEK_SET); + fseek(dev->fp, 8, SEEK_SET); - (void) !fread(dev->track_offset, 1, d86f_get_track_table_size(drive), dev->f); + (void) !fread(dev->track_offset, 1, d86f_get_track_table_size(drive), dev->fp); if (!(dev->track_offset[0])) { /* File has no track 0 side 0, abort. */ d86f_log("86F: No Track 0 side 0\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); d86f[drive] = NULL; @@ -3718,8 +3724,8 @@ d86f_load(int drive, char *fn) if ((d86f_get_sides(drive) == 2) && !(dev->track_offset[1])) { /* File is 2-sided but has no track 0 side 1, abort. */ d86f_log("86F: No Track 0 side 1\n"); - fclose(dev->f); - dev->f = NULL; + fclose(dev->fp); + dev->fp = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); d86f[drive] = NULL; @@ -3727,12 +3733,12 @@ d86f_load(int drive, char *fn) } /* Load track 0 flags as default. */ - if (fseek(dev->f, dev->track_offset[0], SEEK_SET) == -1) + if (fseek(dev->fp, dev->track_offset[0], SEEK_SET) == -1) fatal("d86f_load(): Track 0: Error seeking to the beginning of the file\n"); - if (fread(&(dev->side_flags[0]), 1, 2, dev->f) != 2) + if (fread(&(dev->side_flags[0]), 1, 2, dev->fp) != 2) fatal("d86f_load(): Track 0: Error reading side flags\n"); if (dev->disk_flags & 0x80) { - if (fread(&(dev->extra_bit_cells[0]), 1, 4, dev->f) != 4) + if (fread(&(dev->extra_bit_cells[0]), 1, 4, dev->fp) != 4) fatal("d86f_load(): Track 0: Error reading the amount of extra bit cells\n"); if ((dev->disk_flags & 0x1060) != 0x1000) { if (dev->extra_bit_cells[0] < -32768) @@ -3745,12 +3751,12 @@ d86f_load(int drive, char *fn) } if (d86f_get_sides(drive) == 2) { - if (fseek(dev->f, dev->track_offset[1], SEEK_SET) == -1) + if (fseek(dev->fp, dev->track_offset[1], SEEK_SET) == -1) fatal("d86f_load(): Track 1: Error seeking to the beginning of the file\n"); - if (fread(&(dev->side_flags[1]), 1, 2, dev->f) != 2) + if (fread(&(dev->side_flags[1]), 1, 2, dev->fp) != 2) fatal("d86f_load(): Track 1: Error reading side flags\n"); if (dev->disk_flags & 0x80) { - if (fread(&(dev->extra_bit_cells[1]), 1, 4, dev->f) != 4) + if (fread(&(dev->extra_bit_cells[1]), 1, 4, dev->fp) != 4) fatal("d86f_load(): Track 4: Error reading the amount of extra bit cells\n"); if ((dev->disk_flags & 0x1060) != 0x1000) { if (dev->extra_bit_cells[1] < -32768) @@ -3781,10 +3787,10 @@ d86f_load(int drive, char *fn) dev->extra_bit_cells[1] = 0; } - fseek(dev->f, 0, SEEK_END); - dev->file_size = ftell(dev->f); + fseek(dev->fp, 0, SEEK_END); + dev->file_size = ftell(dev->fp); - fseek(dev->f, 0, SEEK_SET); + fseek(dev->fp, 0, SEEK_SET); d86f_register_86f(drive); @@ -3847,9 +3853,9 @@ d86f_close(int drive) } } - if (dev->f) { - fclose(dev->f); - dev->f = NULL; + if (dev->fp) { + fclose(dev->fp); + dev->fp = NULL; } #ifdef D86F_COMPRESS if (dev->is_compressed) diff --git a/src/floppy/fdd_fdi.c b/src/floppy/fdd_fdi.c index a1a2a61ee..f14bf2cd4 100644 --- a/src/floppy/fdd_fdi.c +++ b/src/floppy/fdd_fdi.c @@ -36,8 +36,8 @@ #include <86box/fdc.h> #include -typedef struct { - FILE *f; +typedef struct fdi_t { + FILE *fp; FDI *h; int lasttrack; @@ -176,10 +176,10 @@ fdi_density(void) static int32_t extra_bit_cells(int drive, int side) { - fdi_t *dev = fdi[drive]; - int density = 0; - int raw_size = 0; - int is_300_rpm = 0; + const fdi_t *dev = fdi[drive]; + int density = 0; + int raw_size = 0; + int is_300_rpm = 0; density = fdi_density(); @@ -249,8 +249,8 @@ read_revolution(int drive) static uint32_t index_hole_pos(int drive, int side) { - fdi_t *dev = fdi[drive]; - int density; + const fdi_t *dev = fdi[drive]; + int density; density = fdi_density(); @@ -260,8 +260,8 @@ index_hole_pos(int drive, int side) static uint32_t get_raw_size(int drive, int side) { - fdi_t *dev = fdi[drive]; - int density; + const fdi_t *dev = fdi[drive]; + int density; density = fdi_density(); @@ -291,7 +291,7 @@ fdi_seek(int drive, int track) d86f_set_cur_track(drive, track); - if (dev->f == NULL) + if (dev->fp == NULL) return; if (track < 0) @@ -327,16 +327,16 @@ fdi_load(int drive, char *fn) d86f_unregister(drive); - dev->f = plat_fopen(fn, "rb"); - if (fread(header, 1, 25, dev->f) != 25) + dev->fp = plat_fopen(fn, "rb"); + if (fread(header, 1, 25, dev->fp) != 25) fatal("fdi_load(): Error reading header\n"); - if (fseek(dev->f, 0, SEEK_SET) == -1) + if (fseek(dev->fp, 0, SEEK_SET) == -1) fatal("fdi_load(): Error seeking to the beginning of the file\n"); header[25] = 0; if (strcmp(header, "Formatted Disk Image file") != 0) { /* This is a Japanese FDI file. */ fdi_log("fdi_load(): Japanese FDI file detected, redirecting to IMG loader\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); img_load(drive, fn); return; @@ -345,7 +345,7 @@ fdi_load(int drive, char *fn) /* Set up the drive unit. */ fdi[drive] = dev; - dev->h = fdi2raw_header(dev->f); + dev->h = fdi2raw_header(dev->fp); dev->lasttrack = fdi2raw_get_last_track(dev->h); dev->sides = fdi2raw_get_last_head(dev->h) + 1; @@ -386,8 +386,8 @@ fdi_close(int drive) if (dev->h) fdi2raw_header_free(dev->h); - if (dev->f) - fclose(dev->f); + if (dev->fp) + fclose(dev->fp); /* Release the memory. */ free(dev); diff --git a/src/floppy/fdd_imd.c b/src/floppy/fdd_imd.c index 211b18373..a5cd8f056 100644 --- a/src/floppy/fdd_imd.c +++ b/src/floppy/fdd_imd.c @@ -31,7 +31,7 @@ #include <86box/fdd_imd.h> #include <86box/fdc.h> -typedef struct { +typedef struct imd_track_t { uint8_t is_present; uint32_t file_offs; uint8_t params[5]; @@ -47,8 +47,8 @@ typedef struct { uint8_t max_sector_size; } imd_track_t; -typedef struct { - FILE *f; +typedef struct imd_t { + FILE *fp; char *buffer; uint32_t start_offs; int track_count; @@ -136,21 +136,20 @@ get_raw_tsize(int side_flags, int slower_rpm) static int track_is_xdf(int drive, int side, int track) { - imd_t *dev = imd[drive]; - int i; - int effective_sectors; - int xdf_sectors; - int high_sectors; - int low_sectors; - int max_high_id; - int expected_high_count; - int expected_low_count; - uint8_t *r_map; - uint8_t *n_map; + imd_t *dev = imd[drive]; + int effective_sectors; + int xdf_sectors; + int high_sectors; + int low_sectors; + int max_high_id; + int expected_high_count; + int expected_low_count; + const uint8_t *r_map; + const uint8_t *n_map; effective_sectors = xdf_sectors = high_sectors = low_sectors = 0; - for (i = 0; i < 256; i++) + for (uint16_t i = 0; i < 256; i++) dev->xdf_ordered_pos[i][side] = 0; if (dev->tracks[track][side].params[2] & 0xC0) @@ -175,7 +174,7 @@ track_is_xdf(int drive, int side, int track) expected_low_count = 0; } - for (i = 0; i < dev->tracks[track][side].params[3]; i++) { + for (uint8_t i = 0; i < dev->tracks[track][side].params[3]; i++) { if ((r_map[i] >= 0x81) && (r_map[i] <= max_high_id)) { high_sectors++; dev->xdf_ordered_pos[(int) r_map[i]][side] = i; @@ -196,7 +195,7 @@ track_is_xdf(int drive, int side, int track) n_map = (uint8_t *) (dev->buffer + dev->tracks[track][side].n_map_offs); - for (i = 0; i < dev->tracks[track][side].params[3]; i++) { + for (uint8_t i = 0; i < dev->tracks[track][side].params[3]; i++) { effective_sectors++; if (!(r_map[i]) && !(n_map[i])) effective_sectors--; @@ -224,10 +223,10 @@ track_is_xdf(int drive, int side, int track) static int track_is_interleave(int drive, int side, int track) { - imd_t *dev = imd[drive]; - int effective_sectors; - char *r_map; - int track_spt; + imd_t *dev = imd[drive]; + int effective_sectors; + const char *r_map; + int track_spt; effective_sectors = 0; @@ -263,9 +262,9 @@ track_is_interleave(int drive, int side, int track) static void sector_to_buffer(int drive, int track, int side, uint8_t *buffer, int sector, int len) { - imd_t *dev = imd[drive]; - int type = dev->buffer[dev->tracks[track][side].sector_data_offs[sector]]; - uint8_t fill_char; + const imd_t *dev = imd[drive]; + int type = dev->buffer[dev->tracks[track][side].sector_data_offs[sector]]; + uint8_t fill_char; if (type == 0) memset(buffer, 0x00, len); @@ -282,35 +281,35 @@ sector_to_buffer(int drive, int track, int side, uint8_t *buffer, int sector, in static void imd_seek(int drive, int track) { - uint32_t track_buf_pos[2] = { 0, 0 }; - uint8_t id[4] = { 0, 0, 0, 0 }; - uint8_t type; - imd_t *dev = imd[drive]; - int sector; - int current_pos; - int c = 0; - int h; - int n; - int ssize = 512; - int track_rate = 0; - int track_gap2 = 22; - int track_gap3 = 12; - int xdf_type = 0; - int interleave_type = 0; - int is_trackx = 0; - int xdf_spt = 0; - int xdf_sector = 0; - int ordered_pos = 0; - int real_sector = 0; - int actual_sector = 0; - char *c_map = NULL; - char *h_map = NULL; - char *r_map; - char *n_map = NULL; - uint8_t *data; - int flags = 0x00; + uint32_t track_buf_pos[2] = { 0, 0 }; + uint8_t id[4] = { 0, 0, 0, 0 }; + uint8_t type; + imd_t *dev = imd[drive]; + int sector; + int current_pos; + int c = 0; + int h; + int n; + int ssize = 512; + int track_rate = 0; + int track_gap2 = 22; + int track_gap3 = 12; + int xdf_type = 0; + int interleave_type = 0; + int is_trackx = 0; + int xdf_spt = 0; + int xdf_sector = 0; + int ordered_pos = 0; + int real_sector = 0; + int actual_sector = 0; + const char *c_map = NULL; + const char *h_map = NULL; + const char *r_map; + const char *n_map = NULL; + uint8_t *data; + int flags = 0x00; - if (dev->f == NULL) + if (dev->fp == NULL) return; if (!dev->track_width && fdd_doublestep_40(drive)) @@ -452,7 +451,7 @@ imd_seek(int drive, int track) static uint16_t disk_flags(int drive) { - imd_t *dev = imd[drive]; + const imd_t *dev = imd[drive]; return (dev->disk_flags); } @@ -460,9 +459,9 @@ disk_flags(int drive) static uint16_t side_flags(int drive) { - imd_t *dev = imd[drive]; - int side = 0; - uint16_t sflags = 0; + const imd_t *dev = imd[drive]; + int side = 0; + uint16_t sflags = 0; side = fdd_get_head(drive); sflags = dev->current_side_flags[side]; @@ -473,19 +472,19 @@ side_flags(int drive) static void set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { - imd_t *dev = imd[drive]; - int track = dev->track; - int sc; - int sh; - int sn; - char *c_map = NULL; - char *h_map = NULL; - char *r_map = NULL; - char *n_map = NULL; - uint8_t id[4] = { 0, 0, 0, 0 }; - sc = dev->tracks[track][side].params[1]; - sh = dev->tracks[track][side].params[2]; - sn = dev->tracks[track][side].params[4]; + imd_t *dev = imd[drive]; + int track = dev->track; + int sc; + int sh; + int sn; + const char *c_map = NULL; + const char *h_map = NULL; + const char *r_map = NULL; + const char *n_map = NULL; + uint8_t id[4] = { 0, 0, 0, 0 }; + sc = dev->tracks[track][side].params[1]; + sh = dev->tracks[track][side].params[2]; + sn = dev->tracks[track][side].params[4]; if (sh & 0x80) c_map = dev->buffer + dev->tracks[track][side].c_map_offs; @@ -513,39 +512,39 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) static void imd_writeback(int drive) { - imd_t *dev = imd[drive]; - int track = dev->track; - char *n_map = 0; - uint8_t h; - uint8_t n; - uint8_t spt; - uint32_t ssize; + imd_t *dev = imd[drive]; + int track = dev->track; + const char *n_map = 0; + uint8_t h; + uint8_t n; + uint8_t spt; + uint32_t ssize; if (writeprot[drive]) return; for (int side = 0; side < dev->sides; side++) { if (dev->tracks[track][side].is_present) { - fseek(dev->f, dev->tracks[track][side].file_offs, SEEK_SET); + fseek(dev->fp, dev->tracks[track][side].file_offs, SEEK_SET); h = dev->tracks[track][side].params[2]; spt = dev->tracks[track][side].params[3]; n = dev->tracks[track][side].params[4]; - fwrite(dev->tracks[track][side].params, 1, 5, dev->f); + fwrite(dev->tracks[track][side].params, 1, 5, dev->fp); if (h & 0x80) - fwrite(dev->buffer + dev->tracks[track][side].c_map_offs, 1, spt, dev->f); + fwrite(dev->buffer + dev->tracks[track][side].c_map_offs, 1, spt, dev->fp); if (h & 0x40) - fwrite(dev->buffer + dev->tracks[track][side].h_map_offs, 1, spt, dev->f); + fwrite(dev->buffer + dev->tracks[track][side].h_map_offs, 1, spt, dev->fp); if (n == 0xFF) { n_map = dev->buffer + dev->tracks[track][side].n_map_offs; - fwrite(n_map, 1, spt, dev->f); + fwrite(n_map, 1, spt, dev->fp); } for (uint8_t i = 0; i < spt; i++) { ssize = (n == 0xFF) ? n_map[i] : n; ssize = 128 << ssize; - fwrite(dev->buffer + dev->tracks[track][side].sector_data_offs[i], 1, ssize, dev->f); + fwrite(dev->buffer + dev->tracks[track][side].sector_data_offs[i], 1, ssize, dev->fp); } } } @@ -554,8 +553,8 @@ imd_writeback(int drive) static uint8_t poll_read_data(int drive, int side, uint16_t pos) { - imd_t *dev = imd[drive]; - int type = dev->current_data[side][0]; + const imd_t *dev = imd[drive]; + int type = dev->current_data[side][0]; if ((type == 0) || (type > 8)) return 0xf6; /* Should never happen. */ @@ -569,8 +568,8 @@ poll_read_data(int drive, int side, uint16_t pos) static void poll_write_data(int drive, int side, uint16_t pos, uint8_t data) { - imd_t *dev = imd[drive]; - int type = dev->current_data[side][0]; + const imd_t *dev = imd[drive]; + int type = dev->current_data[side][0]; if (writeprot[drive]) return; @@ -584,10 +583,10 @@ poll_write_data(int drive, int side, uint16_t pos, uint8_t data) static int format_conditions(int drive) { - imd_t *dev = imd[drive]; - int track = dev->track; - int side; - int temp; + const imd_t *dev = imd[drive]; + int track = dev->track; + int side; + int temp; side = fdd_get_head(drive); temp = (fdc_get_format_sectors(imd_fdc) == dev->tracks[track][side].params[3]); @@ -605,29 +604,28 @@ imd_init(void) void imd_load(int drive, char *fn) { - uint32_t magic = 0; - uint32_t fsize = 0; - char *buffer; - char *buffer2; - imd_t *dev; - int i = 0; - int track_spt = 0; - int sector_size = 0; - int track = 0; - int side = 0; - int extra = 0; - uint32_t last_offset = 0; - uint32_t data_size = 512; - uint32_t mfm = 0; - uint32_t pre_sector = 0; - uint32_t track_total = 0; - uint32_t raw_tsize = 0; - uint32_t minimum_gap3 = 0; - uint32_t minimum_gap4 = 0; - uint8_t converted_rate; - uint8_t type; - int size_diff; - int gap_sum; + uint32_t magic = 0; + uint32_t fsize = 0; + const char *buffer; + const char *buffer2; + imd_t *dev; + int track_spt = 0; + int sector_size = 0; + int track = 0; + int side = 0; + int extra = 0; + uint32_t last_offset = 0; + uint32_t data_size = 512; + uint32_t mfm = 0; + uint32_t pre_sector = 0; + uint32_t track_total = 0; + uint32_t raw_tsize = 0; + uint32_t minimum_gap3 = 0; + uint32_t minimum_gap4 = 0; + uint8_t converted_rate; + uint8_t type; + int size_diff; + int gap_sum; d86f_unregister(drive); @@ -637,10 +635,10 @@ imd_load(int drive, char *fn) dev = (imd_t *) malloc(sizeof(imd_t)); memset(dev, 0x00, sizeof(imd_t)); - dev->f = plat_fopen(fn, "rb+"); - if (dev->f == NULL) { - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb+"); + if (dev->fp == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); return; @@ -652,40 +650,40 @@ imd_load(int drive, char *fn) writeprot[drive] = 1; fwriteprot[drive] = writeprot[drive]; - if (fseek(dev->f, 0, SEEK_SET) == -1) + if (fseek(dev->fp, 0, SEEK_SET) == -1) fatal("imd_load(): Error seeking to the beginning of the file\n"); - if (fread(&magic, 1, 4, dev->f) != 4) + if (fread(&magic, 1, 4, dev->fp) != 4) fatal("imd_load(): Error reading the magic number\n"); if (magic != 0x20444D49) { imd_log("IMD: Not a valid ImageDisk image\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; } else imd_log("IMD: Valid ImageDisk image\n"); - if (fseek(dev->f, 0, SEEK_END) == -1) + if (fseek(dev->fp, 0, SEEK_END) == -1) fatal("imd_load(): Error seeking to the end of the file\n"); - fsize = ftell(dev->f); + fsize = ftell(dev->fp); if (fsize <= 0) { imd_log("IMD: Too small ImageDisk image\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; } - if (fseek(dev->f, 0, SEEK_SET) == -1) + if (fseek(dev->fp, 0, SEEK_SET) == -1) fatal("imd_load(): Error seeking to the beginning of the file again\n"); dev->buffer = malloc(fsize); - if (fread(dev->buffer, 1, fsize, dev->f) != fsize) + if (fread(dev->buffer, 1, fsize, dev->fp) != fsize) fatal("imd_load(): Error reading data\n"); buffer = dev->buffer; buffer2 = memchr(buffer, 0x1A, fsize); if (buffer2 == NULL) { imd_log("IMD: No ASCII EOF character\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -696,7 +694,7 @@ imd_load(int drive, char *fn) buffer2++; if ((buffer2 - buffer) == fsize) { imd_log("IMD: File ends after ASCII EOF character\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -775,7 +773,7 @@ imd_load(int drive, char *fn) dev->tracks[track][side].data_offs = last_offset; - for (i = 0; i < track_spt; i++) { + for (int i = 0; i < track_spt; i++) { data_size = buffer2[i]; data_size = 128 << data_size; dev->tracks[track][side].sector_data_offs[i] = last_offset; @@ -784,7 +782,7 @@ imd_load(int drive, char *fn) /* Invalid sector data type, possibly a malformed HxC IMG image (it outputs data errored sectors with a variable amount of bytes, against the specification). */ imd_log("IMD: Invalid sector data type %02X\n", dev->buffer[dev->tracks[track][side].sector_data_offs[i]]); - fclose(dev->f); + fclose(dev->fp); free(dev); imd[drive] = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); @@ -807,7 +805,7 @@ imd_load(int drive, char *fn) } else { dev->tracks[track][side].data_offs = last_offset; - for (i = 0; i < track_spt; i++) { + for (int i = 0; i < track_spt; i++) { data_size = sector_size; data_size = 128 << data_size; dev->tracks[track][side].sector_data_offs[i] = last_offset; @@ -816,7 +814,7 @@ imd_load(int drive, char *fn) /* Invalid sector data type, possibly a malformed HxC IMG image (it outputs data errored sectors with a variable amount of bytes, against the specification). */ imd_log("IMD: Invalid sector data type %02X\n", dev->buffer[dev->tracks[track][side].sector_data_offs[i]]); - fclose(dev->f); + fclose(dev->fp); free(dev); imd[drive] = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); @@ -865,7 +863,7 @@ imd_load(int drive, char *fn) if (size_diff < gap_sum) { /* If we can't fit the sectors with a reasonable minimum gap even at 2% slower RPM, abort. */ imd_log("IMD: Unable to fit the %i sectors in a track\n", track_spt); - fclose(dev->f); + fclose(dev->fp); free(dev); imd[drive] = NULL; memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); @@ -931,10 +929,10 @@ imd_close(int drive) d86f_unregister(drive); - if (dev->f != NULL) { + if (dev->fp != NULL) { free(dev->buffer); - fclose(dev->f); + fclose(dev->fp); } /* Release the memory. */ diff --git a/src/floppy/fdd_img.c b/src/floppy/fdd_img.c index 589f04292..404cbf9fa 100644 --- a/src/floppy/fdd_img.c +++ b/src/floppy/fdd_img.c @@ -40,8 +40,8 @@ #include <86box/fdd_img.h> #include <86box/fdc.h> -typedef struct { - FILE *f; +typedef struct img_t { + FILE *fp; uint8_t track_data[2][688128]; int sectors, tracks, sides; uint8_t sector_size; @@ -418,17 +418,17 @@ write_back(int drive) int ssize = 128 << ((int) dev->sector_size); int size; - if (dev->f == NULL) + if (dev->fp == NULL) return; if (dev->disk_at_once) return; - if (fseek(dev->f, dev->base + (dev->track * dev->sectors * ssize * dev->sides), SEEK_SET) == -1) + if (fseek(dev->fp, dev->base + (dev->track * dev->sectors * ssize * dev->sides), SEEK_SET) == -1) pclog("IMG write_back(): Error seeking to the beginning of the file\n"); for (int side = 0; side < dev->sides; side++) { size = dev->sectors * ssize; - if (fwrite(dev->track_data[side], 1, size, dev->f) != size) + if (fwrite(dev->track_data[side], 1, size, dev->fp) != size) fatal("IMG write_back(): Error writing data\n"); } } @@ -436,7 +436,7 @@ write_back(int drive) static uint16_t disk_flags(int drive) { - img_t *dev = img[drive]; + const img_t *dev = img[drive]; return (dev->disk_flags); } @@ -444,7 +444,7 @@ disk_flags(int drive) static uint16_t side_flags(int drive) { - img_t *dev = img[drive]; + const img_t *dev = img[drive]; return (dev->track_flags); } @@ -461,7 +461,7 @@ set_sector(int drive, UNUSED(int side), UNUSED(uint8_t c), uint8_t h, uint8_t r, static uint8_t poll_read_data(int drive, UNUSED(int side), uint16_t pos) { - img_t *dev = img[drive]; + const img_t *dev = img[drive]; return (dev->track_data[dev->current_sector_pos_side][dev->current_sector_pos + pos]); } @@ -477,8 +477,8 @@ poll_write_data(int drive, UNUSED(int side), uint16_t pos, uint8_t data) static int format_conditions(int drive) { - img_t *dev = img[drive]; - int temp = (fdc_get_format_sectors(img_fdc) == dev->sectors); + const img_t *dev = img[drive]; + int temp = (fdc_get_format_sectors(img_fdc) == dev->sectors); temp = temp && (fdc_get_format_n(img_fdc) == dev->sector_size); temp = temp && (dev->xdf_type == 0); @@ -507,7 +507,7 @@ img_seek(int drive, int track) int ssize = 128 << ((int) dev->sector_size); uint32_t cur_pos = 0; - if (dev->f == NULL) + if (dev->fp == NULL) return; if (!dev->track_width && fdd_doublestep_40(drive)) @@ -519,7 +519,7 @@ img_seek(int drive, int track) is_t0 = (track == 0) ? 1 : 0; if (!dev->disk_at_once) { - if (fseek(dev->f, dev->base + (track * dev->sectors * ssize * dev->sides), SEEK_SET) == -1) + if (fseek(dev->fp, dev->base + (track * dev->sectors * ssize * dev->sides), SEEK_SET) == -1) fatal("img_seek(): Error seeking\n"); } @@ -528,7 +528,7 @@ img_seek(int drive, int track) cur_pos = (track * dev->sectors * ssize * dev->sides) + (side * dev->sectors * ssize); memcpy(dev->track_data[side], dev->disk_data + cur_pos, (size_t) dev->sectors * ssize); } else { - read_bytes = fread(dev->track_data[side], 1, (size_t) dev->sectors * ssize, dev->f); + read_bytes = fread(dev->track_data[side], 1, (size_t) dev->sectors * ssize, dev->fp); if (read_bytes < (dev->sectors * ssize)) memset(dev->track_data[side] + read_bytes, 0xf6, (dev->sectors * ssize) - read_bytes); } @@ -668,8 +668,8 @@ img_load(int drive, char *fn) uint16_t track_bytes = 0; uint8_t *literal; img_t *dev; - int temp_rate; - int guess = 0; + int temp_rate = 0; + int guess = 0; int size; ext = path_get_extension(fn); @@ -682,10 +682,10 @@ img_load(int drive, char *fn) dev = (img_t *) malloc(sizeof(img_t)); memset(dev, 0x00, sizeof(img_t)); - dev->f = plat_fopen(fn, "rb+"); - if (dev->f == NULL) { - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb+"); + if (dev->fp == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -710,23 +710,23 @@ img_load(int drive, char *fn) if (!strcasecmp(ext, "FDI")) { /* This is a Japanese FDI image, so let's read the header */ img_log("img_load(): File is a Japanese FDI image...\n"); - fseek(dev->f, 0x10, SEEK_SET); - (void) !fread(&bpb_bps, 1, 2, dev->f); - fseek(dev->f, 0x0C, SEEK_SET); - (void) !fread(&size, 1, 4, dev->f); + fseek(dev->fp, 0x10, SEEK_SET); + (void) !fread(&bpb_bps, 1, 2, dev->fp); + fseek(dev->fp, 0x0C, SEEK_SET); + (void) !fread(&size, 1, 4, dev->fp); bpb_total = size / bpb_bps; - fseek(dev->f, 0x08, SEEK_SET); - (void) !fread(&(dev->base), 1, 4, dev->f); - fseek(dev->f, dev->base + 0x15, SEEK_SET); - bpb_mid = fgetc(dev->f); + fseek(dev->fp, 0x08, SEEK_SET); + (void) !fread(&(dev->base), 1, 4, dev->fp); + fseek(dev->fp, dev->base + 0x15, SEEK_SET); + bpb_mid = fgetc(dev->fp); if (bpb_mid < 0xF0) bpb_mid = 0xF0; - fseek(dev->f, 0x14, SEEK_SET); - bpb_sectors = fgetc(dev->f); - fseek(dev->f, 0x18, SEEK_SET); - bpb_sides = fgetc(dev->f); - fseek(dev->f, dev->base, SEEK_SET); - first_byte = fgetc(dev->f); + fseek(dev->fp, 0x14, SEEK_SET); + bpb_sectors = fgetc(dev->fp); + fseek(dev->fp, 0x18, SEEK_SET); + bpb_sides = fgetc(dev->fp); + fseek(dev->fp, dev->base, SEEK_SET); + first_byte = fgetc(dev->fp); fdi = 1; cqm = 0; @@ -734,53 +734,53 @@ img_load(int drive, char *fn) fdf = 0; } else { /* Read the first four bytes. */ - fseek(dev->f, 0x00, SEEK_SET); - first_byte = fgetc(dev->f); - fseek(dev->f, 0x01, SEEK_SET); - second_byte = fgetc(dev->f); - fseek(dev->f, 0x02, SEEK_SET); - third_byte = fgetc(dev->f); - fseek(dev->f, 0x03, SEEK_SET); - fourth_byte = fgetc(dev->f); + fseek(dev->fp, 0x00, SEEK_SET); + first_byte = fgetc(dev->fp); + fseek(dev->fp, 0x01, SEEK_SET); + second_byte = fgetc(dev->fp); + fseek(dev->fp, 0x02, SEEK_SET); + third_byte = fgetc(dev->fp); + fseek(dev->fp, 0x03, SEEK_SET); + fourth_byte = fgetc(dev->fp); if ((first_byte == 0x1A) && (second_byte == 'F') && (third_byte == 'D') && (fourth_byte == 'F')) { /* This is a FDF image. */ img_log("img_load(): File is a FDF image...\n"); fwriteprot[drive] = writeprot[drive] = 1; - fclose(dev->f); - dev->f = plat_fopen(fn, "rb"); + fclose(dev->fp); + dev->fp = plat_fopen(fn, "rb"); fdf = 1; cqm = 0; dev->disk_at_once = 1; - fseek(dev->f, 0x50, SEEK_SET); - (void) !fread(&dev->tracks, 1, 4, dev->f); + fseek(dev->fp, 0x50, SEEK_SET); + (void) !fread(&dev->tracks, 1, 4, dev->fp); /* Decode the entire file - pass 1, no write to buffer, determine length. */ - fseek(dev->f, 0x80, SEEK_SET); + fseek(dev->fp, 0x80, SEEK_SET); size = 0; track_bytes = 0; bpos = dev->disk_data; - while (!feof(dev->f)) { + while (!feof(dev->fp)) { if (!track_bytes) { /* Skip first 3 bytes - their meaning is unknown to us but could be a checksum. */ - first_byte = fgetc(dev->f); - (void) !fread(&track_bytes, 1, 2, dev->f); + first_byte = fgetc(dev->fp); + (void) !fread(&track_bytes, 1, 2, dev->fp); img_log("Block header: %02X %04X ", first_byte, track_bytes); /* Read the length of encoded data block. */ - (void) !fread(&track_bytes, 1, 2, dev->f); + (void) !fread(&track_bytes, 1, 2, dev->fp); img_log("%04X\n", track_bytes); } - if (feof(dev->f)) + if (feof(dev->fp)) break; if (first_byte == 0xFF) break; if (first_byte) { - run = fgetc(dev->f); + run = fgetc(dev->fp); /* I *HAVE* to read something because fseek tries to be smart and never hits EOF, causing an infinite loop. */ track_bytes--; @@ -788,12 +788,12 @@ img_load(int drive, char *fn) if (run & 0x80) { /* Repeat. */ track_bytes--; - rep_byte = fgetc(dev->f); + rep_byte = fgetc(dev->fp); } else { /* Literal. */ track_bytes -= (run & 0x7f); literal = (uint8_t *) malloc(run & 0x7f); - (void) !fread(literal, 1, (run & 0x7f), dev->f); + (void) !fread(literal, 1, (run & 0x7f), dev->fp); free(literal); } size += (run & 0x7f); @@ -803,12 +803,12 @@ img_load(int drive, char *fn) /* Literal block. */ size += (track_bytes - fdf_suppress_final_byte); literal = (uint8_t *) malloc(track_bytes); - (void) !fread(literal, 1, track_bytes, dev->f); + (void) !fread(literal, 1, track_bytes, dev->fp); free(literal); track_bytes = 0; } - if (feof(dev->f)) + if (feof(dev->fp)) break; } @@ -816,28 +816,28 @@ img_load(int drive, char *fn) dev->disk_data = (uint8_t *) malloc(size); /* Decode the entire file - pass 2, write to buffer. */ - fseek(dev->f, 0x80, SEEK_SET); + fseek(dev->fp, 0x80, SEEK_SET); track_bytes = 0; bpos = dev->disk_data; - while (!feof(dev->f)) { + while (!feof(dev->fp)) { if (!track_bytes) { /* Skip first 3 bytes - their meaning is unknown to us but could be a checksum. */ - first_byte = fgetc(dev->f); - (void) !fread(&track_bytes, 1, 2, dev->f); + first_byte = fgetc(dev->fp); + (void) !fread(&track_bytes, 1, 2, dev->fp); img_log("Block header: %02X %04X ", first_byte, track_bytes); /* Read the length of encoded data block. */ - (void) !fread(&track_bytes, 1, 2, dev->f); + (void) !fread(&track_bytes, 1, 2, dev->fp); img_log("%04X\n", track_bytes); } - if (feof(dev->f)) + if (feof(dev->fp)) break; if (first_byte == 0xFF) break; if (first_byte) { - run = fgetc(dev->f); + run = fgetc(dev->fp); real_run = (run & 0x7f); /* I *HAVE* to read something because fseek tries to be smart and never hits EOF, causing an infinite loop. */ @@ -848,14 +848,14 @@ img_load(int drive, char *fn) track_bytes--; if (!track_bytes) real_run -= fdf_suppress_final_byte; - rep_byte = fgetc(dev->f); + rep_byte = fgetc(dev->fp); if (real_run) memset(bpos, rep_byte, real_run); } else { /* Literal. */ track_bytes -= real_run; literal = (uint8_t *) malloc(real_run); - (void) !fread(literal, 1, real_run, dev->f); + (void) !fread(literal, 1, real_run, dev->fp); if (!track_bytes) real_run -= fdf_suppress_final_byte; if (run & 0x7f) @@ -866,14 +866,14 @@ img_load(int drive, char *fn) } else { /* Literal block. */ literal = (uint8_t *) malloc(track_bytes); - (void) !fread(literal, 1, track_bytes, dev->f); + (void) !fread(literal, 1, track_bytes, dev->fp); memcpy(bpos, literal, track_bytes - fdf_suppress_final_byte); free(literal); bpos += (track_bytes - fdf_suppress_final_byte); track_bytes = 0; } - if (feof(dev->f)) + if (feof(dev->fp)) break; } @@ -892,48 +892,48 @@ img_load(int drive, char *fn) if (((first_byte == 'C') && (second_byte == 'Q')) || ((first_byte == 'c') && (second_byte == 'q'))) { img_log("img_load(): File is a CopyQM image...\n"); fwriteprot[drive] = writeprot[drive] = 1; - fclose(dev->f); - dev->f = plat_fopen(fn, "rb"); + fclose(dev->fp); + dev->fp = plat_fopen(fn, "rb"); - fseek(dev->f, 0x03, SEEK_SET); - (void) !fread(&bpb_bps, 1, 2, dev->f); + fseek(dev->fp, 0x03, SEEK_SET); + (void) !fread(&bpb_bps, 1, 2, dev->fp); #if 0 - fseek(dev->f, 0x0B, SEEK_SET); - (void) !fread(&bpb_total, 1, 2, dev->f); + fseek(dev->fp, 0x0B, SEEK_SET); + (void) !fread(&bpb_total, 1, 2, dev->fp); #endif - fseek(dev->f, 0x10, SEEK_SET); - bpb_sectors = fgetc(dev->f); - fseek(dev->f, 0x12, SEEK_SET); - bpb_sides = fgetc(dev->f); - fseek(dev->f, 0x5B, SEEK_SET); - dev->tracks = fgetc(dev->f); + fseek(dev->fp, 0x10, SEEK_SET); + bpb_sectors = fgetc(dev->fp); + fseek(dev->fp, 0x12, SEEK_SET); + bpb_sides = fgetc(dev->fp); + fseek(dev->fp, 0x5B, SEEK_SET); + dev->tracks = fgetc(dev->fp); bpb_total = ((uint16_t) bpb_sectors) * ((uint16_t) bpb_sides) * dev->tracks; - fseek(dev->f, 0x74, SEEK_SET); - dev->interleave = fgetc(dev->f); - fseek(dev->f, 0x76, SEEK_SET); - dev->skew = fgetc(dev->f); + fseek(dev->fp, 0x74, SEEK_SET); + dev->interleave = fgetc(dev->fp); + fseek(dev->fp, 0x76, SEEK_SET); + dev->skew = fgetc(dev->fp); dev->disk_data = (uint8_t *) malloc(((uint32_t) bpb_total) * ((uint32_t) bpb_bps)); memset(dev->disk_data, 0xf6, ((uint32_t) bpb_total) * ((uint32_t) bpb_bps)); - fseek(dev->f, 0x6F, SEEK_SET); - (void) !fread(&comment_len, 1, 2, dev->f); + fseek(dev->fp, 0x6F, SEEK_SET); + (void) !fread(&comment_len, 1, 2, dev->fp); - fseek(dev->f, -1, SEEK_END); - size = ftell(dev->f) + 1; + fseek(dev->fp, -1, SEEK_END); + size = ftell(dev->fp) + 1; - fseek(dev->f, 133 + comment_len, SEEK_SET); + fseek(dev->fp, 133 + comment_len, SEEK_SET); cur_pos = 0; - while (!feof(dev->f)) { - (void) !fread(&block_len, 1, 2, dev->f); + while (!feof(dev->fp)) { + (void) !fread(&block_len, 1, 2, dev->fp); - if (!feof(dev->f)) { + if (!feof(dev->fp)) { if (block_len < 0) { - rep_byte = fgetc(dev->f); + rep_byte = fgetc(dev->fp); block_len = -block_len; if ((cur_pos + block_len) > ((uint32_t) bpb_total) * ((uint32_t) bpb_bps)) { block_len = ((uint32_t) bpb_total) * ((uint32_t) bpb_bps) - cur_pos; @@ -946,10 +946,10 @@ img_load(int drive, char *fn) } else if (block_len > 0) { if ((cur_pos + block_len) > ((uint32_t) bpb_total) * ((uint32_t) bpb_bps)) { block_len = ((uint32_t) bpb_total) * ((uint32_t) bpb_bps) - cur_pos; - (void) !fread(dev->disk_data + cur_pos, 1, block_len, dev->f); + (void) !fread(dev->disk_data + cur_pos, 1, block_len, dev->fp); break; } else { - (void) !fread(dev->disk_data + cur_pos, 1, block_len, dev->f); + (void) !fread(dev->disk_data + cur_pos, 1, block_len, dev->fp); cur_pos += block_len; } } @@ -969,22 +969,22 @@ img_load(int drive, char *fn) fwriteprot[drive] = writeprot[drive] = 1; } else img_log("img_load(): File is a raw image...\n"); - fseek(dev->f, dev->base + 0x0B, SEEK_SET); - (void) !fread(&bpb_bps, 1, 2, dev->f); - fseek(dev->f, dev->base + 0x13, SEEK_SET); - (void) !fread(&bpb_total, 1, 2, dev->f); - fseek(dev->f, dev->base + 0x15, SEEK_SET); - bpb_mid = fgetc(dev->f); - fseek(dev->f, dev->base + 0x18, SEEK_SET); - bpb_sectors = fgetc(dev->f); - fseek(dev->f, dev->base + 0x1A, SEEK_SET); - bpb_sides = fgetc(dev->f); + fseek(dev->fp, dev->base + 0x0B, SEEK_SET); + (void) !fread(&bpb_bps, 1, 2, dev->fp); + fseek(dev->fp, dev->base + 0x13, SEEK_SET); + (void) !fread(&bpb_total, 1, 2, dev->fp); + fseek(dev->fp, dev->base + 0x15, SEEK_SET); + bpb_mid = fgetc(dev->fp); + fseek(dev->fp, dev->base + 0x18, SEEK_SET); + bpb_sectors = fgetc(dev->fp); + fseek(dev->fp, dev->base + 0x1A, SEEK_SET); + bpb_sides = fgetc(dev->fp); cqm = 0; } - fseek(dev->f, -1, SEEK_END); - size = ftell(dev->f) + 1; + fseek(dev->fp, -1, SEEK_END); + size = ftell(dev->fp) + 1; if (ddi) size -= 0x2400; @@ -1125,7 +1125,7 @@ jump_if_fdf: dev->tracks = 86; } else { img_log("Image is bigger than can fit on an ED floppy, ejecting...\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -1138,9 +1138,9 @@ jump_if_fdf: /* The BPB readings appear to be valid, so let's set the values. */ if (fdi) { /* The image is a Japanese FDI, therefore we read the number of tracks from the header. */ - if (fseek(dev->f, 0x1C, SEEK_SET) == -1) + if (fseek(dev->fp, 0x1C, SEEK_SET) == -1) fatal("Japanese FDI: Failed when seeking to 0x1C\n"); - (void) !fread(&(dev->tracks), 1, 4, dev->f); + (void) !fread(&(dev->tracks), 1, 4, dev->fp); } else { if (!cqm && !fdf) { /* Number of tracks = number of total sectors divided by sides times sectors per track. */ @@ -1182,7 +1182,7 @@ jump_if_fdf: if (temp_rate == 0xFF) { img_log("Image is bigger than can fit on an ED floppy, ejecting...\n"); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -1199,7 +1199,7 @@ jump_if_fdf: } if (!dev->gap3_size) { img_log("ERROR: Floppy image of unknown format was inserted into drive %c:!\n", drive + 0x41); - fclose(dev->f); + fclose(dev->fp); free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -1259,9 +1259,9 @@ img_close(int drive) d86f_unregister(drive); - if (dev->f != NULL) { - fclose(dev->f); - dev->f = NULL; + if (dev->fp != NULL) { + fclose(dev->fp); + dev->fp = NULL; } if (dev->disk_data != NULL) diff --git a/src/floppy/fdd_json.c b/src/floppy/fdd_json.c index 1b70d8fc8..36a041a68 100644 --- a/src/floppy/fdd_json.c +++ b/src/floppy/fdd_json.c @@ -62,7 +62,7 @@ #define NSIDES 2 #define NSECTORS 256 -typedef struct { +typedef struct sector_t { uint8_t track; /* ID: track number */ uint8_t side; /* side number */ uint8_t sector; /* sector number 1.. */ @@ -70,8 +70,8 @@ typedef struct { uint8_t *data; /* allocated data for it */ } sector_t; -typedef struct { - FILE *f; +typedef struct json_t { + FILE *fp; /* Geometry. */ uint8_t tracks; /* number of tracks */ @@ -215,7 +215,7 @@ load_image(json_t *dev) int level; char *ptr; - if (dev->f == NULL) { + if (dev->fp == NULL) { json_log("JSON: no file loaded!\n"); return 0; } @@ -232,8 +232,8 @@ load_image(json_t *dev) level = state = 0; while (state >= 0) { /* Get a character from the input. */ - c = fgetc(dev->f); - if ((c == EOF) || ferror(dev->f)) { + c = fgetc(dev->fp); + if ((c == EOF) || ferror(dev->fp)) { state = -1; break; } @@ -372,6 +372,9 @@ load_image(json_t *dev) } dev->track++; break; + + default: + break; } } @@ -396,7 +399,7 @@ json_seek(int drive, int track) int rsec; int asec; - if (dev->f == NULL) { + if (dev->fp == NULL) { json_log("JSON: seek: no file loaded!\n"); return; } @@ -464,7 +467,7 @@ json_seek(int drive, int track) static uint16_t disk_flags(int drive) { - json_t *dev = images[drive]; + const json_t *dev = images[drive]; return (dev->disk_flags); } @@ -472,7 +475,7 @@ disk_flags(int drive) static uint16_t track_flags(int drive) { - json_t *dev = images[drive]; + const json_t *dev = images[drive]; return (dev->track_flags); } @@ -502,8 +505,8 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) static uint8_t poll_read_data(int drive, int side, uint16_t pos) { - json_t *dev = images[drive]; - uint8_t sec = dev->sector[side]; + const json_t *dev = images[drive]; + uint8_t sec = dev->sector[side]; return (dev->sects[dev->track][side][sec].data[pos]); } @@ -517,10 +520,10 @@ json_init(void) void json_load(int drive, char *fn) { - double bit_rate; - int temp_rate; - sector_t *sec; - json_t *dev; + double bit_rate; + int temp_rate; + const sector_t *sec; + json_t *dev; /* Just in case- remove ourselves from 86F. */ d86f_unregister(drive); @@ -530,8 +533,8 @@ json_load(int drive, char *fn) memset(dev, 0x00, sizeof(json_t)); /* Open the image file. */ - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { free(dev); memset(fn, 0x00, sizeof(char)); return; @@ -546,7 +549,7 @@ json_load(int drive, char *fn) /* Load all sectors from the image file. */ if (!load_image(dev)) { json_log("JSON: failed to initialize\n"); - (void) fclose(dev->f); + (void) fclose(dev->fp); free(dev); images[drive] = NULL; memset(fn, 0x00, sizeof(char)); @@ -608,8 +611,8 @@ json_load(int drive, char *fn) if (temp_rate == 0xff) { json_log("JSON: invalid image (temp_rate=0xff)\n"); - (void) fclose(dev->f); - dev->f = NULL; + (void) fclose(dev->fp); + dev->fp = NULL; free(dev); images[drive] = NULL; memset(fn, 0x00, sizeof(char)); @@ -630,8 +633,8 @@ json_load(int drive, char *fn) if (!dev->gap3_len) { json_log("JSON: image of unknown format was inserted into drive %c:!\n", 'C' + drive); - (void) fclose(dev->f); - dev->f = NULL; + (void) fclose(dev->fp); + dev->fp = NULL; free(dev); images[drive] = NULL; memset(fn, 0x00, sizeof(char)); @@ -692,8 +695,8 @@ json_close(int drive) } } - if (dev->f != NULL) - (void) fclose(dev->f); + if (dev->fp != NULL) + (void) fclose(dev->fp); /* Release the memory. */ free(dev); diff --git a/src/floppy/fdd_mfm.c b/src/floppy/fdd_mfm.c index 5719c3672..b4c859d5d 100644 --- a/src/floppy/fdd_mfm.c +++ b/src/floppy/fdd_mfm.c @@ -32,7 +32,7 @@ #include <86box/fdc.h> #pragma pack(push, 1) -typedef struct { +typedef struct mfm_header_t { uint8_t hdr_name[7]; uint16_t tracks_no; @@ -45,14 +45,14 @@ typedef struct { uint32_t track_list_offset; } mfm_header_t; -typedef struct { +typedef struct mfm_track_t { uint16_t track_no; uint8_t side_no; uint32_t track_size; uint32_t track_offset; } mfm_track_t; -typedef struct { +typedef struct mfm_adv_track_t { uint16_t track_no; uint8_t side_no; uint16_t rpm; @@ -62,8 +62,8 @@ typedef struct { } mfm_adv_track_t; #pragma pack(pop) -typedef struct { - FILE *f; +typedef struct mfm_t { + FILE *fp; mfm_header_t hdr; mfm_track_t *tracks; @@ -105,8 +105,8 @@ mfm_log(const char *fmt, ...) static int get_track_index(int drive, int side, int track) { - mfm_t *dev = mfm[drive]; - int ret = -1; + const mfm_t *dev = mfm[drive]; + int ret = -1; for (int i = 0; i < dev->total_tracks; i++) { if ((dev->tracks[i].track_no == track) && (dev->tracks[i].side_no == side)) { @@ -121,8 +121,8 @@ get_track_index(int drive, int side, int track) static int get_adv_track_index(int drive, int side, int track) { - mfm_t *dev = mfm[drive]; - int ret = -1; + const mfm_t *dev = mfm[drive]; + int ret = -1; for (int i = 0; i < dev->total_tracks; i++) { if ((dev->adv_tracks[i].track_no == track) && (dev->adv_tracks[i].side_no == side)) { @@ -137,9 +137,9 @@ get_adv_track_index(int drive, int side, int track) static void get_adv_track_bitrate(int drive, int side, int track, int *br, int *rpm) { - mfm_t *dev = mfm[drive]; - int track_index; - double dbr; + const mfm_t *dev = mfm[drive]; + int track_index; + double dbr; track_index = get_adv_track_index(drive, side, track); @@ -197,7 +197,7 @@ set_disk_flags(int drive) static uint16_t disk_flags(int drive) { - mfm_t *dev = mfm[drive]; + const mfm_t *dev = mfm[drive]; return dev->disk_flags; } @@ -257,8 +257,8 @@ set_side_flags(int drive, int side) static uint16_t side_flags(int drive) { - mfm_t *dev = mfm[drive]; - int side; + const mfm_t *dev = mfm[drive]; + int side; side = fdd_get_head(drive); @@ -268,11 +268,11 @@ side_flags(int drive) static uint32_t get_raw_size(int drive, int side) { - mfm_t *dev = mfm[drive]; - int track_index; - int is_300_rpm; - int br = 250; - int rpm = 300; + const mfm_t *dev = mfm[drive]; + int track_index; + int is_300_rpm; + int br = 250; + int rpm = 300; if (dev->hdr.if_type & 0x80) { track_index = get_adv_track_index(drive, side, dev->cur_track); @@ -345,12 +345,12 @@ mfm_read_side(int drive, int side) memset(dev->track_data[side], 0x00, track_bytes); else { if (dev->hdr.if_type & 0x80) - ret = fseek(dev->f, dev->adv_tracks[track_index].track_offset, SEEK_SET); + ret = fseek(dev->fp, dev->adv_tracks[track_index].track_offset, SEEK_SET); else - ret = fseek(dev->f, dev->tracks[track_index].track_offset, SEEK_SET); + ret = fseek(dev->fp, dev->tracks[track_index].track_offset, SEEK_SET); if (ret == -1) fatal("mfm_read_side(): Error seeking to the beginning of the file\n"); - if (fread(dev->track_data[side], 1, track_bytes, dev->f) != track_bytes) + if (fread(dev->track_data[side], 1, track_bytes, dev->fp) != track_bytes) fatal("mfm_read_side(): Error reading track bytes\n"); } @@ -373,7 +373,7 @@ mfm_seek(int drive, int track) dev->cur_track = track; d86f_set_cur_track(drive, track); - if (dev->f == NULL) + if (dev->fp == NULL) return; if (track < 0) @@ -399,8 +399,8 @@ mfm_load(int drive, char *fn) dev = (mfm_t *) malloc(sizeof(mfm_t)); memset(dev, 0x00, sizeof(mfm_t)); - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { free(dev); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; @@ -410,7 +410,7 @@ mfm_load(int drive, char *fn) /* Read the header. */ size = sizeof(mfm_header_t); - if (fread(&dev->hdr, 1, size, dev->f) != size) + if (fread(&dev->hdr, 1, size, dev->fp) != size) fatal("mfm_load(): Error reading header\n"); /* Calculate tracks * sides, allocate the tracks array, and read it. */ @@ -418,12 +418,12 @@ mfm_load(int drive, char *fn) if (dev->hdr.if_type & 0x80) { dev->adv_tracks = (mfm_adv_track_t *) malloc(dev->total_tracks * sizeof(mfm_adv_track_t)); size = dev->total_tracks * sizeof(mfm_adv_track_t); - if (fread(dev->adv_tracks, 1, size, dev->f) != size) + if (fread(dev->adv_tracks, 1, size, dev->fp) != size) fatal("mfm_load(): Error reading advanced tracks\n"); } else { dev->tracks = (mfm_track_t *) malloc(dev->total_tracks * sizeof(mfm_track_t)); size = dev->total_tracks * sizeof(mfm_track_t); - if (fread(dev->tracks, 1, size, dev->f) != size) + if (fread(dev->tracks, 1, size, dev->fp) != size) fatal("mfm_load(): Error reading tracks\n"); } @@ -504,8 +504,8 @@ mfm_close(int drive) if (dev->adv_tracks) free(dev->adv_tracks); - if (dev->f) - fclose(dev->f); + if (dev->fp) + fclose(dev->fp); /* Release the memory. */ free(dev); diff --git a/src/floppy/fdd_td0.c b/src/floppy/fdd_td0.c index 87856b904..46e29343b 100644 --- a/src/floppy/fdd_td0.c +++ b/src/floppy/fdd_td0.c @@ -60,7 +60,7 @@ /* update when cumulative frequency */ /* reaches to this value */ -typedef struct { +typedef struct tdlzhuf_t { uint16_t r; uint16_t bufcnt; /* string buffer */ uint16_t bufndx; /* string buffer */ @@ -72,7 +72,7 @@ typedef struct { uint8_t inbuf[BUFSZ]; /* input buffer */ } tdlzhuf; -typedef struct { +typedef struct td0dsk_t { FILE *fdd_file; off_t fdd_file_offset; @@ -93,7 +93,7 @@ typedef struct { uint8_t getlen; } td0dsk_t; -typedef struct { +typedef struct td0_sector_t { uint8_t track; uint8_t head; uint8_t sector; @@ -103,8 +103,8 @@ typedef struct { uint8_t *data; } td0_sector_t; -typedef struct { - FILE *f; +typedef struct td0_t { + FILE *fp; int tracks; int track_width; @@ -227,9 +227,9 @@ fdd_image_read(int drive, char *buffer, uint32_t offset, uint32_t len) { td0_t *dev = td0[drive]; - if (fseek(dev->f, offset, SEEK_SET) == -1) + if (fseek(dev->fp, offset, SEEK_SET) == -1) fatal("fdd_image_read(): Error seeking to the beginning of the file\n"); - if (fread(buffer, 1, len, dev->f) != len) + if (fread(buffer, 1, len, dev->fp) != len) fatal("fdd_image_read(): Error reading data\n"); } @@ -595,45 +595,45 @@ get_raw_tsize(int side_flags, int slower_rpm) static int td0_initialize(int drive) { - td0_t *dev = td0[drive]; - uint8_t header[12]; - int fm; - int head; - int track; - int track_count = 0; - int head_count = 0; - int track_spt; - int track_spt_adjusted; - int offset = 0; - int density = 0; - int temp_rate = 0; - uint32_t file_size; - uint16_t len; - uint16_t rep; - td0dsk_t disk_decode; - uint8_t *hs; - uint16_t size; - uint8_t *dbuf = dev->processed_buf; - uint32_t total_size = 0; - uint32_t id_field = 0; - uint32_t pre_sector = 0; - int32_t track_size = 0; - int32_t raw_tsize = 0; - uint32_t minimum_gap3 = 0; - uint32_t minimum_gap4 = 0; - int i; - int j; - int k; - int size_diff; - int gap_sum; + td0_t *dev = td0[drive]; + uint8_t header[12]; + int fm; + int head; + int track; + int track_count = 0; + int head_count = 0; + int track_spt; + int track_spt_adjusted; + int offset = 0; + int density = 0; + int temp_rate = 0; + uint32_t file_size; + uint16_t len; + uint16_t rep; + td0dsk_t disk_decode; + const uint8_t *hs; + uint16_t size; + uint8_t *dbuf = dev->processed_buf; + uint32_t total_size = 0; + uint32_t id_field = 0; + uint32_t pre_sector = 0; + int32_t track_size = 0; + int32_t raw_tsize = 0; + uint32_t minimum_gap3 = 0; + uint32_t minimum_gap4 = 0; + int i; + int j; + int k; + int size_diff; + int gap_sum; - if (dev->f == NULL) { + if (dev->fp == NULL) { td0_log("TD0: Attempted to initialize without loading a file first\n"); return 0; } - fseek(dev->f, 0, SEEK_END); - file_size = ftell(dev->f); + fseek(dev->fp, 0, SEEK_END); + file_size = ftell(dev->fp); if (file_size < 12) { td0_log("TD0: File is too small to even contain the header\n"); @@ -645,21 +645,21 @@ td0_initialize(int drive) return 0; } - fseek(dev->f, 0, SEEK_SET); - (void) !fread(header, 1, 12, dev->f); + fseek(dev->fp, 0, SEEK_SET); + (void) !fread(header, 1, 12, dev->fp); head_count = header[9]; if (header[0] == 't') { td0_log("TD0: File is compressed\n"); - disk_decode.fdd_file = dev->f; + disk_decode.fdd_file = dev->fp; state_init_Decode(&disk_decode); disk_decode.fdd_file_offset = 12; state_Decode(&disk_decode, dev->imagebuf, TD0_MAX_BUFSZ); } else { td0_log("TD0: File is uncompressed\n"); - if (fseek(dev->f, 12, SEEK_SET) == -1) + if (fseek(dev->fp, 12, SEEK_SET) == -1) fatal("td0_initialize(): Error seeking to offet 12\n"); - if (fread(dev->imagebuf, 1, file_size - 12, dev->f) != (file_size - 12)) + if (fread(dev->imagebuf, 1, file_size - 12, dev->fp) != (file_size - 12)) fatal("td0_initialize(): Error reading image buffer\n"); } @@ -710,6 +710,9 @@ td0_initialize(int drive) dev->default_track_flags = (density == 1) ? 0x00 : ((density == 2) ? 0x03 : 0x02); dev->max_sector_size = (density == 1) ? 6 : ((density == 2) ? 7 : 5); /* 16384, 8192, or 4096 bytes. */ break; + + default: + break; } dev->disk_flags = header[5] & 0x06; @@ -886,7 +889,7 @@ td0_initialize(int drive) static uint16_t disk_flags(int drive) { - td0_t *dev = td0[drive]; + const td0_t *dev = td0[drive]; return (dev->disk_flags); } @@ -894,9 +897,9 @@ disk_flags(int drive) static uint16_t side_flags(int drive) { - td0_t *dev = td0[drive]; - int side = 0; - uint16_t sflags = 0; + const td0_t *dev = td0[drive]; + int side = 0; + uint16_t sflags = 0; side = fdd_get_head(drive); sflags = dev->current_side_flags[side]; @@ -923,7 +926,7 @@ set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) static uint8_t poll_read_data(int drive, int side, uint16_t pos) { - td0_t *dev = td0[drive]; + const td0_t *dev = td0[drive]; return (dev->sects[dev->track][side][dev->current_sector_index[side]].data[pos]); } @@ -1064,7 +1067,7 @@ td0_seek(int drive, int track) int fm; int sector_adjusted; - if (dev->f == NULL) + if (dev->fp == NULL) return; if (!dev->track_width && fdd_doublestep_40(drive)) @@ -1182,8 +1185,8 @@ td0_abort(int drive) free(dev->imagebuf); if (dev->processed_buf) free(dev->processed_buf); - if (dev->f) - fclose(dev->f); + if (dev->fp) + fclose(dev->fp); memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); free(dev); td0[drive] = NULL; @@ -1203,8 +1206,8 @@ td0_load(int drive, char *fn) memset(dev, 0x00, sizeof(td0_t)); td0[drive] = dev; - dev->f = plat_fopen(fn, "rb"); - if (dev->f == NULL) { + dev->fp = plat_fopen(fn, "rb"); + if (dev->fp == NULL) { memset(floppyfns[drive], 0, sizeof(floppyfns[drive])); return; } @@ -1285,8 +1288,8 @@ td0_close(int drive) memset(dev->sects[i][j], 0, sizeof(td0_sector_t)); } - if (dev->f != NULL) - fclose(dev->f); + if (dev->fp != NULL) + fclose(dev->fp); /* Release resources. */ free(dev); diff --git a/src/floppy/fdi2raw.c b/src/floppy/fdi2raw.c index 7210c89b2..75c65cf25 100644 --- a/src/floppy/fdi2raw.c +++ b/src/floppy/fdi2raw.c @@ -36,7 +36,9 @@ #include #include <86box/plat_unused.h> +#ifdef DEBUG #undef DEBUG +#endif #define VERBOSE #undef VERBOSE @@ -96,24 +98,24 @@ static int fdi_allocated; #ifdef DEBUG static void -fdi_free(void *p) +fdi_free(void *priv) { int size; - if (!p) + if (!priv) return; - size = ((int *) p)[-1]; + size = ((int *) priv)[-1]; fdi_allocated -= size; write_log("%d freed (%d)\n", size, fdi_allocated); - free((int *) p - 1); + free((int *) priv - 1); } static void * fdi_malloc(int size) { - void *p = xmalloc(size + sizeof(int)); - ((int *) p)[0] = size; + void *priv = xmalloc(size + sizeof(int)); + ((int *) prv)[0] = size; fdi_allocated += size; write_log("%d allocated (%d)\n", size, fdi_allocated); - return (int *) p + 1; + return (int *) priv + 1; } #else # define fdi_free free @@ -1290,6 +1292,9 @@ track_atari_st(struct fdi *fdi, int max_sector) case 10: gap3 = 24; break; + + default: + break; } s15(fdi); for (int i = 0; i < max_sector; i++) { @@ -1915,9 +1920,9 @@ fdi2_decode(FDI *fdi, uint32_t totalavg, uint32_t *avgp, uint32_t *minp, uint32_ static void fdi2_celltiming(FDI *fdi, uint32_t totalavg, int bitoffset, uint16_t *out) { - uint16_t *pt2; - uint16_t *pt; - double avg_bit_len; + const uint16_t *pt2; + uint16_t *pt; + double avg_bit_len; avg_bit_len = (double) totalavg / (double) bitoffset; pt2 = fdi->track_dst_buffer_timing; @@ -1935,27 +1940,27 @@ fdi2_celltiming(FDI *fdi, uint32_t totalavg, int bitoffset, uint16_t *out) static int decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) { - uint8_t *p1; - uint32_t *p2; - uint32_t *avgp; - uint32_t *minp = 0; - uint32_t *maxp = 0; - uint8_t *idxp = 0; - uint32_t maxidx; - uint32_t totalavg; - uint32_t weakbits; - int i; - int j; - int len; - int pulses; - int indexoffset; - int avg_free; - int min_free = 0; - int max_free = 0; - int idx_free; - int idx_off1 = 0; - int idx_off2 = 0; - int idx_off3 = 0; + uint8_t *p1; + const uint32_t *p2; + uint32_t *avgp; + uint32_t *minp = 0; + uint32_t *maxp = 0; + uint8_t *idxp = 0; + uint32_t maxidx; + uint32_t totalavg; + uint32_t weakbits; + int j; + int k; + int len; + int pulses; + int indexoffset; + int avg_free; + int min_free = 0; + int max_free = 0; + int idx_free; + int idx_off1 = 0; + int idx_off2 = 0; + int idx_off3 = 0; p1 = fdi->track_src; pulses = get_u32(p1); @@ -1974,7 +1979,7 @@ decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) maxp = (uint32_t *) fdi_decompress(pulses, p1 + 6, p1 + len, &max_free); len += get_u24(p1 + 6) & 0x3fffff; /* Computes the real min and max values */ - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { maxp[i] = avgp[i] + minp[i] - maxp[i]; minp[i] = avgp[i] - minp[i]; } @@ -2000,7 +2005,7 @@ decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) } else { idxp = fdi_malloc(pulses * 2); idx_free = 1; - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { idxp[i * 2 + 0] = 2; idxp[i * 2 + 1] = 0; } @@ -2011,43 +2016,43 @@ decode_lowlevel_track(FDI *fdi, int track, struct fdi_cache *cache) maxidx = 0; indexoffset = 0; p1 = idxp; - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { if ((uint32_t) p1[idx_off1] + (uint32_t) p1[idx_off2] > maxidx) maxidx = p1[idx_off1] + p1[idx_off2]; p1 += idx_off3; } p1 = idxp; - for (i = 0; (i < pulses) && (p1[idx_off2] != 0); i++) /* falling edge, replace with idx_off1 for rising edge */ + for (k = 0; (k < pulses) && (p1[idx_off2] != 0); k++) /* falling edge, replace with idx_off1 for rising edge */ p1 += idx_off3; - if (i < pulses) { - j = i; + if (k < pulses) { + j = k; do { - i++; + k++; p1 += idx_off3; - if (i >= pulses) { - i = 0; + if (k >= pulses) { + k = 0; p1 = idxp; } - } while ((i != j) && (p1[idx_off2] == 0)); /* falling edge, replace with idx_off1 for rising edge */ - if (i != j) /* index pulse detected */ + } while ((k != j) && (p1[idx_off2] == 0)); /* falling edge, replace with idx_off1 for rising edge */ + if (k != j) /* index pulse detected */ { - while ((i != j) && (p1[idx_off1] > p1[idx_off2])) { /* falling edge, replace with "<" for rising edge */ - i++; + while ((k != j) && (p1[idx_off1] > p1[idx_off2])) { /* falling edge, replace with "<" for rising edge */ + k++; p1 += idx_off3; - if (i >= pulses) { - i = 0; + if (k >= pulses) { + k = 0; p1 = idxp; } } - if (i != j) - indexoffset = i; /* index position detected */ + if (k != j) + indexoffset = k; /* index position detected */ } } p1 = idxp; p2 = avgp; totalavg = 0; weakbits = 0; - for (i = 0; i < pulses; i++) { + for (int i = 0; i < pulses; i++) { uint32_t sum = p1[idx_off1] + p1[idx_off2]; if (sum >= maxidx) { totalavg += *p2; @@ -2254,7 +2259,7 @@ fdi2raw_loadrevolution_2(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int *tracklength = len; for (int i = 0; i < (len + 15) / (2 * 8); i++) { - uint8_t *data = fdi->track_dst_buffer + i * 2; + const uint8_t *data = fdi->track_dst_buffer + i * 2; *mfmbuf++ = 256 * *data + *(data + 1); } fdi2_celltiming(fdi, cache->totalavg, len, tracktiming); @@ -2273,7 +2278,7 @@ fdi2raw_loadrevolution(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int tr int fdi2raw_loadtrack(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int track, int *tracklength, int *indexoffsetp, int *multirev, int mfm) { - uint8_t *p; + const uint8_t *p; int outlen; struct fdi_cache *cache = &fdi->cache[track]; @@ -2347,8 +2352,8 @@ fdi2raw_loadtrack(FDI *fdi, uint16_t *mfmbuf, uint16_t *tracktiming, int track, return fdi2raw_loadrevolution_2(fdi, mfmbuf, tracktiming, track, tracklength, indexoffsetp, multirev, mfm); *tracklength = fdi->out; for (int i = 0; i < ((*tracklength) + 15) / (2 * 8); i++) { - uint8_t *data = fdi->track_dst_buffer + i * 2; - *mfmbuf++ = 256 * *data + *(data + 1); + const uint8_t *data = fdi->track_dst_buffer + i * 2; + *mfmbuf++ = 256 * *data + *(data + 1); } } return outlen; diff --git a/src/gdbstub.c b/src/gdbstub.c index 867ebe1d1..4fafb545e 100644 --- a/src/gdbstub.c +++ b/src/gdbstub.c @@ -120,13 +120,20 @@ typedef struct _gdbstub_client_ { int socket; struct sockaddr_in addr; - char packet[16384], response[16384]; - int has_packet : 1, first_packet_received : 1, ida_mode : 1, waiting_stop : 1, - packet_pos, response_pos; + char packet[16384], response[16384]; + uint8_t has_packet : 1; + uint8_t first_packet_received : 1; + uint8_t ida_mode : 1; + uint8_t waiting_stop : 1; + int packet_pos; + int response_pos; - event_t *processed_event, *response_event; + event_t *processed_event; + event_t *response_event; - uint16_t last_io_base, last_io_len, last_io_value; + uint16_t last_io_base; + uint16_t last_io_len; + uint16_t last_io_value; struct _gdbstub_client_ *next; } gdbstub_client_t; @@ -339,7 +346,8 @@ static gdbstub_breakpoint_t *first_rwatch = NULL; static gdbstub_breakpoint_t *first_wwatch = NULL; static gdbstub_breakpoint_t *first_awatch = NULL; -int gdbstub_step = 0, gdbstub_next_asap = 0; +int gdbstub_step = 0; +int gdbstub_next_asap = 0; uint64_t gdbstub_watch_pages[(((uint32_t) -1) >> (MEM_GRANULARITY_BITS + 6)) + 1]; static void @@ -461,6 +469,9 @@ gdbstub_num_decode(char *p, int *dest, int mode) else return 0; break; + + default: + break; } p++; } @@ -476,8 +487,8 @@ gdbstub_num_decode(char *p, int *dest, int mode) static int gdbstub_client_read_word(gdbstub_client_t *client, int *dest) { - char *p = &client->packet[client->packet_pos]; - char *q = p; + const char *p = &client->packet[client->packet_pos]; + const char *q = p; while (((*p >= '0') && (*p <= '9')) || ((*p >= 'A') && (*p <= 'F')) || ((*p >= 'a') && (*p <= 'f'))) *dest = ((*dest) << 4) | gdbstub_hex_decode(*p++); return p - q; @@ -1491,7 +1502,6 @@ gdbstub_client_thread(void *priv) gdbstub_client_t *client = (gdbstub_client_t *) priv; uint8_t buf[256]; ssize_t bytes_read; - int i; gdbstub_log("GDB Stub: New connection from %s:%d\n", inet_ntoa(client->addr.sin_addr), client->addr.sin_port); @@ -1500,7 +1510,7 @@ gdbstub_client_thread(void *priv) /* Read data from client. */ while ((bytes_read = recv(client->socket, (char *) buf, sizeof(buf), 0)) > 0) { - for (i = 0; i < bytes_read; i++) { + for (ssize_t i = 0; i < bytes_read; i++) { switch (buf[i]) { case '$': /* packet start */ /* Wait for any existing packets to be processed. */ diff --git a/src/include/86box/hdc.h b/src/include/86box/hdc.h index 4320d86e2..64fd88659 100644 --- a/src/include/86box/hdc.h +++ b/src/include/86box/hdc.h @@ -60,16 +60,22 @@ extern const device_t ide_vlb_2ch_device; /* vlb_ide_2ch */ extern const device_t ide_pci_device; /* pci_ide */ extern const device_t ide_pci_2ch_device; /* pci_ide_2ch */ -extern const device_t ide_cmd640_vlb_device; /* CMD PCI-640B VLB */ -extern const device_t ide_cmd640_vlb_178_device; /* CMD PCI-640B VLB (Port 178h) */ -extern const device_t ide_cmd640_pci_device; /* CMD PCI-640B PCI */ -extern const device_t ide_cmd640_pci_legacy_only_device; /* CMD PCI-640B PCI (Legacy Mode Only) */ -extern const device_t ide_cmd640_pci_single_channel_device; /* CMD PCI-640B PCI (Only primary channel) */ -extern const device_t ide_cmd646_device; /* CMD PCI-646 */ -extern const device_t ide_cmd646_legacy_only_device; /* CMD PCI-646 (Legacy Mode Only) */ -extern const device_t ide_cmd646_single_channel_device; /* CMD PCI-646 (Only primary channel) */ +extern const device_t ide_cmd640_vlb_device; /* CMD PCI-640B VLB */ +extern const device_t ide_cmd640_vlb_178_device; /* CMD PCI-640B VLB (Port 178h) */ +extern const device_t ide_cmd640_vlb_pri_device; /* CMD PCI-640B VLB (Only primary channel) */ +extern const device_t ide_cmd640_vlb_pri_178_device; /* CMD PCI-640B VLB (Only primary channel) (Port 178h) */ +extern const device_t ide_cmd640_vlb_sec_device; /* CMD PCI-640B VLB (Only secondary channel) */ +extern const device_t ide_cmd640_vlb_sec_178_device; /* CMD PCI-640B VLB (Only secondary channel) (Port 178h) */ +extern const device_t ide_cmd640_pci_device; /* CMD PCI-640B PCI */ +extern const device_t ide_cmd640_pci_legacy_only_device; /* CMD PCI-640B PCI (Legacy Mode Only) */ +extern const device_t ide_cmd640_pci_single_channel_device; /* CMD PCI-640B PCI (Only primary channel) */ +extern const device_t ide_cmd640_pci_single_channel_sec_device; /* CMD PCI-640B PCI (Only secondary channel) */ +extern const device_t ide_cmd646_device; /* CMD PCI-646 */ +extern const device_t ide_cmd646_legacy_only_device; /* CMD PCI-646 (Legacy Mode Only) */ +extern const device_t ide_cmd646_single_channel_device; /* CMD PCI-646 (Only primary channel) */ -extern const device_t ide_opti611_vlb_device; /* OPTi 82c611/611A VLB */ +extern const device_t ide_opti611_vlb_device; /* OPTi 82c611/611A VLB */ +extern const device_t ide_opti611_vlb_sec_device; /* OPTi 82c611/611A VLB (Secondary channel) */ extern const device_t ide_ter_device; extern const device_t ide_ter_pnp_device; diff --git a/src/include/86box/keyboard.h b/src/include/86box/keyboard.h index f09507601..b84733d9c 100644 --- a/src/include/86box/keyboard.h +++ b/src/include/86box/keyboard.h @@ -268,9 +268,9 @@ extern void keyboard_get_states(uint8_t *cl, uint8_t *nl, uint8_t *sl); extern void keyboard_set_states(uint8_t cl, uint8_t nl, uint8_t sl); extern int keyboard_recv(uint16_t key); extern int keyboard_isfsenter(void); -extern int keyboard_isfsenter_down(void); +extern int keyboard_isfsenter_up(void); extern int keyboard_isfsexit(void); -extern int keyboard_isfsexit_down(void); +extern int keyboard_isfsexit_up(void); extern int keyboard_ismsexit(void); extern void keyboard_set_is_amstrad(int ams); diff --git a/src/include/86box/language.h b/src/include/86box/language.h index c9b807a99..af459c0ff 100644 --- a/src/include/86box/language.h +++ b/src/include/86box/language.h @@ -52,7 +52,6 @@ #define IDS_2077 2077 // "Click to capture mouse" #define IDS_2078 2078 // "Press F12-F8 to release mouse" #define IDS_2079 2079 // "Press F12-F8 or middle button.." -#define IDS_2080 2080 // "Unable to initialize Flui.." #define IDS_2081 2081 // "Bus" #define IDS_BUS IDS_2081 // "Bus" #define IDS_2082 2082 // "File" @@ -98,7 +97,6 @@ #define IDS_2108 2108 // "%u MB (CHS: %i, %i, %i)" #define IDS_2109 2109 // "Floppy %i (%s): %ls" #define IDS_2110 2110 // "All floppy images (*.0??;*.." -#define IDS_2111 2111 // "Unable to initialize Free.." #define IDS_2112 2112 // "Unable to initialize SDL..." #define IDS_2113 2113 // "Are you sure you want to..." #define IDS_2114 2114 // "Are you sure you want to..." @@ -119,9 +117,7 @@ #define IDS_2129 2129 // "Hardware not available" #define IDS_2130 2130 // "Make sure " LIB_NAME_PCAP "..." #define IDS_2131 2131 // "Invalid configuration" -#define IDS_2132 2132 // LIB_NAME_FREETYPE " is required..." #define IDS_2133 2133 // LIB_NAME_GS " is required for... -#define IDS_2134 2134 // LIB_NAME_FLUIDSYNTH " is required..." #define IDS_2135 2135 // "Entering fullscreen mode" #define IDS_2136 2136 // "Don't show this message again" #define IDS_2137 2137 // "Don't exit" diff --git a/src/include/86box/mem.h b/src/include/86box/mem.h index dee144109..bd2207fe7 100644 --- a/src/include/86box/mem.h +++ b/src/include/86box/mem.h @@ -194,7 +194,7 @@ typedef struct _mem_mapping_ { /* There is never a needed to pass a pointer to the mapping itself, it is much preferable to prepare a structure with the requires data (usually, the base address and mask) instead. */ - void *p; /* backpointer to device */ + void *priv; /* backpointer to device */ } mem_mapping_t; #ifdef USE_NEW_DYNAREC @@ -207,9 +207,9 @@ extern uint64_t *byte_code_present_mask; # define EVICT_NOT_IN_LIST ((uint32_t) -1) typedef struct page_t { - void (*write_b)(uint32_t addr, uint8_t val, struct page_t *p); - void (*write_w)(uint32_t addr, uint16_t val, struct page_t *p); - void (*write_l)(uint32_t addr, uint32_t val, struct page_t *p); + void (*write_b)(uint32_t addr, uint8_t val, struct page_t *page); + void (*write_w)(uint32_t addr, uint16_t val, struct page_t *page); + void (*write_l)(uint32_t addr, uint32_t val, struct page_t *page); uint8_t *mem; @@ -218,9 +218,11 @@ typedef struct page_t { /*Head of codeblock tree associated with this page*/ uint16_t head; - uint64_t code_present_mask, dirty_mask; + uint64_t code_present_mask; + uint64_t dirty_mask; - uint32_t evict_prev, evict_next; + uint32_t evict_prev; + uint32_t evict_next; uint64_t *byte_dirty_mask; uint64_t *byte_code_present_mask; @@ -228,31 +230,33 @@ typedef struct page_t { extern uint32_t purgable_page_list_head; __attribute__((always_inline)) static inline int -page_in_evict_list(page_t *p) +page_in_evict_list(page_t *page) { - return (p->evict_prev != EVICT_NOT_IN_LIST); + return (page->evict_prev != EVICT_NOT_IN_LIST); } -void page_remove_from_evict_list(page_t *p); -void page_add_to_evict_list(page_t *p); +void page_remove_from_evict_list(page_t *page); +void page_add_to_evict_list(page_t *page); #else typedef struct _page_ { - void (*write_b)(uint32_t addr, uint8_t val, struct _page_ *p); - void (*write_w)(uint32_t addr, uint16_t val, struct _page_ *p); - void (*write_l)(uint32_t addr, uint32_t val, struct _page_ *p); + void (*write_b)(uint32_t addr, uint8_t val, struct _page_ *page); + void (*write_w)(uint32_t addr, uint16_t val, struct _page_ *page); + void (*write_l)(uint32_t addr, uint32_t val, struct _page_ *page); uint8_t *mem; - uint64_t code_present_mask[4], - dirty_mask[4]; + uint64_t code_present_mask[4]; + uint64_t dirty_mask[4]; - struct codeblock_t *block[4], *block_2[4]; + struct codeblock_t *block[4]; + struct codeblock_t *block_2[4]; /*Head of codeblock tree associated with this page*/ struct codeblock_t *head; } page_t; #endif -extern uint8_t *ram, *ram2; +extern uint8_t *ram; +extern uint8_t *ram2; extern uint32_t rammask; extern uint8_t *rom; @@ -336,37 +340,37 @@ extern void addwritelookup(uint32_t virt, uint32_t phys); extern void mem_mapping_set(mem_mapping_t *, uint32_t base, uint32_t size, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p), + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv), uint8_t *exec, uint32_t flags, - void *p); + void *priv); extern void mem_mapping_add(mem_mapping_t *, uint32_t base, uint32_t size, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p), + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv), uint8_t *exec, uint32_t flags, - void *p); + void *priv); extern void mem_mapping_set_handler(mem_mapping_t *, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p)); + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv)); -extern void mem_mapping_set_p(mem_mapping_t *, void *p); +extern void mem_mapping_set_p(mem_mapping_t *, void *priv); extern void mem_mapping_set_addr(mem_mapping_t *, uint32_t base, uint32_t size); @@ -407,9 +411,9 @@ extern uint64_t mmutranslate_noabrt(uint32_t addr, int rw); extern void mem_invalidate_range(uint32_t start_addr, uint32_t end_addr); -extern void mem_write_ramb_page(uint32_t addr, uint8_t val, page_t *p); -extern void mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *p); -extern void mem_write_raml_page(uint32_t addr, uint32_t val, page_t *p); +extern void mem_write_ramb_page(uint32_t addr, uint8_t val, page_t *page); +extern void mem_write_ramw_page(uint32_t addr, uint16_t val, page_t *page); +extern void mem_write_raml_page(uint32_t addr, uint32_t val, page_t *page); extern void mem_flush_write_page(uint32_t addr, uint32_t virt); extern void mem_reset_page_blocks(void); diff --git a/src/include/86box/midi.h b/src/include/86box/midi.h index 029ad06dc..af7fd217d 100644 --- a/src/include/86box/midi.h +++ b/src/include/86box/midi.h @@ -40,10 +40,11 @@ typedef struct midi_in_handler_t { int cnt; uint32_t len; - void (*msg)(void *p, uint8_t *msg, uint32_t len); - int (*sysex)(void *p, uint8_t *buffer, uint32_t len, int abort); - struct midi_in_handler_t *p; - struct midi_in_handler_t *prev, *next; + void (*msg)(void *priv, uint8_t *msg, uint32_t len); + int (*sysex)(void *priv, uint8_t *buffer, uint32_t len, int abort); + struct midi_in_handler_t *priv; + struct midi_in_handler_t *prev; + struct midi_in_handler_t *next; } midi_in_handler_t; typedef struct midi_t { @@ -77,7 +78,7 @@ extern void midi_raw_out_byte(uint8_t val); extern void midi_clear_buffer(void); extern void midi_poll(void); -extern void midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int (*sysex)(void *p, uint8_t *buffer, uint32_t len, int abort), void *p); +extern void midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int (*sysex)(void *p, uint8_t *buffer, uint32_t len, int abort), void *priv); extern void midi_in_handlers_clear(void); extern void midi_in_msg(uint8_t *msg, uint32_t len); extern void midi_in_sysex(uint8_t *buffer, uint32_t len); diff --git a/src/include/86box/pci.h b/src/include/86box/pci.h index 60c0d8742..df9c4c573 100644 --- a/src/include/86box/pci.h +++ b/src/include/86box/pci.h @@ -69,7 +69,7 @@ enum { PCI_CARD_SOUND = 0x13, PCI_CARD_IDE = 0x14, PCI_CARD_NETWORK = 0x15, - PCI_CARD_BRIDGE = 0x16, + PCI_CARD_BRIDGE = 0x16 }; enum { diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 932dfe87b..2b0809c2e 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -55,6 +55,10 @@ extern int strnicmp(const char *s1, const char *s2, size_t n); # define off64_t off_t #endif +#if !defined (__APPLE__) && !defined(__clang__) +# define FALLTHROUGH_ANNOTATION +#endif + #ifdef _MSC_VER # define UNUSED(arg) arg #else diff --git a/src/include/86box/plat_fallthrough.h b/src/include/86box/plat_fallthrough.h new file mode 100644 index 000000000..212d662fe --- /dev/null +++ b/src/include/86box/plat_fallthrough.h @@ -0,0 +1,25 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Define the various platform support functions. + * + * + * + * Authors: Jasmine Iwanek, + * + * Copyright 2023 Jasmine Iwanek + */ + +#ifndef EMU_PLAT_FALLTHROUGH_H +#define EMU_PLAT_FALLTHROUGH_H + +#if !defined (__APPLE__) && !defined(__clang__) +# define FALLTHROUGH_ANNOTATION +#endif + +#endif /*EMU_PLAT_FALLTHROUGH_H*/ diff --git a/src/include/86box/rom.h b/src/include/86box/rom.h index 5da516aef..e4c50ac01 100644 --- a/src/include/86box/rom.h +++ b/src/include/86box/rom.h @@ -54,7 +54,7 @@ extern uint32_t rom_readl(uint32_t addr, void *p); extern FILE *rom_fopen(const char *fn, char *mode); extern int rom_getfile(char *fn, char *s, int size); -extern int rom_present(char *fn); +extern int rom_present(const char *fn); extern int rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr); diff --git a/src/include/86box/snd_ac97.h b/src/include/86box/snd_ac97.h index ee75d56c4..45a921863 100644 --- a/src/include/86box/snd_ac97.h +++ b/src/include/86box/snd_ac97.h @@ -17,7 +17,7 @@ #ifndef SOUND_AC97_H #define SOUND_AC97_H -#define AC97_VENDOR_ID(f, s, t, dev) ((((f) &0xff) << 24) | (((s) &0xff) << 16) | (((t) &0xff) << 8) | ((dev) &0xff)) +#define AC97_VENDOR_ID(a, b, c, i) ((((a) &0xff) << 24) | (((b) &0xff) << 16) | (((c) &0xff) << 8) | ((i) &0xff)) /* Misc support bits (misc_flags). Most of these are not part of any registers, but control enabling/disabling of registers and bits. */ @@ -91,32 +91,26 @@ #define AC97_PRK (1 << 13) #define AC97_PRL (1 << 14) -/* New codecs should be added to the end of this enum to avoid breaking configs. */ -enum { - AC97_CODEC_AD1881 = 0, - AC97_CODEC_ALC100 = 1, - AC97_CODEC_CS4297 = 2, - AC97_CODEC_CS4297A = 3, - AC97_CODEC_WM9701A = 4, - AC97_CODEC_STAC9708 = 5, - AC97_CODEC_STAC9721 = 6, - AC97_CODEC_AK4540 = 7 -}; +/* Codec IDs. */ +#define AC97_CODEC_AD1881 AC97_VENDOR_ID('A', 'D', 'S', 0x40) +#define AC97_CODEC_AK4540 AC97_VENDOR_ID('A', 'D', 'S', 0x40) +#define AC97_CODEC_ALC100 AC97_VENDOR_ID('A', 'L', 'C', 0x20) +#define AC97_CODEC_CS4297 AC97_VENDOR_ID('C', 'R', 'Y', 0x03) +#define AC97_CODEC_CS4297A AC97_VENDOR_ID('C', 'R', 'Y', 0x11) +#define AC97_CODEC_STAC9708 AC97_VENDOR_ID(0x83, 0x84, 0x76, 0x08) +#define AC97_CODEC_STAC9721 AC97_VENDOR_ID(0x83, 0x84, 0x76, 0x09) +#define AC97_CODEC_TR28023 AC97_VENDOR_ID('T', 'R', 'A', 0x03) +#define AC97_CODEC_WM9701A AC97_VENDOR_ID('W', 'M', 'L', 0x00) typedef struct ac97_vendor_reg_t { - const uint16_t index; - const uint16_t value; - const uint16_t write_mask; + uint8_t page; /* for paged registers [60:6F], 0 otherwise */ + uint8_t index; + uint16_t value; + uint16_t write_mask; } ac97_vendor_reg_t; typedef struct ac97_codec_t { - uint32_t vendor_id; - uint32_t min_rate; - uint32_t max_rate; - uint32_t misc_flags; - uint16_t reset_flags; - uint16_t extid_flags; - uint16_t powerdown_mask; + int model; uint16_t regs[64]; uint8_t codec_id; uint8_t vendor_reg_page_max; @@ -129,7 +123,7 @@ extern void ac97_codec_writew(ac97_codec_t *dev, uint8_t reg, uint16_ extern void ac97_codec_reset(void *priv); extern void ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r); extern uint32_t ac97_codec_getrate(void *priv, uint8_t reg); -extern const device_t *ac97_codec_get(int model); +extern const device_t *ac97_codec_get(uint32_t id); extern void ac97_via_set_slot(void *priv, int slot, int irq_pin); extern uint8_t ac97_via_read_status(void *priv, uint8_t modem); @@ -152,8 +146,10 @@ extern const device_t ak4540_device; extern const device_t alc100_device; extern const device_t cs4297_device; extern const device_t cs4297a_device; +# define ct1297_device tr28023_device extern const device_t stac9708_device; extern const device_t stac9721_device; +extern const device_t tr28023_device; extern const device_t wm9701a_device; extern const device_t ac97_via_device; diff --git a/src/include/86box/timer.h b/src/include/86box/timer.h index 774729e17..e38ac51a3 100644 --- a/src/include/86box/timer.h +++ b/src/include/86box/timer.h @@ -47,8 +47,8 @@ typedef struct pc_timer_t { double period; /* This is used for large period timers to count the microseconds and split the period. */ - void (*callback)(void *p); - void *p; + void (*callback)(void *priv); + void *priv; struct pc_timer_t *prev; struct pc_timer_t *next; @@ -76,7 +76,7 @@ extern void timer_init(void); /*Add new timer. If start_timer is set, timer will be enabled with a zero timestamp - this is useful for permanently enabled timers*/ -extern void timer_add(pc_timer_t *timer, void (*callback)(void *p), void *p, int start_timer); +extern void timer_add(pc_timer_t *timer, void (*callback)(void *priv), void *priv, int start_timer); /*1us in 32:32 format*/ extern uint64_t TIMER_USEC; @@ -162,16 +162,16 @@ timer_get_remaining_u64(pc_timer_t *timer) /*Set timer callback function*/ static __inline void -timer_set_callback(pc_timer_t *timer, void (*callback)(void *p)) +timer_set_callback(pc_timer_t *timer, void (*callback)(void *priv)) { timer->callback = callback; } /*Set timer private data*/ static __inline void -timer_set_p(pc_timer_t *timer, void *p) +timer_set_p(pc_timer_t *timer, void *priv) { - timer->p = p; + timer->priv = priv; } /* The API for big timer periods starts here. */ @@ -209,7 +209,7 @@ timer_process_inline(void) if (timer->flags & TIMER_SPLIT) timer_advance_ex(timer, 0); /* We're splitting a > 1 s period into multiple <= 1 s periods. */ else if (timer->callback != NULL) /* Make sure it's no NULL, so that we can have a NULL callback when no operation is needed. */ - timer->callback(timer->p); + timer->callback(timer->priv); } timer_target = timer_head->ts.ts32.integer; diff --git a/src/include/86box/vid_8514a.h b/src/include/86box/vid_8514a.h index b21da9fba..b2932c725 100644 --- a/src/include/86box/vid_8514a.h +++ b/src/include/86box/vid_8514a.h @@ -31,22 +31,30 @@ typedef struct ibm8514_t { uint32_t vram_mask; PALETTE vgapal; - uint8_t dac_mask, dac_status; + uint8_t dac_mask; + uint8_t dac_status; uint32_t *map8; - int dac_addr, dac_pos, dac_r, dac_g; + int dac_addr; + int dac_pos; + int dac_r; + int dac_g; int internal_pitch; struct { uint16_t subsys_cntl; uint16_t setup_md; - uint8_t advfunc_cntl, ext_advfunc_cntl; - uint16_t cur_y, cur_y_bitres; - uint16_t cur_x, cur_x_bitres; + uint8_t advfunc_cntl; + uint8_t ext_advfunc_cntl; + uint16_t cur_y; + uint16_t cur_y_bitres; + uint16_t cur_x; + uint16_t cur_x_bitres; int16_t desty_axstp; int16_t destx_distp; int16_t err_term; int16_t maj_axis_pcnt; - uint16_t cmd, cmd_back; + uint16_t cmd; + uint16_t cmd_back; uint16_t short_stroke; uint16_t bkgd_color; uint16_t frgd_color; @@ -57,63 +65,120 @@ typedef struct ibm8514_t { uint16_t frgd_mix; uint16_t multifunc_cntl; uint16_t multifunc[16]; - int16_t clip_left, clip_top; + int16_t clip_left; + int16_t clip_top; uint8_t pix_trans[2]; int poly_draw; int ssv_state; - int16_t x1, x2, x3, y1, y2; - int sys_cnt, sys_cnt2; + int x1; + int x2; + int x3; + int y1; + int y2; + int sys_cnt; + int sys_cnt2; int temp_cnt; - int16_t cx, cy, oldcy; - int16_t sx, sy; - int16_t dx, dy; + int16_t cx; + int16_t cy; + int16_t oldcy; + int16_t sx; + int16_t sy; + int16_t dx; + int16_t dy; int16_t err; - uint32_t src, dest; - uint32_t newsrc_blt, newdest_blt; - uint32_t newdest_in, newdest_out; - uint8_t *writemono, *nibbleset; - int x_count, xx_count, y_count; - int input, output; + uint32_t src; + uint32_t dest; + uint32_t newsrc_blt; + uint32_t newdest_blt; + uint32_t newdest_in; + uint32_t newdest_out; + uint8_t *writemono; + uint8_t *nibbleset; + int x_count; + int xx_count; + int y_count; + int input; + int output; - uint16_t cur_x_bit12, cur_y_bit12; + uint16_t cur_x_bit12; + uint16_t cur_y_bit12; int ssv_len; uint8_t ssv_dir; uint8_t ssv_draw; - int odd_in, odd_out; + int odd_in; + int odd_out; uint16_t scratch; - int fill_state, xdir, ydir; + int fill_state; + int xdir; + int ydir; uint32_t ge_offset; } accel; uint16_t test; - int ibm_mode; + int ibm_mode; - int v_total, dispend, v_syncstart, split, - h_disp, h_disp_old, h_total, h_disp_time, rowoffset, - dispon, hdisp_on, linecountff, - vc, linepos, oddeven, cursoron, blink, scrollcache, - firstline, lastline, firstline_draw, lastline_draw, - displine, fullchange; - uint32_t ma, maback; + int v_total; + int dispend; + int v_syncstart; + int split; + int h_disp; + int h_disp_old; + int h_total; + int h_disp_time; + int rowoffset; + int dispon; + int hdisp_on; + int linecountff; + int vc; + int linepos; + int oddeven; + int cursoron; + int blink; + int scrollcache; + int firstline; + int lastline; + int firstline_draw; + int lastline_draw; + int displine; + int fullchange; + uint32_t ma; + uint32_t maback; - uint8_t *vram, *changedvram, linedbl; + uint8_t *vram; + uint8_t *changedvram; + uint8_t linedbl; - uint8_t data_available, data_available2; - uint8_t scanmodulos, rowcount; - int htotal, hdisp, vtadj, vdadj, vsadj, sc, - vtb, vdb, vsb, vsyncstart, vsyncwidth; - int vtotal, vdisp; - int disp_cntl, interlace; - uint8_t subsys_cntl, subsys_stat; + uint8_t data_available; + uint8_t data_available2; + uint8_t scanmodulos; + uint8_t rowcount; + int htotal; + int hdisp; + int vtadj; + int vdadj; + int vsadj; + int sc; + int vtb; + int vdb; + int vsb; + int vsyncstart; + int vsyncwidth; + int vtotal; + int vdisp; + int disp_cntl; + int interlace; + uint8_t subsys_cntl; + uint8_t subsys_stat; - atomic_int force_busy, force_busy2; + atomic_int force_busy; + atomic_int force_busy2; int blitter_busy; uint64_t blitter_time; uint64_t status_time; - int pitch; - int ext_pitch; - int ext_crt_pitch; + int pitch; + int ext_pitch; + int ext_crt_pitch; } ibm8514_t; #endif /*VIDEO_8514A_H*/ diff --git a/src/include/86box/vid_ati_eeprom.h b/src/include/86box/vid_ati_eeprom.h index 7de5170d8..99af36eda 100644 --- a/src/include/86box/vid_ati_eeprom.h +++ b/src/include/86box/vid_ati_eeprom.h @@ -32,8 +32,12 @@ enum { typedef struct ati_eeprom_t { uint16_t data[256]; - int oldclk, oldena; - int opcode, state, count, out; + int oldclk; + int oldena; + int opcode; + int state; + int count; + int out; int wp; uint32_t dat; int type; diff --git a/src/include/86box/vid_cga.h b/src/include/86box/vid_cga.h index 39e1c24ef..f49fc73cc 100644 --- a/src/include/86box/vid_cga.h +++ b/src/include/86box/vid_cga.h @@ -28,21 +28,31 @@ typedef struct cga_t { uint8_t cgastat; - uint8_t cgamode, cgacol; + uint8_t cgamode; + uint8_t cgacol; int fontbase; - int linepos, displine; - int sc, vc; + int linepos; + int displine; + int sc; + int vc; int cgadispon; - int con, coff, cursoron, cgablink; - int vsynctime, vadj; - uint16_t ma, maback; + int con; + int coff; + int cursoron; + int cgablink; + int vsynctime; + int vadj; + uint16_t ma; + uint16_t maback; int oddeven; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; - int firstline, lastline; + int firstline; + int lastline; int drawcursor; @@ -59,12 +69,12 @@ typedef struct cga_t { } cga_t; void cga_init(cga_t *cga); -void cga_out(uint16_t addr, uint8_t val, void *p); -uint8_t cga_in(uint16_t addr, void *p); -void cga_write(uint32_t addr, uint8_t val, void *p); -uint8_t cga_read(uint32_t addr, void *p); +void cga_out(uint16_t addr, uint8_t val, void *priv); +uint8_t cga_in(uint16_t addr, void *priv); +void cga_write(uint32_t addr, uint8_t val, void *priv); +uint8_t cga_read(uint32_t addr, void *priv); void cga_recalctimings(cga_t *cga); -void cga_poll(void *p); +void cga_poll(void *priv); #ifdef EMU_DEVICE_H extern const device_config_t cga_config[]; diff --git a/src/include/86box/vid_cga_comp.h b/src/include/86box/vid_cga_comp.h index 3c7916034..291145291 100644 --- a/src/include/86box/vid_cga_comp.h +++ b/src/include/86box/vid_cga_comp.h @@ -21,13 +21,11 @@ #ifndef VIDEO_CGA_COMP_H #define VIDEO_CGA_COMP_H -#define Bit8u uint8_t -#define Bit32u uint32_t -#define Bitu unsigned int -#define bool uint8_t +#define Bitu unsigned int +#define bool uint8_t void update_cga16_color(uint8_t cgamode); void cga_comp_init(int revision); -Bit32u *Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewidth*/, Bit32u *TempLine); +Bit32u *Composite_Process(uint8_t cgamode, uint8_t border, uint32_t blocks /*, bool doublewidth*/, uint32_t *TempLine); #endif /*VIDEO_CGA_COMP_H*/ diff --git a/src/include/86box/vid_ega.h b/src/include/86box/vid_ega.h index 6c4eb02a8..97a08b583 100644 --- a/src/include/86box/vid_ega.h +++ b/src/include/86box/vid_ega.h @@ -27,11 +27,26 @@ typedef struct ega_t { rom_t bios_rom; - uint8_t crtcreg, gdcaddr, attraddr, attrff, - attr_palette_enable, seqaddr, miscout, - writemask, la, lb, lc, ld, - stat, colourcompare, colournocare, scrblank, - plane_mask, pad, pad0, pad1; + uint8_t crtcreg; + uint8_t gdcaddr; + uint8_t attraddr; + uint8_t attrff; + uint8_t attr_palette_enable; + uint8_t seqaddr; + uint8_t miscout; + uint8_t writemask; + uint8_t la; + uint8_t lb; + uint8_t lc; + uint8_t ld; + uint8_t stat; + uint8_t colourcompare; + uint8_t colournocare; + uint8_t scrblank; + uint8_t plane_mask; + uint8_t pad; + uint8_t pad0; + uint8_t pad1; uint8_t crtc[32]; uint8_t gdcreg[16]; uint8_t attrregs[32]; @@ -41,25 +56,72 @@ typedef struct ega_t { uint8_t *vram; - int vidclock, fast, extvram, vres, - readmode, writemode, readplane, vrammask, - chain4, chain2_read, chain2_write, con, - oddeven_page, oddeven_chain, vc, sc, - dispon, hdisp_on, cursoron, blink, fullchange, - linepos, vslines, linecountff, oddeven, - lowres, interlace, linedbl, lindebl, rowcount, - vtotal, dispend, vsyncstart, split, - hdisp, hdisp_old, htotal, hdisp_time, rowoffset, - vblankstart, scrollcache, firstline, lastline, - firstline_draw, lastline_draw, x_add, y_add, - displine, res_x, res_y, bpp, index; + int vidclock; + int fast; + int extvram; + int vres; + int readmode; + int writemode; + int readplane; + int vrammask; + int chain4; + int chain2_read; + int chain2_write; + int con; + int oddeven_page; + int oddeven_chain; + int vc; + int sc; + int dispon; + int hdisp_on; + int cursoron; + int blink; + int fullchange; + int linepos; + int vslines; + int linecountff; + int oddeven; + int lowres; + int interlace; + int linedbl; + int lindebl; + int rowcount; + int vtotal; + int dispend; + int vsyncstart; + int split; + int hdisp; + int hdisp_old; + int htotal; + int hdisp_time; + int rowoffset; + int vblankstart; + int scrollcache; + int firstline; + int lastline; + int firstline_draw; + int lastline_draw; + int x_add; + int y_add; + int displine; + int res_x; + int res_y; + int bpp; + int index; - uint32_t charseta, charsetb, ma_latch, ma, - maback, ca, vram_limit, overscan_color; + uint32_t charseta; + uint32_t charsetb; + uint32_t ma_latch; + uint32_t ma; + uint32_t maback; + uint32_t ca; + uint32_t vram_limit; + uint32_t overscan_color; uint32_t *pallook; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; double clock; @@ -97,18 +159,22 @@ extern void ega_recalctimings(struct ega_t *ega); extern void ega_recalc_remap_func(struct ega_t *ega); #endif -extern void ega_out(uint16_t addr, uint8_t val, void *p); -extern uint8_t ega_in(uint16_t addr, void *p); -extern void ega_poll(void *p); -extern void ega_write(uint32_t addr, uint8_t val, void *p); -extern uint8_t ega_read(uint32_t addr, void *p); +extern void ega_out(uint16_t addr, uint8_t val, void *priv); +extern uint8_t ega_in(uint16_t addr, void *priv); +extern void ega_poll(void *priv); +extern void ega_write(uint32_t addr, uint8_t val, void *priv); +extern uint8_t ega_read(uint32_t addr, void *priv); -extern int firstline_draw, lastline_draw; +extern int firstline_draw; +extern int lastline_draw; extern int displine; extern int sc; -extern uint32_t ma, ca; -extern int con, cursoron, cgablink; +extern uint32_t ma; +extern uint32_t ca; +extern int con; +extern int cursoron; +extern int cgablink; extern int scrollcache; diff --git a/src/include/86box/vid_ega_render_remap.h b/src/include/86box/vid_ega_render_remap.h index 37f6904db..b01bb2b0e 100644 --- a/src/include/86box/vid_ega_render_remap.h +++ b/src/include/86box/vid_ega_render_remap.h @@ -85,7 +85,7 @@ ega_recalc_remap_func(ega_t *ega) func_nr = VAR_DWORD_MODE; else if (ega->crtc[0x17] & 0x40) func_nr = VAR_BYTE_MODE; - else if ((ega->crtc[0x17] & 0x20) && ega->vram_limit > 64*1024) + else if ((ega->crtc[0x17] & 0x20) && ega->vram_limit > 64 * 1024) func_nr = VAR_WORD_MODE_MA15; else func_nr = VAR_WORD_MODE_MA13; diff --git a/src/include/86box/vid_hercules.h b/src/include/86box/vid_hercules.h index bbb4239aa..b5ba6af9f 100644 --- a/src/include/86box/vid_hercules.h +++ b/src/include/86box/vid_hercules.h @@ -25,30 +25,32 @@ typedef struct { mem_mapping_t mapping; - uint8_t crtc[32], charbuffer[4096]; + uint8_t crtc[32]; + uint8_t charbuffer[4096]; int crtcreg; - uint8_t ctrl, - ctrl2, - stat; + uint8_t ctrl; + uint8_t ctrl2; + uint8_t stat; - uint64_t dispontime, - dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; - int firstline, - lastline; + int firstline; + int lastline; - int linepos, - displine; - int vc, - sc; - uint16_t ma, - maback; - int con, coff, - cursoron; - int dispon, - blink; + int linepos; + int displine; + int vc; + int sc; + uint16_t ma; + uint16_t maback; + int con; + int coff; + int cursoron; + int dispon; + int blink; int vsynctime; int vadj; diff --git a/src/include/86box/vid_mda.h b/src/include/86box/vid_mda.h index 0f5080865..ea98bef61 100644 --- a/src/include/86box/vid_mda.h +++ b/src/include/86box/vid_mda.h @@ -11,18 +11,27 @@ typedef struct mda_t { uint8_t crtc[32]; int crtcreg; - uint8_t ctrl, stat; + uint8_t ctrl; + uint8_t stat; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; - int firstline, lastline; + int firstline; + int lastline; - int linepos, displine; - int vc, sc; - uint16_t ma, maback; - int con, coff, cursoron; - int dispon, blink; + int linepos; + int displine; + int vc; + int sc; + uint16_t ma; + uint16_t maback; + int con; + int coff; + int cursoron; + int dispon; + int blink; int vsynctime; int vadj; int monitor_index; @@ -43,12 +52,12 @@ typedef struct mda_t { void mda_init(mda_t *mda); void mda_setcol(int chr, int blink, int fg, uint8_t cga_ink); -void mda_out(uint16_t addr, uint8_t val, void *p); -uint8_t mda_in(uint16_t addr, void *p); -void mda_write(uint32_t addr, uint8_t val, void *p); -uint8_t mda_read(uint32_t addr, void *p); +void mda_out(uint16_t addr, uint8_t val, void *priv); +uint8_t mda_in(uint16_t addr, void *priv); +void mda_write(uint32_t addr, uint8_t val, void *priv); +uint8_t mda_read(uint32_t addr, void *priv); void mda_recalctimings(mda_t *mda); -void mda_poll(void *p); +void mda_poll(void *priv); #ifdef EMU_DEVICE_H extern const device_t mda_device; diff --git a/src/include/86box/vid_pgc.h b/src/include/86box/vid_pgc.h index 12450c0d1..a59ca3d8e 100644 --- a/src/include/86box/vid_pgc.h +++ b/src/include/86box/vid_pgc.h @@ -59,10 +59,10 @@ typedef struct pgc { mem_mapping_t mapping; mem_mapping_t cga_mapping; - pgc_cl_t *clist, - *clcur; - const pgc_cmd_t *master, - *commands; + pgc_cl_t *clist; + pgc_cl_t *clcur; + const pgc_cmd_t *master; + const pgc_cmd_t *commands; uint8_t mapram[2048]; /* host <> PGC communication buffer */ uint8_t *cga_vram; @@ -73,10 +73,18 @@ typedef struct pgc { uint32_t userpal[256]; uint32_t maxw, maxh; /* maximum framebuffer size */ uint32_t visw, vish; /* maximum screen size */ - uint32_t screenw, screenh; - int16_t pan_x, pan_y; - uint16_t win_x1, win_x2, win_y1, win_y2; - uint16_t vp_x1, vp_x2, vp_y1, vp_y2; + uint32_t screenw; + uint32_t screenh; + int16_t pan_x; + int16_t pan_y; + uint16_t win_x1; + uint16_t win_x2; + uint16_t win_y1; + uint16_t win_y2; + uint16_t vp_x1; + uint16_t vp_x2; + uint16_t vp_y1; + uint16_t vp_y2; int16_t fill_pattern[16]; int16_t line_pattern; uint8_t draw_mode; @@ -86,7 +94,9 @@ typedef struct pgc { uint8_t tjust_v; /* vert alignment 1=bottom 2=ctr 3=top*/ int32_t tsize; /* horizontal spacing */ - int32_t x, y, z; /* drawing position */ + int32_t x; + int32_t y; + int32_t z; /* drawing position */ thread_t *pgc_thread; event_t *pgc_wake_thread; @@ -98,18 +108,23 @@ typedef struct pgc { int ascii_mode; int result_count; - int fontbase; - int linepos, - displine; + int fontbase; + int linepos; + int displine; int vc; int cgadispon; - int con, coff, cursoron, cgablink; - int vsynctime, vadj; - uint16_t ma, maback; + int con; + int coff; + int cursoron; + int cgablink; + int vsynctime; + int vadj; + uint16_t ma; + uint16_t maback; int oddeven; - uint64_t dispontime, - dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; double native_pixel_clock; @@ -140,10 +155,14 @@ extern void pgc_init(pgc_t *, extern void pgc_sto_raster(pgc_t *, int16_t *x, int16_t *y); extern void pgc_ito_raster(pgc_t *, int32_t *x, int32_t *y); extern void pgc_dto_raster(pgc_t *, double *x, double *y); -// extern int pgc_input_byte(pgc_t *, uint8_t *val); -// extern int pgc_output_byte(pgc_t *, uint8_t val); +#if 0 +extern int pgc_input_byte(pgc_t *, uint8_t *val); +extern int pgc_output_byte(pgc_t *, uint8_t val); +#endif extern int pgc_output_string(pgc_t *, const char *val); -// extern int pgc_error_byte(pgc_t *, uint8_t val); +#if 0 +extern int pgc_error_byte(pgc_t *, uint8_t val); +#endif extern int pgc_error_string(pgc_t *, const char *val); extern int pgc_error(pgc_t *, int err); diff --git a/src/include/86box/vid_svga.h b/src/include/86box/vid_svga.h index f8dafdd20..ab8144a77 100644 --- a/src/include/86box/vid_svga.h +++ b/src/include/86box/vid_svga.h @@ -31,16 +31,23 @@ # define FLAG_NOSKEW 16 # define FLAG_ADDR_BY16 32 # define FLAG_RAMDAC_SHIFT 64 -# define FLAG_ATI 128 +# define FLAG_ATI 128 # define FLAG_S3_911_16BIT 256 # define FLAG_512K_MASK 512 struct monitor_t; -typedef struct { - int ena, - x, y, xoff, yoff, cur_xsize, cur_ysize, - v_acc, h_acc; - uint32_t addr, pitch; +typedef struct hwcursor_t { + int ena; + int x; + int y; + int xoff; + int yoff; + int cur_xsize; + int cur_ysize; + int v_acc; + int h_acc; + uint32_t addr; + uint32_t pitch; } hwcursor_t; typedef union { @@ -55,25 +62,78 @@ typedef struct svga_t { xga_t xga; mem_mapping_t mapping; - uint8_t fast, chain4, chain2_write, chain2_read, - ext_overscan, bus_size, - lowres, interlace, linedbl, rowcount, - set_reset_disabled, bpp, ramdac_type, fb_only, - readmode, writemode, readplane, - hwcursor_oddeven, dac_hwcursor_oddeven, overlay_oddeven, - fcr, hblank_overscan; + uint8_t fast; + uint8_t chain4; + uint8_t chain2_write; + uint8_t chain2_read; + uint8_t ext_overscan; + uint8_t bus_size; + uint8_t lowres; + uint8_t interlace; + uint8_t linedbl; + uint8_t rowcount; + uint8_t set_reset_disabled; + uint8_t bpp; + uint8_t ramdac_type; + uint8_t fb_only; + uint8_t readmode; + uint8_t writemode; + uint8_t readplane; + uint8_t hwcursor_oddeven; + uint8_t dac_hwcursor_oddeven; + uint8_t overlay_oddeven; + uint8_t fcr; + uint8_t hblank_overscan; - int dac_addr, dac_pos, dac_r, dac_g, - vtotal, dispend, vsyncstart, split, vblankstart, - hdisp, hdisp_old, htotal, hdisp_time, rowoffset, - dispon, hdisp_on, - vc, sc, linepos, vslines, linecountff, oddeven, - con, cursoron, blink, scrollcache, char_width, - firstline, lastline, firstline_draw, lastline_draw, - displine, fullchange, x_add, y_add, pan, - vram_display_mask, vidclock, dots_per_clock, hblank_ext, - hwcursor_on, dac_hwcursor_on, overlay_on, set_override, - hblankstart, hblankend, hblank_sub, hblank_end_val, hblank_end_len; + int dac_addr; + int dac_pos; + int dac_r; + int dac_g; + int vtotal; + int dispend; + int vsyncstart; + int split; + int vblankstart; + int hdisp; + int hdisp_old; + int htotal; + int hdisp_time; + int rowoffset; + int dispon; + int hdisp_on; + int vc; + int sc; + int linepos; + int vslines; + int linecountff; + int oddeven; + int con; + int cursoron; + int blink; + int scrollcache; + int char_width; + int firstline; + int lastline; + int firstline_draw; + int lastline_draw; + int displine; + int fullchange; + int x_add; + int y_add; + int pan; + int vram_display_mask; + int vidclock; + int dots_per_clock; + int hblank_ext; + int hwcursor_on; + int dac_hwcursor_on; + int overlay_on; + int set_override; + int hblankstart; + int hblankend; + int hblank_sub; + int hblank_end_val; + int hblank_end_len; /*The three variables below allow us to implement memory maps like that seen on a 1MB Trio64 : 0MB-1MB - VRAM @@ -84,35 +144,47 @@ typedef struct svga_t { For the example memory map, decode_mask would be 4MB-1 (4MB address space), vram_max would be 2MB (present video memory only responds to first 2MB), vram_mask would be 1MB-1 (video memory wraps at 1MB) */ - uint32_t decode_mask, vram_max, - vram_mask, - charseta, charsetb, - adv_flags, ma_latch, - ca_adj, ma, maback, - write_bank, read_bank, - extra_banks[2], - banked_mask, - ca, overscan_color, - *map8, pallook[512]; + uint32_t decode_mask; + uint32_t vram_max; + uint32_t vram_mask; + uint32_t charseta; + uint32_t charsetb; + uint32_t adv_flags; + uint32_t ma_latch; + uint32_t ca_adj; + uint32_t ma; + uint32_t maback; + uint32_t write_bank; + uint32_t read_bank; + uint32_t extra_banks[2]; + uint32_t banked_mask; + uint32_t ca; + uint32_t overscan_color; + uint32_t *map8; + uint32_t pallook[512]; PALETTE vgapal; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; latch_t latch; pc_timer_t timer; double clock; - hwcursor_t hwcursor, hwcursor_latch, - dac_hwcursor, dac_hwcursor_latch, - overlay, overlay_latch; + hwcursor_t hwcursor; + hwcursor_t hwcursor_latch; + hwcursor_t dac_hwcursor; + hwcursor_t dac_hwcursor_latch; + hwcursor_t overlay; + hwcursor_t overlay_latch; void (*render)(struct svga_t *svga); void (*recalctimings_ex)(struct svga_t *svga); - void (*video_out)(uint16_t addr, uint8_t val, void *p); - uint8_t (*video_in)(uint16_t addr, void *p); + void (*video_out)(uint16_t addr, uint8_t val, void *priv); + uint8_t (*video_in)(uint16_t addr, void *priv); void (*hwcursor_draw)(struct svga_t *svga, int displine); @@ -123,7 +195,7 @@ typedef struct svga_t { void (*vblank_start)(struct svga_t *svga); void (*ven_write)(struct svga_t *svga, uint8_t val, uint32_t addr); - float (*getclock)(int clock, void *p); + float (*getclock)(int clock, void *priv); /* Called when VC=R18 and friends. If this returns zero then MA resetting is skipped. Matrox Mystique in Power mode reuses this counter for @@ -133,24 +205,39 @@ typedef struct svga_t { /*Called at the start of vertical sync*/ void (*vsync_callback)(struct svga_t *svga); - uint32_t (*translate_address)(uint32_t addr, void *p); + uint32_t (*translate_address)(uint32_t addr, void *priv); /*If set then another device is driving the monitor output and the SVGA card should not attempt to display anything */ int override; - void *p; + void *priv; - uint8_t crtc[256], gdcreg[256], attrregs[32], seqregs[256], - egapal[16], - *vram, *changedvram; + uint8_t crtc[256]; + uint8_t gdcreg[256]; + uint8_t attrregs[32]; + uint8_t seqregs[256]; + uint8_t egapal[16]; + uint8_t *vram; + uint8_t *changedvram; - uint8_t crtcreg, gdcaddr, - attrff, attr_palette_enable, attraddr, seqaddr, - miscout, cgastat, scrblank, - plane_mask, writemask, - colourcompare, colournocare, - dac_mask, dac_status, - dpms, dpms_ui, - ksc5601_sbyte_mask, ksc5601_udc_area_msb[2]; + uint8_t crtcreg; + uint8_t gdcaddr; + uint8_t attrff; + uint8_t attr_palette_enable; + uint8_t attraddr; + uint8_t seqaddr; + uint8_t miscout; + uint8_t cgastat; + uint8_t scrblank; + uint8_t plane_mask; + uint8_t writemask; + uint8_t colourcompare; + uint8_t colournocare; + uint8_t dac_mask; + uint8_t dac_status; + uint8_t dpms; + uint8_t dpms_ui; + uint8_t ksc5601_sbyte_mask; + uint8_t ksc5601_udc_area_msb[2]; int ksc5601_swap_mode; uint16_t ksc5601_english_font_type; @@ -172,61 +259,62 @@ typedef struct svga_t { int remap_required; uint32_t (*remap_func)(struct svga_t *svga, uint32_t in_addr); - void *ramdac, *clock_gen; + void *ramdac; + void *clock_gen; /* Monitor Index */ uint8_t monitor_index; /* Pointer to monitor */ - monitor_t* monitor; + monitor_t *monitor; } svga_t; extern int vga_on; extern int ibm8514_on; -extern void ibm8514_poll(ibm8514_t *dev, svga_t *svga); -extern void ibm8514_recalctimings(svga_t *svga); -extern uint8_t ibm8514_ramdac_in(uint16_t port, void *p); -extern void ibm8514_ramdac_out(uint16_t port, uint8_t val, void *p); -extern int ibm8514_cpu_src(svga_t *svga); -extern int ibm8514_cpu_dest(svga_t *svga); -extern void ibm8514_accel_out_pixtrans(svga_t *svga, uint16_t port, uint16_t val, int len); -extern void ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, uint8_t ssv, int len); -extern void ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, int len); +extern void ibm8514_poll(ibm8514_t *dev, svga_t *svga); +extern void ibm8514_recalctimings(svga_t *svga); +extern uint8_t ibm8514_ramdac_in(uint16_t port, void *priv); +extern void ibm8514_ramdac_out(uint16_t port, uint8_t val, void *priv); +extern int ibm8514_cpu_src(svga_t *svga); +extern int ibm8514_cpu_dest(svga_t *svga); +extern void ibm8514_accel_out_pixtrans(svga_t *svga, uint16_t port, uint16_t val, int len); +extern void ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, uint8_t ssv, int len); +extern void ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, int len); extern void xga_poll(xga_t *xga, svga_t *svga); extern void xga_recalctimings(svga_t *svga); -extern int svga_init(const device_t *info, svga_t *svga, void *p, int memsize, +extern int svga_init(const device_t *info, svga_t *svga, void *priv, int memsize, void (*recalctimings_ex)(struct svga_t *svga), - uint8_t (*video_in)(uint16_t addr, void *p), - void (*video_out)(uint16_t addr, uint8_t val, void *p), + uint8_t (*video_in)(uint16_t addr, void *priv), + void (*video_out)(uint16_t addr, uint8_t val, void *priv), void (*hwcursor_draw)(struct svga_t *svga, int displine), void (*overlay_draw)(struct svga_t *svga, int displine)); extern void svga_recalctimings(svga_t *svga); extern void svga_close(svga_t *svga); -uint8_t svga_read(uint32_t addr, void *p); -uint16_t svga_readw(uint32_t addr, void *p); -uint32_t svga_readl(uint32_t addr, void *p); -void svga_write(uint32_t addr, uint8_t val, void *p); -void svga_writew(uint32_t addr, uint16_t val, void *p); -void svga_writel(uint32_t addr, uint32_t val, void *p); -uint8_t svga_read_linear(uint32_t addr, void *p); -uint8_t svga_readb_linear(uint32_t addr, void *p); -uint16_t svga_readw_linear(uint32_t addr, void *p); -uint32_t svga_readl_linear(uint32_t addr, void *p); -void svga_write_linear(uint32_t addr, uint8_t val, void *p); -void svga_writeb_linear(uint32_t addr, uint8_t val, void *p); -void svga_writew_linear(uint32_t addr, uint16_t val, void *p); -void svga_writel_linear(uint32_t addr, uint32_t val, void *p); +uint8_t svga_read(uint32_t addr, void *priv); +uint16_t svga_readw(uint32_t addr, void *priv); +uint32_t svga_readl(uint32_t addr, void *priv); +void svga_write(uint32_t addr, uint8_t val, void *priv); +void svga_writew(uint32_t addr, uint16_t val, void *priv); +void svga_writel(uint32_t addr, uint32_t val, void *priv); +uint8_t svga_read_linear(uint32_t addr, void *priv); +uint8_t svga_readb_linear(uint32_t addr, void *priv); +uint16_t svga_readw_linear(uint32_t addr, void *priv); +uint32_t svga_readl_linear(uint32_t addr, void *priv); +void svga_write_linear(uint32_t addr, uint8_t val, void *priv); +void svga_writeb_linear(uint32_t addr, uint8_t val, void *priv); +void svga_writew_linear(uint32_t addr, uint16_t val, void *priv); +void svga_writel_linear(uint32_t addr, uint32_t val, void *priv); -void svga_add_status_info(char *s, int max_len, void *p); +void svga_add_status_info(char *s, int max_len, void *priv); extern uint8_t svga_rotate[8][256]; -void svga_out(uint16_t addr, uint8_t val, void *p); -uint8_t svga_in(uint16_t addr, void *p); +void svga_out(uint16_t addr, uint8_t val, void *priv); +uint8_t svga_in(uint16_t addr, void *priv); svga_t *svga_get_pri(void); void svga_set_override(svga_t *svga, int val); @@ -246,65 +334,65 @@ enum { /* We need a way to add a device with a pointer to a parent device so it can attach itself to it, and possibly also a second ATi 68860 RAM DAC type that auto-sets SVGA render on RAM DAC render change. */ -extern void ati68860_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga); -extern uint8_t ati68860_ramdac_in(uint16_t addr, void *p, svga_t *svga); -extern void ati68860_set_ramdac_type(void *p, int type); -extern void ati68860_ramdac_set_render(void *p, svga_t *svga); -extern void ati68860_ramdac_set_pallook(void *p, int i, uint32_t col); +extern void ati68860_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); +extern uint8_t ati68860_ramdac_in(uint16_t addr, void *priv, svga_t *svga); +extern void ati68860_set_ramdac_type(void *priv, int type); +extern void ati68860_ramdac_set_render(void *priv, svga_t *svga); +extern void ati68860_ramdac_set_pallook(void *priv, int i, uint32_t col); extern void ati68860_hwcursor_draw(svga_t *svga, int displine); -extern void att49x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t att49x_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); +extern void att49x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t att49x_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); -extern void att498_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t att498_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); -extern float av9194_getclock(int clock, void *p); +extern void att498_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t att498_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); +extern float av9194_getclock(int clock, void *priv); -extern void bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t *svga); -extern uint8_t bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga); -extern void bt48x_recalctimings(void *p, svga_t *svga); +extern void bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, svga_t *svga); +extern uint8_t bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga); +extern void bt48x_recalctimings(void *priv, svga_t *svga); extern void bt48x_hwcursor_draw(svga_t *svga, int displine); -extern void ibm_rgb528_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t ibm_rgb528_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); -extern void ibm_rgb528_recalctimings(void *p, svga_t *svga); +extern void ibm_rgb528_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t ibm_rgb528_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); +extern void ibm_rgb528_recalctimings(void *priv, svga_t *svga); extern void ibm_rgb528_hwcursor_draw(svga_t *svga, int displine); -extern void icd2061_write(void *p, int val); -extern float icd2061_getclock(int clock, void *p); +extern void icd2061_write(void *priv, int val); +extern float icd2061_getclock(int clock, void *priv); /* The code is the same, the #define's are so that the correct name can be used. */ # define ics9161_write icd2061_write # define ics9161_getclock icd2061_getclock -extern float ics2494_getclock(int clock, void *p); +extern float ics2494_getclock(int clock, void *priv); -extern void ics2595_write(void *p, int strobe, int dat); -extern double ics2595_getclock(void *p); -extern void ics2595_setclock(void *p, double clock); +extern void ics2595_write(void *priv, int strobe, int dat); +extern double ics2595_getclock(void *priv); +extern void ics2595_setclock(void *priv, double clock); -extern void sc1148x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t sc1148x_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); +extern void sc1148x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t sc1148x_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); -extern void sc1502x_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga); -extern uint8_t sc1502x_ramdac_in(uint16_t addr, void *p, svga_t *svga); +extern void sc1502x_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); +extern uint8_t sc1502x_ramdac_in(uint16_t addr, void *priv, svga_t *svga); -extern void sdac_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga); -extern uint8_t sdac_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga); -extern float sdac_getclock(int clock, void *p); +extern void sdac_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *priv, svga_t *svga); +extern uint8_t sdac_ramdac_in(uint16_t addr, int rs2, void *priv, svga_t *svga); +extern float sdac_getclock(int clock, void *priv); -extern void stg_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga); -extern uint8_t stg_ramdac_in(uint16_t addr, void *p, svga_t *svga); -extern float stg_getclock(int clock, void *p); +extern void stg_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); +extern uint8_t stg_ramdac_in(uint16_t addr, void *priv, svga_t *svga); +extern float stg_getclock(int clock, void *priv); -extern void tkd8001_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga); -extern uint8_t tkd8001_ramdac_in(uint16_t addr, void *p, svga_t *svga); +extern void tkd8001_ramdac_out(uint16_t addr, uint8_t val, void *priv, svga_t *svga); +extern uint8_t tkd8001_ramdac_in(uint16_t addr, void *priv, svga_t *svga); -extern void tvp3026_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t *svga); -extern uint8_t tvp3026_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga); -extern void tvp3026_recalctimings(void *p, svga_t *svga); +extern void tvp3026_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *priv, svga_t *svga); +extern uint8_t tvp3026_ramdac_in(uint16_t addr, int rs2, int rs3, void *priv, svga_t *svga); +extern void tvp3026_recalctimings(void *priv, svga_t *svga); extern void tvp3026_hwcursor_draw(svga_t *svga, int displine); -extern float tvp3026_getclock(int clock, void *p); +extern float tvp3026_getclock(int clock, void *priv); # ifdef EMU_DEVICE_H extern const device_t ati68860_ramdac_device; diff --git a/src/include/86box/vid_svga_render.h b/src/include/86box/vid_svga_render.h index 13ff527e0..1f587d4f5 100644 --- a/src/include/86box/vid_svga_render.h +++ b/src/include/86box/vid_svga_render.h @@ -20,12 +20,16 @@ #ifndef VIDEO_SVGA_RENDER_H #define VIDEO_SVGA_RENDER_H -extern int firstline_draw, lastline_draw; +extern int firstline_draw; +extern int lastline_draw; extern int displine; extern int sc; -extern uint32_t ma, ca; -extern int con, cursoron, cgablink; +extern uint32_t ma; +extern uint32_t ca; +extern int con; +extern int cursoron; +extern int cgablink; extern int scrollcache; diff --git a/src/include/86box/vid_vga.h b/src/include/86box/vid_vga.h index 08a1a2591..bc552b285 100644 --- a/src/include/86box/vid_vga.h +++ b/src/include/86box/vid_vga.h @@ -30,7 +30,7 @@ typedef struct vga_t { static video_timings_t timing_vga = { VIDEO_ISA, 8, 16, 32, 8, 16, 32 }; -void vga_out(uint16_t addr, uint8_t val, void *p); -uint8_t vga_in(uint16_t addr, void *p); +void vga_out(uint16_t addr, uint8_t val, void *priv); +uint8_t vga_in(uint16_t addr, void *priv); #endif /*VIDEO_VGA_H*/ diff --git a/src/include/86box/vid_voodoo_banshee.h b/src/include/86box/vid_voodoo_banshee.h index 56fd47eeb..89298e94e 100644 --- a/src/include/86box/vid_voodoo_banshee.h +++ b/src/include/86box/vid_voodoo_banshee.h @@ -18,6 +18,6 @@ #ifndef VIDEO_VOODOO_BANSHEE_H #define VIDEO_VOODOO_BANSHEE_H -void banshee_set_overlay_addr(void *p, uint32_t addr); +void banshee_set_overlay_addr(void *priv, uint32_t addr); #endif /*VIDEO_VOODOO_BANSHEE_H*/ diff --git a/src/include/86box/vid_voodoo_codegen_x86-64.h b/src/include/86box/vid_voodoo_codegen_x86-64.h index b50d3332a..dc0ebce72 100644 --- a/src/include/86box/vid_voodoo_codegen_x86-64.h +++ b/src/include/86box/vid_voodoo_codegen_x86-64.h @@ -38,7 +38,9 @@ typedef struct voodoo_x86_data_t { int is_tiled; } voodoo_x86_data_t; -// static voodoo_x86_data_t voodoo_x86_data[2][BLOCK_NUM]; +#if 0 +static voodoo_x86_data_t voodoo_x86_data[2][BLOCK_NUM]; +#endif static int last_block[4] = { 0, 0 }; static int next_block_to_write[4] = { 0, 0 }; @@ -234,10 +236,12 @@ codegen_texture_fetch(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *pa addlong(1); addbyte(0x28); /*SUB DL, CL*/ addbyte(0xca); - // addbyte(0x8a); /*MOV DL, params->tex_shift[RSI+ECX*4]*/ - // addbyte(0x94); - // addbyte(0x8e); - // addlong(offsetof(voodoo_params_t, tex_shift)); +#if 0 + addbyte(0x8a); /*MOV DL, params->tex_shift[RSI+ECX*4]*/ + addbyte(0x94); + addbyte(0x8e); + addlong(offsetof(voodoo_params_t, tex_shift)); +#endif addbyte(0xd3); /*SHL EBP, CL*/ addbyte(0xe5); addbyte(0x8b); /*MOV EAX, state->tex_s[RDI]*/ @@ -656,24 +660,29 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, int depth_jump_pos = 0; int depth_jump_pos2 = 0; int loop_jump_pos = 0; - // xmm_01_w = (__m128i)0x0001000100010001ull; - // xmm_ff_w = (__m128i)0x00ff00ff00ff00ffull; - // xmm_ff_b = (__m128i)0x00000000ffffffffull; +#if 0 + xmm_01_w = (__m128i)0x0001000100010001ull; + xmm_ff_w = (__m128i)0x00ff00ff00ff00ffull; + xmm_ff_b = (__m128i)0x00000000ffffffffull; +#endif xmm_01_w = _mm_set_epi32(0, 0, 0x00010001, 0x00010001); xmm_ff_w = _mm_set_epi32(0, 0, 0x00ff00ff, 0x00ff00ff); xmm_ff_b = _mm_set_epi32(0, 0, 0, 0x00ffffff); minus_254 = _mm_set_epi32(0, 0, 0xff02ff02, 0xff02ff02); - // *(uint64_t *)&const_1_48 = 0x45b0000000000000ull; - // block_pos = 0; - // voodoo_get_depth = &code_block[block_pos]; +#if 0 + *(uint64_t *)&const_1_48 = 0x45b0000000000000ull; + block_pos = 0; + voodoo_get_depth = &code_block[block_pos]; +#endif /*W at (%esp+4) Z at (%esp+12) new_depth at (%esp+16)*/ - // if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depth_op == DEPTHOP_NEVER)) - // { - // addbyte(0xC3); /*RET*/ - // return; - // } +#if 0 + if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depth_op == DEPTHOP_NEVER)) { + addbyte(0xC3); /*RET*/ + return; + } +#endif addbyte(0x55); /*PUSH RBP*/ addbyte(0x57); /*PUSH RDI*/ addbyte(0x56); /*PUSH RSI*/ @@ -796,7 +805,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x75); /*JNZ got_depth*/ depth_jump_pos = block_pos; addbyte(0); - // addbyte(4+5+2+3+2+5+5+3+2+2+2+/*3+*/3+2+6+4+5+2+3); +#if 0 + addbyte(4+5+2+3+2+5+5+3+2+2+2+/*3+*/3+2+6+4+5+2+3); +#endif addbyte(0x8b); /*MOV EDX, w*/ addbyte(0x97); addlong(offsetof(voodoo_state_t, w)); @@ -810,7 +821,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x74); /*JZ got_depth*/ depth_jump_pos2 = block_pos; addbyte(0); - // addbyte(5+5+3+2+2+2+/*3+*/3+2+6+4+5+2+3); +#if 0 + addbyte(5+5+3+2+2+2+/*3+*/3+2+6+4+5+2+3); +#endif addbyte(0xb9); /*MOV ECX, 19*/ addlong(19); addbyte(0x0f); /*BSR EAX, EDX*/ @@ -2224,10 +2237,12 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(10); addbyte(0x01); /*ADD EAX, EBX*/ addbyte(0xd8); - /* int fog_idx = (w_depth >> 10) & 0x3f; +#if 0 + int fog_idx = (w_depth >> 10) & 0x3f; - fog_a = params->fogTable[fog_idx].fog; - fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10;*/ + fog_a = params->fogTable[fog_idx].fog; + fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10; +#endif break; case FOG_Z: @@ -2239,7 +2254,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(12); addbyte(0x25); /*AND EAX, 0xff*/ addlong(0xff); - // fog_a = (z >> 20) & 0xff; +#if 0 + fog_a = (z >> 20) & 0xff; +#endif break; case FOG_ALPHA: @@ -2261,7 +2278,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); /*CMOVAE EAX, EBX*/ addbyte(0x43); addbyte(0xc3); - // fog_a = CLAMP(ia >> 12); +#if 0 + fog_a = CLAMP(ia >> 12); +#endif break; case FOG_W: @@ -2282,7 +2301,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); /*CMOVAE EAX, EBX*/ addbyte(0x43); addbyte(0xc3); - // fog_a = CLAMP(w >> 32); +#if 0 + fog_a = CLAMP(w >> 32); +#endif break; } addbyte(0x01); /*ADD EAX, EAX*/ @@ -3164,12 +3185,11 @@ int voodoo_recomp = 0; static inline void * voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *state, int odd_even) { - int c; int b = last_block[odd_even]; voodoo_x86_data_t *voodoo_x86_data = voodoo->codegen_data; voodoo_x86_data_t *data; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { data = &voodoo_x86_data[odd_even + c * 4]; //&voodoo_x86_data[odd_even][b]; if (state->xdir == data->xdir && params->alphaMode == data->alphaMode && params->fbzMode == data->fbzMode && params->fogMode == data->fogMode && params->fbzColorPath == data->fbzColorPath && (voodoo->trexInit1[0] & (1 << 18)) == data->trexInit1 && params->textureMode[0] == data->textureMode[0] && params->textureMode[1] == data->textureMode[1] && (params->tLOD[0] & LOD_MASK) == data->tLOD[0] && (params->tLOD[1] & LOD_MASK) == data->tLOD[1] && ((params->col_tiled || params->aux_tiled) ? 1 : 0) == data->is_tiled) { @@ -3181,7 +3201,9 @@ voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat } voodoo_recomp++; data = &voodoo_x86_data[odd_even + next_block_to_write[odd_even] * 4]; - // code_block = data->code_block; +#if 0 + code_block = data->code_block; +#endif voodoo_generate(data->code_block, voodoo, params, state, depth_op); @@ -3205,11 +3227,9 @@ voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat void voodoo_codegen_init(voodoo_t *voodoo) { - int c; - voodoo->codegen_data = plat_mmap(sizeof(voodoo_x86_data_t) * BLOCK_NUM * 4, 1); - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { int d[4]; int _ds = c & 0xf; int dt = c >> 4; diff --git a/src/include/86box/vid_voodoo_codegen_x86.h b/src/include/86box/vid_voodoo_codegen_x86.h index 9454c9bff..996bd28f1 100644 --- a/src/include/86box/vid_voodoo_codegen_x86.h +++ b/src/include/86box/vid_voodoo_codegen_x86.h @@ -639,24 +639,29 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, int depth_jump_pos = 0; int depth_jump_pos2 = 0; int loop_jump_pos = 0; - // xmm_01_w = (__m128i)0x0001000100010001ull; - // xmm_ff_w = (__m128i)0x00ff00ff00ff00ffull; - // xmm_ff_b = (__m128i)0x00000000ffffffffull; +#if 0 + xmm_01_w = (__m128i)0x0001000100010001ull; + xmm_ff_w = (__m128i)0x00ff00ff00ff00ffull; + xmm_ff_b = (__m128i)0x00000000ffffffffull; +#endif xmm_01_w = _mm_set_epi32(0, 0, 0x00010001, 0x00010001); xmm_ff_w = _mm_set_epi32(0, 0, 0x00ff00ff, 0x00ff00ff); xmm_ff_b = _mm_set_epi32(0, 0, 0, 0x00ffffff); minus_254 = _mm_set_epi32(0, 0, 0xff02ff02, 0xff02ff02); - // *(uint64_t *)&const_1_48 = 0x45b0000000000000ull; - // block_pos = 0; - // voodoo_get_depth = &code_block[block_pos]; +#if 0 + *(uint64_t *)&const_1_48 = 0x45b0000000000000ull; + block_pos = 0; + voodoo_get_depth = &code_block[block_pos]; +#endif /*W at (%esp+4) Z at (%esp+12) new_depth at (%esp+16)*/ - // if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depth_op == DEPTHOP_NEVER)) - // { - // addbyte(0xC3); /*RET*/ - // return; - // } +#if 0 + if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depth_op == DEPTHOP_NEVER)) { + addbyte(0xC3); /*RET*/ + return; + } +#endif addbyte(0x55); /*PUSH EBP*/ addbyte(0x57); /*PUSH EDI*/ addbyte(0x56); /*PUSH ESI*/ @@ -871,16 +876,19 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, fatal("Bad depth_op\n"); } else if ((params->fbzMode & FBZ_DEPTH_ENABLE) && (depthop == DEPTHOP_NEVER)) { addbyte(0xC3); /*RET*/ - // addbyte(0x30); /*XOR EAX, EAX*/ - // addbyte(0xc0); +#if 0 + addbyte(0x30); /*XOR EAX, EAX*/ + addbyte(0xc0); +#endif + } +#if 0 + else { + addbyte(0xb0); /*MOV AL, 1*/ + addbyte(1); } - // else - // { - // addbyte(0xb0); /*MOV AL, 1*/ - // addbyte(1); - // } - // voodoo_combine = &code_block[block_pos]; + voodoo_combine = &code_block[block_pos]; +#endif /*XMM0 = colour*/ /*XMM2 = 0 (for unpacking*/ @@ -2076,12 +2084,13 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x05); addlong((uint32_t) &xmm_ff_b); } - // #if 0 - // addbyte(0x66); /*MOVD state->out[EDI], XMM0*/ - // addbyte(0x0f); - // addbyte(0x7e); - // addbyte(0x87); - // addlong(offsetof(voodoo_state_t, out)); +#if 0 + addbyte(0x66); /*MOVD state->out[EDI], XMM0*/ + addbyte(0x0f); + addbyte(0x7e); + addbyte(0x87); + addlong(offsetof(voodoo_state_t, out)); +#endif if (params->fogMode & FOG_ENABLE) { if (params->fogMode & FOG_CONSTANT) { addbyte(0x66); /*MOVD XMM3, params->fogColor[ESI]*/ @@ -2093,11 +2102,18 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); addbyte(0xdc); addbyte(0xc3); - /* src_r += params->fogColor.r; - src_g += params->fogColor.g; - src_b += params->fogColor.b; */ +#if 0 + src_r += params->fogColor.r; + src_g += params->fogColor.g; + src_b += params->fogColor.b; */ +#endif } else { - /*int fog_r, fog_g, fog_b, fog_a; */ +#if 0 + int fog_r; + int fog_g; + int fog_b; + int fog_a; +#endif addbyte(0x66); /*PUNPCKLBW XMM0, XMM2*/ addbyte(0x0f); @@ -2168,10 +2184,12 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x01); /*ADD EAX, EBX*/ addbyte(0xd8); - /* int fog_idx = (w_depth >> 10) & 0x3f; +#if 0 + int fog_idx = (w_depth >> 10) & 0x3f; - fog_a = params->fogTable[fog_idx].fog; - fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10;*/ + fog_a = params->fogTable[fog_idx].fog; + fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10; +#endif break; case FOG_Z: @@ -2183,7 +2201,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(12); addbyte(0x25); /*AND EAX, 0xff*/ addlong(0xff); - // fog_a = (z >> 20) & 0xff; +#if 0 + fog_a = (z >> 20) & 0xff; +#endif break; case FOG_ALPHA: @@ -2205,7 +2225,9 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); /*CMOVAE EAX, EBX*/ addbyte(0x43); addbyte(0xc3); - // fog_a = CLAMP(ia >> 12); +#if 0 + fog_a = CLAMP(ia >> 12); +#endif break; case FOG_W: @@ -2226,13 +2248,16 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); /*CMOVAE EAX, EBX*/ addbyte(0x43); addbyte(0xc3); - // fog_a = CLAMP(w >> 32); +#if 0 + fog_a = CLAMP(w >> 32); +#endif break; } addbyte(0x01); /*ADD EAX, EAX*/ addbyte(0xc0); - // fog_a++; - +#if 0 + fog_a++; +#endif addbyte(0x66); /*PMULLW XMM3, alookup+4[EAX*8]*/ addbyte(0x0f); addbyte(0xd5); @@ -2244,9 +2269,11 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x71); addbyte(0xe3); addbyte(7); - /* fog_r = (fog_r * fog_a) >> 8; - fog_g = (fog_g * fog_a) >> 8; - fog_b = (fog_b * fog_a) >> 8;*/ +#if 0 + fog_r = (fog_r * fog_a) >> 8; + fog_g = (fog_g * fog_a) >> 8; + fog_b = (fog_b * fog_a) >> 8; +#endif if (params->fogMode & FOG_MULT) { addbyte(0xf3); /*MOV XMM0, XMM3*/ @@ -2258,9 +2285,11 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x0f); addbyte(0xfd); addbyte(0xc3); - /* src_r += fog_r; - src_g += fog_g; - src_b += fog_b;*/ +#if 0 + src_r += fog_r; + src_g += fog_g; + src_b += fog_b; +#endif } addbyte(0x66); /*PACKUSWB XMM0, XMM0*/ addbyte(0x0f); @@ -2268,9 +2297,11 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0xc0); } - /* src_r = CLAMP(src_r); - src_g = CLAMP(src_g); - src_b = CLAMP(src_b);*/ +#if 0 + src_r = CLAMP(src_r); + src_g = CLAMP(src_g); + src_b = CLAMP(src_b); +#endif } if ((params->alphaMode & 1) && (alpha_func != AFUNC_NEVER) && (alpha_func != AFUNC_ALWAYS)) { @@ -2696,12 +2727,13 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0x67); addbyte(0xc0); } - // #endif - // addbyte(0x8b); /*MOV EDX, x (ESP+12)*/ - // addbyte(0x54); - // addbyte(0x24); - // addbyte(12); +#if 0 + addbyte(0x8b); /*MOV EDX, x (ESP+12)*/ + addbyte(0x54); + addbyte(0x24); + addbyte(12); +#endif addbyte(0x8b); /*MOV EDX, state->x[EDI]*/ addbyte(0x97); @@ -2716,9 +2748,11 @@ voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo_params_t *params, addbyte(0xc0); if (params->fbzMode & FBZ_RGB_WMASK) { - // addbyte(0x89); /*MOV state->rgb_out[EDI], EAX*/ - // addbyte(0x87); - // addlong(offsetof(voodoo_state_t, rgb_out)); +#if 0 + addbyte(0x89); /*MOV state->rgb_out[EDI], EAX*/ + addbyte(0x87); + addlong(offsetof(voodoo_state_t, rgb_out)); +#endif if (dither) { addbyte(0x8b); /*MOV ESI, real_y (ESP+16)*/ @@ -3118,7 +3152,9 @@ voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat } voodoo_recomp++; data = &codegen_data[odd_even + next_block_to_write[odd_even] * 4]; - // code_block = data->code_block; +#if 0 + code_block = data->code_block; +#endif voodoo_generate(data->code_block, voodoo, params, state, depth_op); @@ -3142,11 +3178,9 @@ voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *stat void voodoo_codegen_init(voodoo_t *voodoo) { - int c; - voodoo->codegen_data = plat_mmap(sizeof(voodoo_x86_data_t) * BLOCK_NUM * 4, 1); - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { int d[4]; int _ds = c & 0xf; int dt = c >> 4; diff --git a/src/include/86box/vid_voodoo_common.h b/src/include/86box/vid_voodoo_common.h index 6eae0bf6d..92c608789 100644 --- a/src/include/86box/vid_voodoo_common.h +++ b/src/include/86box/vid_voodoo_common.h @@ -596,7 +596,9 @@ typedef struct voodoo_t { uint32_t vidOverlayDudxOffsetSrcWidth; uint32_t vidOverlayDvdy; uint32_t vidOverlayDvdyOffset; - // uint32_t vidDesktopOverlayStride; +#if 0 + uint32_t vidDesktopOverlayStride; +#endif int start_x; int start_y; diff --git a/src/include/86box/vid_xga.h b/src/include/86box/vid_xga.h index 550ae7cd6..b022aff28 100644 --- a/src/include/86box/vid_xga.h +++ b/src/include/86box/vid_xga.h @@ -20,7 +20,7 @@ #include <86box/rom.h> -typedef struct { +typedef struct xga_hwcursor_t { int ena; int x; int y; @@ -36,12 +36,15 @@ typedef struct xga_t { mem_mapping_t linear_mapping; mem_mapping_t video_mapping; rom_t bios_rom; - rom_t vga_bios_rom; - xga_hwcursor_t hwcursor, hwcursor_latch; + rom_t vga_bios_rom; + xga_hwcursor_t hwcursor; + xga_hwcursor_t hwcursor_latch; PALETTE extpal; - uint8_t test, atest[2], testpixel; - ; + uint8_t test; + uint8_t atest[2]; + uint8_t testpixel; + uint8_t pos_regs[8]; uint8_t disp_addr; uint8_t cfg_reg; @@ -54,33 +57,44 @@ typedef struct xga_t { uint8_t regs_idx; uint8_t hwc_hotspot_x; uint8_t hwc_hotspot_y; - uint8_t disp_cntl_1, disp_cntl_2; - uint8_t clk_sel_1, clk_sel_2; + uint8_t disp_cntl_1; + uint8_t disp_cntl_2; + uint8_t clk_sel_1; + uint8_t clk_sel_2; uint8_t hwc_control; uint8_t bus_arb; uint8_t isa_pos_enable; uint8_t hwcursor_oddeven; uint8_t cfg_reg_instance; uint8_t rowcount; - uint8_t pal_idx, pal_idx_prefetch; + uint8_t pal_idx; + uint8_t pal_idx_prefetch; uint8_t pal_seq; uint8_t pal_mask; - uint8_t pal_r, pal_r_prefetch; - uint8_t pal_g, pal_g_prefetch; - uint8_t pal_b, pal_b_prefetch; + uint8_t pal_r; + uint8_t pal_r_prefetch; + uint8_t pal_g; + uint8_t pal_g_prefetch; + uint8_t pal_b; + uint8_t pal_b_prefetch; uint8_t sprite_data[1024]; uint8_t scrollcache; + uint8_t border_color; uint8_t direct_color; uint8_t dma_channel; - uint8_t instance_isa, instance_num, ext_mem_addr; - uint8_t *vram, *changedvram; + uint8_t instance_isa; + uint8_t instance_num; + uint8_t ext_mem_addr; + uint8_t *vram; + uint8_t *changedvram; int16_t hwc_pos_x; int16_t hwc_pos_y; uint16_t pos_idx; uint16_t htotal; - uint16_t sprite_idx, sprite_idx_prefetch; + uint16_t sprite_idx; + uint16_t sprite_idx_prefetch; uint16_t hdisp; uint16_t vtotal; uint16_t vdispend; @@ -88,41 +102,74 @@ typedef struct xga_t { uint16_t vsyncstart; uint16_t linecmp; uint16_t pix_map_width; - uint16_t sprite_pal_addr_idx, old_pal_addr_idx; + uint16_t sprite_pal_addr_idx; + uint16_t old_pal_addr_idx; uint16_t sprite_pal_addr_idx_prefetch; - int v_total, dispend, v_syncstart, split, v_blankstart, - h_disp, h_disp_old, h_total, h_disp_time, rowoffset, - dispon, h_disp_on, vc, sc, linepos, oddeven, firstline, lastline, - firstline_draw, lastline_draw, displine, fullchange, interlace, - char_width, hwcursor_on; - int pal_pos, pal_pos_prefetch; + int v_total; + int dispend; + int v_syncstart; + int split; + int v_blankstart; + int h_disp; + int h_disp_old; + int h_total; + int h_disp_time; + int rowoffset; + int dispon; + int h_disp_on; + int vc; + int sc; + int linepos; + int oddeven; + int firstline; + int lastline; + int firstline_draw; + int lastline_draw; + int displine; + int fullchange; + int interlace; + int char_width; + int hwcursor_on; + int pal_pos; + int pal_pos_prefetch; int on; - int op_mode_reset, linear_endian_reverse; - int sprite_pos, sprite_pos_prefetch, cursor_data_on; - int pal_test, a5_test; - int type, bus; + int op_mode_reset; + int linear_endian_reverse; + int sprite_pos; + int sprite_pos_prefetch; + int cursor_data_on; + int pal_test; + int a5_test; + int type; + int bus; - uint32_t linear_base, linear_size, banked_mask; + uint32_t linear_base; + uint32_t linear_size; + uint32_t banked_mask; uint32_t base_addr_1mb; - uint32_t hwc_color0, hwc_color1; + uint32_t hwc_color0; + uint32_t hwc_color1; uint32_t disp_start_addr; uint32_t ma_latch; uint32_t vram_size; uint32_t vram_mask; uint32_t rom_addr; - uint32_t ma, maback; + uint32_t ma; + uint32_t maback; uint32_t extpallook[256]; - uint32_t read_bank, write_bank; + uint32_t read_bank; + uint32_t write_bank; uint32_t px_map_base; - uint64_t dispontime, dispofftime; + uint64_t dispontime; + uint64_t dispofftime; - struct - { + struct { uint8_t control; uint8_t px_map_idx; - uint8_t frgd_mix, bkgd_mix; + uint8_t frgd_mix; + uint8_t bkgd_mix; uint8_t cc_cond; uint8_t octant; uint8_t draw_mode; @@ -133,15 +180,19 @@ typedef struct xga_t { uint8_t short_stroke_vector4; int16_t bres_err_term; - int16_t bres_k1, bres_k2; + int16_t bres_k1; + int16_t bres_k2; uint16_t blt_width; uint16_t blt_height; uint16_t mask_map_origin_x_off; uint16_t mask_map_origin_y_off; - uint16_t src_map_x, src_map_y; - uint16_t dst_map_x, dst_map_y; - uint16_t pat_map_x, pat_map_y; + uint16_t src_map_x; + uint16_t src_map_y; + uint16_t dst_map_x; + uint16_t dst_map_y; + uint16_t pat_map_x; + uint16_t pat_map_y; int ssv_state; int pat_src; @@ -149,7 +200,14 @@ typedef struct xga_t { int dst_map; int bkgd_src; int fore_src; - int x, y, sx, sy, dx, dy, px, py; + int x; + int y; + int sx; + int sy; + int dx; + int dy; + int px; + int py; int pattern; int command_len; @@ -157,7 +215,8 @@ typedef struct xga_t { uint32_t color_cmp; uint32_t carry_chain; uint32_t plane_mask; - uint32_t frgd_color, bkgd_color; + uint32_t frgd_color; + uint32_t bkgd_color; uint32_t command; uint32_t dir_cmd; @@ -167,6 +226,6 @@ typedef struct xga_t { uint32_t px_map_base[4]; } accel; - volatile int force_busy; + int big_endian_linear; } xga_t; #endif /*VIDEO_XGA_H*/ diff --git a/src/include/tinyglib.h b/src/include/tinyglib.h deleted file mode 100644 index 9edd5986a..000000000 --- a/src/include/tinyglib.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Minimal reimplementation of GLib for libslirp. - * - * - * - * Authors: RichardG, - * - * Copyright 2020 RichardG. - */ -#ifndef TINYGLIB_H -#define TINYGLIB_H - -/* Define this to bypass TinyGLib and use full GLib instead. */ -#ifdef TINYGLIB_USE_GLIB -# include -#else - -# include -# include -# include -# include -# define HAVE_STDARG_H -# include <86box/86box.h> - -/* Definitions */ - -# define G_LITTLE_ENDIAN 1234 -# define G_BIG_ENDIAN 4321 -# define G_PDP_ENDIAN 3412 -# ifdef __BYTE_ORDER__ -# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -# define G_BYTE_ORDER G_LITTLE_ENDIAN -# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define G_BYTE_ORDER G_BIG_ENDIAN -# elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ -# define G_BYTE_ORDER G_PDP_ENDIAN -# endif -# endif -# ifndef G_BYTE_ORDER -/* Safe to assume LE for MSVC, as Windows is LE on all architectures. */ -# define G_BYTE_ORDER G_LITTLE_ENDIAN -# endif - -# ifdef _WIN32 -# define G_OS_WIN32 1 -# else -# define G_OS_UNIX 1 -# endif - -# define G_SPAWN_SEARCH_PATH 0 - -# if defined(__LP64__) || defined(__LLP64__) || defined(_WIN64) -# define GLIB_SIZEOF_VOID_P 8 -# if defined(__LLP64__) || defined(_WIN64) -# define GLIB_SIZEOF_LONG 4 -# else -# define GLIB_SIZEOF_LONG 8 -# endif -# define GLIB_SIZEOF_SIZE_T 8 -# define GLIB_SIZEOF_SSIZE_T 8 -# else -# define GLIB_SIZEOF_VOID_P 4 -# define GLIB_SIZEOF_LONG 4 -# define GLIB_SIZEOF_SIZE_T 4 -# define GLIB_SIZEOF_SSIZE_T 4 -# endif - -/* Types */ - -/* Windows does not define ssize_t, so we need to define it here. */ -# ifndef _SSIZE_T_DEFINED -# define _SSIZE_T_DEFINED -# undef ssize_t -# ifdef _WIN64 -# define ssize_t int64_t -# else -# define ssize_t int32_t -# endif -# endif - -# define gboolean int -# define gchar char -# define gint int -# define gint16 int16_t -# define gint32 int32_t -# define gint64 int64_t -# define glong long -# define GPid void * -# define gpointer void * -# define gsize size_t -# define GSpawnFlags void * -# define GSpawnChildSetupFunc void * -# define gssize ssize_t -# define GString char -# define GStrv char ** -# define guint unsigned int -# define guint16 uint16_t -# define guint32 uint32_t -# define guint64 uint64_t - -typedef struct _GDebugKey { - char key[32]; - int val; -} GDebugKey; - -typedef struct _GError { - char message[1]; -} GError; - -typedef struct _GRand { - uint8_t dummy; -} GRand; - -/* Functions */ -extern gboolean g_spawn_async_with_fds(const gchar *working_directory, gchar **argv, - gchar **envp, GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, GPid *child_pid, gint stdin_fd, - gint stdout_fd, gint stderr_fd, GError **error); -extern gboolean g_str_has_prefix (const gchar *str, - const gchar *prefix); -extern GString *g_string_new(gchar *base); -extern gchar *g_string_free(GString *string, gboolean free_segment); -extern gchar *g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle); -extern guint g_strv_length(gchar **str_array); - -/* Macros */ -# define tinyglib_pclog(f, s, ...) pclog("TinyGLib " f "(): " s "\n", ##__VA_ARGS__) - -# define GLIB_CHECK_VERSION(a, b, c) 1 -# ifdef __GNUC__ -# define G_GNUC_PRINTF(format_idx, arg_idx) __attribute__((__format__(__printf__, format_idx, arg_idx))) -# else -# define G_GNUC_PRINTF(format_idx, arg_idx) -# endif -# define G_N_ELEMENTS(arr) (sizeof(arr) / sizeof((arr)[0])) -# define G_STATIC_ASSERT(e) /* this should probably do something */ -# define G_UNLIKELY(e) (e) - -# define g_assert(e) \ - do { \ - if (!(e)) \ - fatal("TinyGLib g_assert(" #e ")\n"); \ - } while (0) -# ifdef __GNUC__ -# define g_assert_not_reached __builtin_unreachable -# else -# ifdef _MSC_VER -# define g_assert_not_reached() __assume(0) -# else -# define g_assert_not_reached() -# endif -# endif -# define g_critical(s, ...) fatal("TinyGLib g_critical(): " s "\n", ##__VA_ARGS__) -# ifdef TINYGLIB_DEBUG -# define g_debug(s, ...) tinyglib_pclog("g_debug", s, ##__VA_ARGS__) -# else -# define g_debug(s, ...) -# endif -# define g_error(s, ...) tinyglib_pclog("g_error", s, ##__VA_ARGS__) -# define g_error_free(err) -# define g_malloc0(s) calloc(1, s) -# define g_new(t, n) (t *) malloc(sizeof(t) * n) -# define g_new0(t, n) (t *) calloc(n, sizeof(t)) -# ifdef TINYGLIB_DEBUG -# define g_parse_debug_string(s, k, n) ((!!sizeof(k)) * -1) /* unimplemented; always enables all debug flags */ -# else -# define g_parse_debug_string(s, k, n) (!sizeof(k)) -# endif -# define g_rand_int_range(r, min, max) (rand() % (max + 1 - min) + min) -# define g_rand_new() calloc(1, sizeof(GRand)) -# define g_return_val_if_fail(e, v) \ - if (!(e)) \ - return (v) -# define g_shell_parse_argv(a, b, c, d) !!(sizeof(b)) /* unimplemented */ -# define g_strdup(str) ((str) ? strdup(str) : NULL) -# define g_warn_if_fail(e) \ - do { \ - if (!(e)) \ - pclog("TinyGLib g_warn_if_fail(" #e ")\n"); \ - } while (0) -# define g_warn_if_reached() pclog("TinyGLib g_warn_if_reached()\n") -# define g_warning(s, ...) tinyglib_pclog("g_warning", s, ##__VA_ARGS__) - -/* Remapped functions */ -# define g_free free -# define g_getenv getenv -# define g_malloc malloc -# define g_rand_free free -# define g_realloc realloc -# define g_snprintf snprintf -# define g_strerror strerror -# define g_strfreev free -# define g_string_append_printf sprintf /* unimplemented */ -# define g_vsnprintf vsnprintf - -#endif - -#endif diff --git a/src/ini.c b/src/ini.c index 4ea2b6477..29f8e05fb 100644 --- a/src/ini.c +++ b/src/ini.c @@ -544,9 +544,9 @@ ini_section_delete_var(ini_section_t self, const char *name) int ini_section_get_int(ini_section_t self, const char *name, int def) { - section_t *section = (section_t *) self; - entry_t *entry; - int value; + section_t *section = (section_t *) self; + const entry_t *entry; + int value; if (section == NULL) return def; @@ -563,9 +563,9 @@ ini_section_get_int(ini_section_t self, const char *name, int def) double ini_section_get_double(ini_section_t self, const char *name, double def) { - section_t *section = (section_t *) self; - entry_t *entry; - double value; + section_t *section = (section_t *) self; + const entry_t *entry; + double value; if (section == NULL) return def; @@ -582,9 +582,9 @@ ini_section_get_double(ini_section_t self, const char *name, double def) int ini_section_get_hex16(ini_section_t self, const char *name, int def) { - section_t *section = (section_t *) self; - entry_t *entry; - unsigned int value; + section_t *section = (section_t *) self; + const entry_t *entry; + unsigned int value; if (section == NULL) return def; @@ -601,9 +601,9 @@ ini_section_get_hex16(ini_section_t self, const char *name, int def) int ini_section_get_hex20(ini_section_t self, const char *name, int def) { - section_t *section = (section_t *) self; - entry_t *entry; - unsigned int value; + section_t *section = (section_t *) self; + const entry_t *entry; + unsigned int value; if (section == NULL) return def; @@ -620,11 +620,11 @@ ini_section_get_hex20(ini_section_t self, const char *name, int def) int ini_section_get_mac(ini_section_t self, const char *name, int def) { - section_t *section = (section_t *) self; - entry_t *entry; - unsigned int val0 = 0; - unsigned int val1 = 0; - unsigned int val2 = 0; + section_t *section = (section_t *) self; + const entry_t *entry; + unsigned int val0 = 0; + unsigned int val1 = 0; + unsigned int val2 = 0; if (section == NULL) return def; diff --git a/src/lpt.c b/src/lpt.c index f4fc7192f..7eb96a278 100644 --- a/src/lpt.c +++ b/src/lpt.c @@ -168,7 +168,7 @@ lpt_read(uint16_t port, void *priv) void lpt_irq(void *priv, int raise) { - lpt_port_t *dev = (lpt_port_t *) priv; + const lpt_port_t *dev = (lpt_port_t *) priv; if (dev->enable_irq && (dev->irq != 0xff)) { if (raise) diff --git a/src/machine/m_amstrad.c b/src/machine/m_amstrad.c index 17caf6141..543ebfc11 100644 --- a/src/machine/m_amstrad.c +++ b/src/machine/m_amstrad.c @@ -74,6 +74,7 @@ #include <86box/vid_mda.h> #include <86box/machine.h> #include <86box/m_amstrad.h> +#include <86box/plat_unused.h> #define STAT_PARITY 0x80 #define STAT_RTIMEOUT 0x40 @@ -84,60 +85,64 @@ #define STAT_IFULL 0x02 #define STAT_OFULL 0x01 -typedef struct { - rom_t bios_rom; /* 1640 */ - cga_t cga; /* 1640/200 */ - mda_t mda; /* 1512/200/PPC512/640*/ - ega_t ega; /* 1640 */ - uint8_t emulation; /* Which display are we emulating? */ - uint8_t dipswitches; /* DIP switches 1-3 */ - uint8_t crtc_index; /* CRTC index readback - * Bit 7: CGA control port written - * Bit 6: Operation control port written - * Bit 5: CRTC register written - * Bits 0-4: Last CRTC register selected */ - uint8_t operation_ctrl; - uint8_t reg_3df, type; - uint8_t crtc[32]; - int crtcreg; - int cga_enabled; /* 1640 */ - uint8_t cgacol, - cgamode, - stat; - uint8_t plane_write, /* 1512/200 */ - plane_read, /* 1512/200 */ - border, /* 1512/200 */ - invert; /* 512/640 */ - int fontbase; /* 1512/200 */ - int linepos, - displine; - int sc, vc; - int cgadispon; - int con, coff, - cursoron, - cgablink; - int vsynctime; - int fullchange; - int vadj; - uint16_t ma, maback; - int dispon; - int blink; - uint64_t dispontime, /* 1512/1640 */ - dispofftime; /* 1512/1640 */ - pc_timer_t timer; /* 1512/1640 */ - int firstline, - lastline; - uint8_t *vram; - void *ams; +typedef struct amsvid_t { + rom_t bios_rom; /* 1640 */ + cga_t cga; /* 1640/200 */ + mda_t mda; /* 1512/200/PPC512/640*/ + ega_t ega; /* 1640 */ + uint8_t emulation; /* Which display are we emulating? */ + uint8_t dipswitches; /* DIP switches 1-3 */ + uint8_t crtc_index; /* CRTC index readback + * Bit 7: CGA control port written + * Bit 6: Operation control port written + * Bit 5: CRTC register written + * Bits 0-4: Last CRTC register selected */ + uint8_t operation_ctrl; + uint8_t reg_3df; + uint8_t type; + uint8_t crtc[32]; + int crtcreg; + int cga_enabled; /* 1640 */ + uint8_t cgacol; + uint8_t cgamode; + uint8_t stat; + uint8_t plane_write; /* 1512/200 */ + uint8_t plane_read; /* 1512/200 */ + uint8_t border; /* 1512/200 */ + uint8_t invert; /* 512/640 */ + int fontbase; /* 1512/200 */ + int linepos; + int displine; + int sc; + int vc; + int cgadispon; + int con; + int coff; + int cursoron; + int cgablink; + int vsynctime; + int fullchange; + int vadj; + uint16_t ma; + uint16_t maback; + int dispon; + int blink; + uint64_t dispontime; /* 1512/1640 */ + uint64_t dispofftime; /* 1512/1640 */ + pc_timer_t timer; /* 1512/1640 */ + int firstline; + int lastline; + uint8_t *vram; + void *ams; } amsvid_t; -typedef struct { +typedef struct amstrad_t { /* Machine stuff. */ uint8_t dead; - uint8_t stat1, - stat2; - uint8_t type, - language; + uint8_t stat1; + uint8_t stat2; + uint8_t type; + uint8_t language; /* Keyboard stuff. */ int8_t wantirq; @@ -147,8 +152,8 @@ typedef struct { pc_timer_t send_delay_timer; /* Mouse stuff. */ - uint8_t mousex, - mousey; + uint8_t mousex; + uint8_t mousey; int oldb; /* Video stuff. */ @@ -160,7 +165,7 @@ uint32_t amstrad_latch; static uint8_t key_queue[16]; static int key_queue_start = 0; -static int key_queue_end = 0; +static int key_queue_end = 0; static uint8_t crtc_mask[32] = { 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x7f, 0x7f, 0xf3, 0x1f, 0x7f, 0x1f, 0x3f, 0xff, 0x3f, 0xff, @@ -263,14 +268,17 @@ vid_out_1512(uint16_t addr, uint8_t val, void *priv) case 0x03df: vid->border = val; return; + + default: + return; } } static uint8_t vid_in_1512(uint16_t addr, void *priv) { - amsvid_t *vid = (amsvid_t *) priv; - uint8_t ret = 0xff; + const amsvid_t *vid = (amsvid_t *) priv; + uint8_t ret = 0xff; if ((addr >= 0x3d0) && (addr <= 0x3d7)) addr = (addr & 0xff9) | 0x004; @@ -287,6 +295,9 @@ vid_in_1512(uint16_t addr, void *priv) case 0x03da: ret = vid->stat; break; + + default: + break; } return ret; @@ -316,7 +327,7 @@ vid_write_1512(uint32_t addr, uint8_t val, void *priv) static uint8_t vid_read_1512(uint32_t addr, void *priv) { - amsvid_t *vid = (amsvid_t *) priv; + const amsvid_t *vid = (amsvid_t *) priv; cycles -= 12; addr &= 0x3fff; @@ -780,9 +791,15 @@ vid_out_1640(uint16_t addr, uint8_t val, void *priv) mem_mapping_set_addr(&vid->ega.mapping, 0xb8000, 0x08000); break; + + default: + break; } } return; + + default: + break; } if (vid->cga_enabled) @@ -924,6 +941,9 @@ ams_inform(amsvid_t *vid) case PC200_LCDM: video_inform(VIDEO_FLAG_TYPE_MDA, &timing_pc200); break; + + default: + break; } } @@ -990,7 +1010,7 @@ static unsigned char mapping2[256] = { static void set_lcd_cols(uint8_t mode_reg) { - unsigned char *mapping = (mode_reg & 0x80) ? mapping2 : mapping1; + const unsigned char *mapping = (mode_reg & 0x80) ? mapping2 : mapping1; for (uint16_t c = 0; c < 256; c++) { switch (mapping[c]) { @@ -1013,6 +1033,9 @@ set_lcd_cols(uint8_t mode_reg) lcdcols[c][0][0] = lcdcols[c][1][0] = blue; lcdcols[c][0][1] = lcdcols[c][1][1] = blue; break; + + default: + break; } } } @@ -1043,6 +1066,9 @@ vid_in_200(uint16_t addr, void *priv) case 0x03df: return (vid->reg_3df); + + default: + break; } if (addr >= 0x3D0 && addr <= 0x3DF) @@ -1176,6 +1202,9 @@ vid_out_200(uint16_t addr, uint8_t val, void *priv) mem_mapping_enable(&vid->cga.mapping); } return; + + default: + break; } if (addr >= 0x3D0 && addr <= 0x3DF) @@ -1272,7 +1301,7 @@ lcdm_poll(amsvid_t *vid) drawcursor = ((mda->ma == ca) && mda->con && mda->cursoron); blink = ((mda->blink & 16) && (mda->ctrl & 0x20) && (attr & 0x80) && !drawcursor); - lcd_draw_char_80(vid, &((uint32_t *) (buffer32->line[mda->displine]))[x * 8], chr, attr, drawcursor, blink, mda->sc, 0, mda->ctrl); + lcd_draw_char_80(vid, &((buffer32->line[mda->displine]))[x * 8], chr, attr, drawcursor, blink, mda->sc, 0, mda->ctrl); mda->ma++; } } @@ -1422,7 +1451,7 @@ lcdc_poll(amsvid_t *vid) 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 (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; + buffer32->line[cga->displine << 1][(x << 4) + c] = buffer32->line[(cga->displine << 1) + 1][(x << 4) + c] = (dat & 0x8000) ? blue : green; dat <<= 1; } } @@ -1568,9 +1597,9 @@ lcdc_poll(amsvid_t *vid) } static void -vid_poll_200(void *p) +vid_poll_200(void *priv) { - amsvid_t *vid = (amsvid_t *) p; + amsvid_t *vid = (amsvid_t *) priv; switch (vid->emulation) { case PC200_LCDM: @@ -1579,6 +1608,9 @@ vid_poll_200(void *p) case PC200_LCDC: lcdc_poll(vid); return; + + default: + break; } } @@ -1614,6 +1646,9 @@ vid_init_200(amstrad_t *ams) break; /* The other combination is 'IDA disabled' (0x20) - see * m_amstrad.c */ + + default: + break; } else switch (vid->emulation) { @@ -1635,6 +1670,9 @@ vid_init_200(amstrad_t *ams) case PC200_LCDM: vid->dipswitches = 0x10; break; + + default: + break; } cga = &vid->cga; @@ -1969,7 +2007,7 @@ const device_t vid_pc3086_device = { }; static void -ms_write(uint16_t addr, uint8_t val, void *priv) +ms_write(uint16_t addr, UNUSED(uint8_t val), void *priv) { amstrad_t *ams = (amstrad_t *) priv; @@ -1997,7 +2035,7 @@ ms_read(uint16_t addr, void *priv) } static int -ms_poll(int x, int y, int z, int b, void *priv) +ms_poll(int x, int y, UNUSED(int z), int b, void *priv) { amstrad_t *ams = (amstrad_t *) priv; @@ -2222,6 +2260,9 @@ ams_write(uint16_t port, uint8_t val, void *priv) case 0xdead: ams->dead = val; break; + + default: + break; } } @@ -2285,6 +2326,9 @@ ams_read(uint16_t port, void *priv) case AMSTRAD_SW10: ret |= 0x20; break; + + default: + break; } break; @@ -2300,6 +2344,9 @@ ams_read(uint16_t port, void *priv) case 0xdead: ret = ams->dead; break; + + default: + break; } return ret; @@ -2482,6 +2529,9 @@ machine_amstrad_init(const machine_t *model, int type) case AMS_PC3086: ams->fdc = device_add(&fdc_at_actlow_device); break; + + default: + break; } ams->language = 7; @@ -2539,6 +2589,9 @@ machine_amstrad_init(const machine_t *model, int type) device_context_restore(); device_add(¶dise_pvga1a_pc3086_device); break; + + default: + break; } else if ((type == AMS_PC200) || (type == AMS_PPC512)) io_sethandler(0x03de, 1, diff --git a/src/machine/m_at_286_386sx.c b/src/machine/m_at_286_386sx.c index 54e7d6b9e..fb87c9976 100644 --- a/src/machine/m_at_286_386sx.c +++ b/src/machine/m_at_286_386sx.c @@ -807,10 +807,6 @@ machine_at_pc8_init(const machine_t *model) return ret; } -/* - * Current bugs: - * - ctrl-alt-del produces an 8042 error - */ int machine_at_3302_init(const machine_t *model) { @@ -820,8 +816,8 @@ machine_at_3302_init(const machine_t *model) 0x000f0000, 65536, 0); if (ret) { - bios_load_aux_linear("roms/machines/3302/f800-setup_ncr3.5-013190.bin", - 0x000f8000, 32768, 0); + ret &= bios_load_aux_linear("roms/machines/3302/f800-setup_ncr3.5-013190.bin", + 0x000f8000, 32768, 0); } if (bios_only || !ret) diff --git a/src/machine/m_at_386dx_486.c b/src/machine/m_at_386dx_486.c index deaa540c4..3f37c13c4 100644 --- a/src/machine/m_at_386dx_486.c +++ b/src/machine/m_at_386dx_486.c @@ -48,6 +48,7 @@ #include <86box/scsi_ncr53c8xx.h> #include <86box/hwm.h> #include <86box/machine.h> +#include <86box/plat_unused.h> int machine_at_acc386_init(const machine_t *model) @@ -812,7 +813,7 @@ machine_at_greenb_init(const machine_t *model) } static void -machine_at_sis_85c496_common_init(const machine_t *model) +machine_at_sis_85c496_common_init(UNUSED(const machine_t *model)) { device_add(&ide_pci_2ch_device); @@ -1281,7 +1282,9 @@ machine_at_abpb4_init(const machine_t *model) device_add(&ali1489_device); device_add(&w83787f_device); device_add(&keyboard_at_device); - // device_add(&intel_flash_bxt_device); +#if 0 + device_add(&intel_flash_bxt_device); +#endif device_add(&sst_flash_29ee010_device); return ret; @@ -1788,7 +1791,7 @@ machine_at_tg486gp_init(const machine_t *model) int machine_at_tg486g_init(const machine_t *model) { - int ret, i; + int ret; ret = bios_load_linear("roms/machines/tg486g/tg486g.bin", 0x000c0000, 262144, 0); @@ -1803,7 +1806,7 @@ machine_at_tg486g_init(const machine_t *model) device_add(&keyboard_ps2_tg_ami_pci_device); if (gfxcard[0] != VID_INTERNAL) { - for (i = 0; i < 32768; i++) + for (uint16_t i = 0; i < 32768; i++) rom[i] = mem_readb_phys(0x000c0000 + i); } mem_mapping_set_addr(&bios_mapping, 0x0c0000, 0x40000); diff --git a/src/machine/m_at_commodore.c b/src/machine/m_at_commodore.c index 3587db44a..a0b522371 100644 --- a/src/machine/m_at_commodore.c +++ b/src/machine/m_at_commodore.c @@ -52,11 +52,12 @@ #include <86box/fdd.h> #include <86box/fdc.h> #include <86box/machine.h> +#include <86box/plat_unused.h> static serial_t *cmd_uart; static void -cbm_io_write(uint16_t port, uint8_t val, void *p) +cbm_io_write(UNUSED(uint16_t port), uint8_t val, UNUSED(void *priv)) { lpt1_remove(); lpt2_remove(); @@ -71,6 +72,9 @@ cbm_io_write(uint16_t port, uint8_t val, void *p) case 3: lpt1_init(LPT2_ADDR); break; + + default: + break; } switch (val & 0xc) { @@ -80,6 +84,9 @@ cbm_io_write(uint16_t port, uint8_t val, void *p) case 0x8: serial_setup(cmd_uart, COM1_ADDR, COM1_IRQ); break; + + default: + break; } } diff --git a/src/machine/m_at_compaq.c b/src/machine/m_at_compaq.c index 3676a9d92..0731aa810 100644 --- a/src/machine/m_at_compaq.c +++ b/src/machine/m_at_compaq.c @@ -41,6 +41,7 @@ #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 }; @@ -127,7 +128,7 @@ compaq_plasma_recalctimings(compaq_plasma_t *self) } static void -compaq_plasma_waitstates(void *p) +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; @@ -205,6 +206,9 @@ compaq_plasma_out(uint16_t addr, uint8_t val, void *priv) else mem_mapping_enable(&self->cga.mapping); break; + + default: + break; } } @@ -249,22 +253,25 @@ compaq_plasma_in(uint16_t addr, void *priv) case 0x23c6: ret = 0; break; + + default: + break; } return ret; } static void -compaq_plasma_poll(void *p) +compaq_plasma_poll(void *priv) { - compaq_plasma_t *self = (compaq_plasma_t *) p; - uint8_t chr, attr; + 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 x, c; int cursorline; int blink = 0; int underline = 0; @@ -272,8 +279,10 @@ compaq_plasma_poll(void *p) uint32_t fg = (self->cga.cgacol & 0x0f) ? amber : black; uint32_t bg = black; uint32_t cols[2]; - uint8_t dat2, pattern; - uint32_t ink0 = 0, ink1 = 0; + uint8_t dat2; + uint8_t pattern; + uint32_t ink0 = 0; + uint32_t ink1 = 0; /* Switch between internal plasma and external CRT display. */ if ((cpq_st_display_internal != -1) && (cpq_st_display_internal != self->internal_monitor)) { @@ -304,25 +313,25 @@ compaq_plasma_poll(void *p) } else { addr = ((self->cga.displine >> 1) & 1) * 0x2000 + (self->cga.displine >> 2) * 80 + ((ma & ~1) << 1); } - for (x = 0; x < 80; x++) { - dat2 = self->cga.vram[(addr & 0x7FFF)]; + for (uint8_t x = 0; x < 80; x++) { + dat2 = self->cga.vram[addr & 0x7FFF]; addr++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { ink = (dat2 & 0x80) ? fg : bg; if (!(self->cga.cgamode & 8)) ink = black; - ((uint32_t *) buffer32->line[self->cga.displine])[x * 8 + c] = ink; + (buffer32->line[self->cga.displine])[x * 8 + c] = ink; dat2 <<= 1; } } } else { addr = ((self->cga.displine >> 1) & 1) * 0x2000 + (self->cga.displine >> 2) * 80 + ((ma & ~1) << 1); - for (x = 0; x < 80; x++) { - dat2 = self->cga.vram[(addr & 0x7fff)]; + for (uint8_t x = 0; x < 80; x++) { + dat2 = self->cga.vram[addr & 0x7fff]; addr++; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { pattern = (dat2 & 0xC0) >> 6; if (!(self->cga.cgamode & 8)) pattern = 0; @@ -352,6 +361,9 @@ compaq_plasma_poll(void *p) 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; @@ -371,7 +383,7 @@ compaq_plasma_poll(void *p) cursorline = ((self->cga.crtc[0x0a] & 0x0f) * 2 <= sc) && ((self->cga.crtc[0x0b] & 0x0F) * 2 >= sc); /* for each text column */ - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { /* video output enabled */ if (self->cga.cgamode & 8) { chr = self->cga.vram[(addr + 2 * x) & 0x7fff]; @@ -405,13 +417,13 @@ compaq_plasma_poll(void *p) /* character underline active and 7th row of pixels in character height being drawn */ if (underline && (sc == 7)) { /* for each pixel in character width */ - for (c = 0; c < 8; c++) + for (uint8_t 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++) + for (uint8_t c = 0; c < 8; c++) buffer32->line[self->cga.displine][(x << 3) + c] = cols[(fontdatm[chr + self->cga.fontbase][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); } else { - for (c = 0; c < 8; c++) + for (uint8_t c = 0; c < 8; c++) buffer32->line[self->cga.displine][(x << 3) + c] = cols[(fontdatm[chr + self->cga.fontbase][sc] & (1 << (c ^ 7))) ? 1 : 0]; } @@ -427,7 +439,7 @@ compaq_plasma_poll(void *p) else cursorline = ((self->cga.crtc[0x0a] & 0x0f) * 2 <= sc) && ((self->cga.crtc[0x0b] & 0x0F) * 2 >= sc); - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { if (self->cga.cgamode & 8) { chr = self->cga.vram[(addr + 2 * x) & 0x7fff]; attr = self->cga.vram[(addr + 2 * x + 1) & 0x7fff]; @@ -460,14 +472,14 @@ compaq_plasma_poll(void *p) /* character underline active and 7th row of pixels in character height being drawn */ if (underline && (sc == 7)) { /* for each pixel in character width */ - for (c = 0; c < 8; c++) + 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 (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { buffer32->line[self->cga.displine][(x << 4) + c * 2] = buffer32->line[self->cga.displine][(x << 4) + c * 2 + 1] = cols[(fontdatm[chr][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); } } else { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { buffer32->line[self->cga.displine][(x << 4) + c * 2] = buffer32->line[self->cga.displine][(x << 4) + c * 2 + 1] = cols[(fontdatm[chr][sc] & (1 << (c ^ 7))) ? 1 : 0]; } } @@ -530,9 +542,7 @@ compaq_plasma_poll(void *p) static void compaq_plasma_mdaattr_rebuild(void) { - int c; - - for (c = 0; c < 256; c++) { + for (uint16_t c = 0; c < 256; c++) { mdaattr[c][0][0] = mdaattr[c][1][0] = mdaattr[c][1][1] = 16; if (c & 8) mdaattr[c][0][1] = 15 + 16; @@ -636,7 +646,7 @@ compaq_plasma_recalcattrs(compaq_plasma_t *self) } static void * -compaq_plasma_init(const device_t *info) +compaq_plasma_init(UNUSED(const device_t *info)) { compaq_plasma_t *self = malloc(sizeof(compaq_plasma_t)); memset(self, 0, sizeof(compaq_plasma_t)); @@ -674,18 +684,18 @@ compaq_plasma_init(const device_t *info) } static void -compaq_plasma_close(void *p) +compaq_plasma_close(void *priv) { - compaq_plasma_t *self = (compaq_plasma_t *) p; + compaq_plasma_t *self = (compaq_plasma_t *) priv; free(self->cga.vram); free(self); } static void -compaq_plasma_speed_changed(void *p) +compaq_plasma_speed_changed(void *priv) { - compaq_plasma_t *self = (compaq_plasma_t *) p; + compaq_plasma_t *self = (compaq_plasma_t *) priv; compaq_plasma_recalctimings(self); } @@ -727,7 +737,7 @@ const device_t compaq_plasma_device = { }; static uint8_t -read_ram(uint32_t addr, void *priv) +read_ram(uint32_t addr, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addreadlookup(mem_logical_addr, addr); @@ -736,7 +746,7 @@ read_ram(uint32_t addr, void *priv) } static uint16_t -read_ramw(uint32_t addr, void *priv) +read_ramw(uint32_t addr, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addreadlookup(mem_logical_addr, addr); @@ -745,7 +755,7 @@ read_ramw(uint32_t addr, void *priv) } static uint32_t -read_raml(uint32_t addr, void *priv) +read_raml(uint32_t addr, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addreadlookup(mem_logical_addr, addr); @@ -754,7 +764,7 @@ read_raml(uint32_t addr, void *priv) } static void -write_ram(uint32_t addr, uint8_t val, void *priv) +write_ram(uint32_t addr, uint8_t val, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addwritelookup(mem_logical_addr, addr); @@ -763,7 +773,7 @@ write_ram(uint32_t addr, uint8_t val, void *priv) } static void -write_ramw(uint32_t addr, uint16_t val, void *priv) +write_ramw(uint32_t addr, uint16_t val, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addwritelookup(mem_logical_addr, addr); @@ -772,7 +782,7 @@ write_ramw(uint32_t addr, uint16_t val, void *priv) } static void -write_raml(uint32_t addr, uint32_t val, void *priv) +write_raml(uint32_t addr, uint32_t val, UNUSED(void *priv)) { addr = (addr & 0x7ffff) + 0x80000; addwritelookup(mem_logical_addr, addr); @@ -830,6 +840,9 @@ machine_at_compaq_init(const machine_t *model, int type) machine_at_common_init(model); device_add(&keyboard_at_compaq_device); break; + + default: + break; } } diff --git a/src/machine/m_at_slot1.c b/src/machine/m_at_slot1.c index 88d3453da..f5cf3bc5e 100644 --- a/src/machine/m_at_slot1.c +++ b/src/machine/m_at_slot1.c @@ -200,8 +200,8 @@ machine_at_p2bls_init(const machine_t *model) pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_NORTHBRIDGE, 0, 0, 0, 0); pci_register_slot(0x04, PCI_CARD_SOUTHBRIDGE, 1, 2, 3, 4); - pci_register_slot(0x06, PCI_CARD_NORMAL, 4, 1, 2, 3); /* SCSI */ - pci_register_slot(0x07, PCI_CARD_NORMAL, 3, 4, 1, 2); /* LAN */ + pci_register_slot(0x06, PCI_CARD_SCSI, 4, 1, 2, 3); + pci_register_slot(0x07, PCI_CARD_NETWORK, 3, 4, 1, 2); pci_register_slot(0x0B, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 2, 3, 4); pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3); @@ -211,7 +211,9 @@ machine_at_p2bls_init(const machine_t *model) device_add(&piix4e_device); device_add(&keyboard_ps2_ami_pci_device); device_add(&w83977ef_device); - // device_add(ics9xxx_get(ICS9150_08)); /* setting proper speeds requires some interaction with the AS97127F ASIC */ +#if 0 + device_add(ics9xxx_get(ICS9150_08)); /* setting proper speeds requires some interaction with the AS97127F ASIC */ +#endif device_add(&sst_flash_39sf020_device); spd_register(SPD_TYPE_SDRAM, 0xF, 256); device_add(&w83781d_device); /* fans: Chassis, CPU, Power; temperatures: MB, unused, CPU */ diff --git a/src/machine/m_at_socket4.c b/src/machine/m_at_socket4.c index ef745d088..b8e080d62 100644 --- a/src/machine/m_at_socket4.c +++ b/src/machine/m_at_socket4.c @@ -81,7 +81,9 @@ machine_at_award_common_init(const machine_t *model) if (fdc_type == FDC_INTERNAL) device_add(&fdc_at_device); - // device_add(&keyboard_ps2_pci_device); +#if 0 + device_add(&keyboard_ps2_pci_device); +#endif device_add(&keyboard_ps2_ami_pci_device); } diff --git a/src/machine/m_at_socket7_3v.c b/src/machine/m_at_socket7_3v.c index d8be38bb1..852ce0a55 100644 --- a/src/machine/m_at_socket7_3v.c +++ b/src/machine/m_at_socket7_3v.c @@ -61,7 +61,9 @@ machine_at_thor_common_init(const machine_t *model, int mr) if (gfxcard[0] == VID_INTERNAL) device_add(&s3_phoenix_trio64vplus_onboard_pci_device); - // device_add(&keyboard_ps2_ami_pci_device); +#if 0 + device_add(&keyboard_ps2_ami_pci_device); +#endif device_add(&keyboard_ps2_intel_ami_pci_device); device_add(&i430fx_device); device_add(&piix_device); diff --git a/src/machine/m_at_t3100e.c b/src/machine/m_at_t3100e.c index b1f8d10f6..a84845982 100644 --- a/src/machine/m_at_t3100e.c +++ b/src/machine/m_at_t3100e.c @@ -166,6 +166,7 @@ #include <86box/fdc_ext.h> #include <86box/machine.h> #include <86box/m_at_t3100e.h> +#include <86box/plat_unused.h> extern uint8_t *ram; /* Physical RAM */ @@ -191,12 +192,12 @@ static unsigned t3100e_ems_page_reg[] = { 0x4208, 0x8208, 0xc208, /* The first four map the first 2Mb */ - /* of RAM into the page frame */ + /* of RAM into the page frame */ 0x218, 0x4218, 0x8218, 0xc218, /* The next four map the next 2Mb */ - /* of RAM */ + /* of RAM */ 0x258, 0x4258, 0x8258, @@ -221,7 +222,7 @@ struct t3100e_ems_regs { /* Bit 0 is 0 for colour, 1 for mono */ } t3100e_ems; -void t3100e_ems_out(uint16_t addr, uint8_t val, void *p); +void t3100e_ems_out(uint16_t addr, uint8_t val, void *priv); #ifdef ENABLE_T3100E_LOG int t3100e_do_log = ENABLE_T3100E_LOG; @@ -331,11 +332,15 @@ port_to_page(uint16_t addr) return 14; case 0xC268: return 15; + + default: + break; } return -1; } -/* Used to dump the memory mapping table, for debugging +/* Used to dump the memory mapping table, for debugging */ +#if 0 void dump_mappings(void) { mem_mapping_t *mm = base_mapping.next; @@ -377,7 +382,8 @@ void dump_mappings(void) mm = mm->next; } -}*/ +} +#endif void t3100e_map_ram(uint8_t val) @@ -437,7 +443,9 @@ t3100e_map_ram(uint8_t val) &t3100e_ems); } - // dump_mappings(); +#if 0 + dump_mappings(); +#endif } void @@ -470,9 +478,9 @@ t3100e_turbo_set(uint8_t value) } uint8_t -t3100e_sys_in(uint16_t addr, void *p) +t3100e_sys_in(UNUSED(uint16_t addr), void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) p; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; /* The low 4 bits always seem to be 0x0C. The high 4 are a * notification sent by the keyboard controller when it detects @@ -483,9 +491,11 @@ t3100e_sys_in(uint16_t addr, void *p) /* Handle writes to the T3100e system control port at 0x8084 */ void -t3100e_sys_out(uint16_t addr, uint8_t val, void *p) +t3100e_sys_out(UNUSED(uint16_t addr), uint8_t val, UNUSED(void *priv)) { - // struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *)p; +#if 0 + struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; +#endif switch (val & 0xE0) { case 0x00: /* Set serial port IRQs. Not implemented */ @@ -551,6 +561,9 @@ t3100e_config_get(void) value |= 0x10; break; /* Tri-mode */ /* All others will be treated as 1.4M */ + + default: + break; } break; case 4: @@ -574,7 +587,11 @@ t3100e_config_get(void) prt_switch = 0; /* No external drive */ } break; + + default: + break; } /* End switch */ + switch (prt_switch) { case 0: value |= 4; @@ -585,15 +602,18 @@ t3100e_config_get(void) case 2: value |= 6; break; /* External floppy is B: */ + + default: + break; } return value; } /* Read EMS page register */ uint8_t -t3100e_ems_in(uint16_t addr, void *p) +t3100e_ems_in(uint16_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) p; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; int page = port_to_page(addr); if (page >= 0) @@ -606,9 +626,9 @@ t3100e_ems_in(uint16_t addr, void *p) /* Write EMS page register */ void -t3100e_ems_out(uint16_t addr, uint8_t val, void *p) +t3100e_ems_out(uint16_t addr, uint8_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) p; + struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; int pg = port_to_page(addr); if (pg == -1) @@ -637,8 +657,8 @@ t3100e_ems_out(uint16_t addr, uint8_t val, void *p) static uint8_t ems_read_ram(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return 0xFF; @@ -649,22 +669,26 @@ ems_read_ram(uint32_t addr, void *priv) static uint16_t ems_read_ramw(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return 0xFFFF; - // t3100e_log("ems_read_ramw addr=%05x ", addr); +#if 0 + t3100e_log("ems_read_ramw addr=%05x ", addr); +#endif addr = regs->page_exec[pg] + (addr & 0x3FFF); - // t3100e_log("-> %06x val=%04x\n", addr, *(uint16_t *)&ram[addr]); +#if 0 + // t3100e_log("-> %06x val=%04x\n", addr, *(uint16_t *) &ram[addr]); +#endif return *(uint16_t *) &ram[addr]; } static uint32_t ems_read_raml(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return 0xFFFFFFFF; @@ -676,8 +700,8 @@ ems_read_raml(uint32_t addr, void *priv) static void ems_write_ram(uint32_t addr, uint8_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -688,14 +712,18 @@ ems_write_ram(uint32_t addr, uint8_t val, void *priv) static void ems_write_ramw(uint32_t addr, uint16_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; - // t3100e_log("ems_write_ramw addr=%05x ", addr); +#if 0 + t3100e_log("ems_write_ramw addr=%05x ", addr); +#endif addr = regs->page_exec[pg] + (addr & 0x3FFF); - // t3100e_log("-> %06x val=%04x\n", addr, val); +#if 0 + t3100e_log("-> %06x val=%04x\n", addr, val); +#endif *(uint16_t *) &ram[addr] = val; } @@ -703,8 +731,8 @@ ems_write_ramw(uint32_t addr, uint16_t val, void *priv) static void ems_write_raml(uint32_t addr, uint32_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; - int pg = addr_to_page(addr); + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -717,7 +745,7 @@ ems_write_raml(uint32_t addr, uint32_t val, void *priv) static uint8_t upper_read_ram(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; return ram[addr]; @@ -726,7 +754,7 @@ upper_read_ram(uint32_t addr, void *priv) static uint16_t upper_read_ramw(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; return *(uint16_t *) &ram[addr]; @@ -735,7 +763,7 @@ upper_read_ramw(uint32_t addr, void *priv) static uint32_t upper_read_raml(uint32_t addr, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; return *(uint32_t *) &ram[addr]; @@ -744,7 +772,7 @@ upper_read_raml(uint32_t addr, void *priv) static void upper_write_ram(uint32_t addr, uint8_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; ram[addr] = val; @@ -753,7 +781,7 @@ upper_write_ram(uint32_t addr, uint8_t val, void *priv) static void upper_write_ramw(uint32_t addr, uint16_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; *(uint16_t *) &ram[addr] = val; @@ -762,7 +790,7 @@ upper_write_ramw(uint32_t addr, uint16_t val, void *priv) static void upper_write_raml(uint32_t addr, uint32_t val, void *priv) { - struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; + const struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *) priv; addr = (addr - (1024 * mem_size)) + regs->upper_base; *(uint32_t *) &ram[addr] = val; diff --git a/src/machine/m_at_t3100e_vid.c b/src/machine/m_at_t3100e_vid.c index 9602b7b9e..57b0641a6 100644 --- a/src/machine/m_at_t3100e_vid.c +++ b/src/machine/m_at_t3100e_vid.c @@ -66,6 +66,7 @@ #include <86box/video.h> #include <86box/vid_cga.h> #include <86box/m_at_t3100e.h> +#include <86box/plat_unused.h> #define T3100E_XSIZE 640 #define T3100E_YSIZE 400 @@ -134,14 +135,14 @@ typedef struct t3100e_t { static video_timings_t timing_t3100e = { VIDEO_ISA, 8, 16, 32, 8, 16, 32 }; void t3100e_recalctimings(t3100e_t *t3100e); -void t3100e_write(uint32_t addr, uint8_t val, void *p); -uint8_t t3100e_read(uint32_t addr, void *p); +void t3100e_write(uint32_t addr, uint8_t val, void *priv); +uint8_t t3100e_read(uint32_t addr, void *priv); void t3100e_recalcattrs(t3100e_t *t3100e); void -t3100e_out(uint16_t addr, uint8_t val, void *p) +t3100e_out(uint16_t addr, uint8_t val, void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; switch (addr) { /* Emulated CRTC, register select */ case 0x3d0: @@ -168,21 +169,20 @@ t3100e_out(uint16_t addr, uint8_t val, void *p) t3100e_recalctimings(t3100e); return; - /* CGA control register */ - case 0x3D8: - cga_out(addr, val, &t3100e->cga); - return; - /* CGA colour register */ - case 0x3D9: + case 0x3D8: /* CGA control register */ + case 0x3D9: /* CGA colour register */ cga_out(addr, val, &t3100e->cga); return; + + default: + break; } } uint8_t -t3100e_in(uint16_t addr, void *p) +t3100e_in(uint16_t addr, void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; uint8_t val; switch (addr) { @@ -196,24 +196,29 @@ t3100e_in(uint16_t addr, void *p) val |= 0x30; /* Plasma / CRT */ return val; } + break; + + default: + break; } return cga_in(addr, &t3100e->cga); } void -t3100e_write(uint32_t addr, uint8_t val, void *p) +t3100e_write(uint32_t addr, uint8_t val, void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; t3100e->vram[addr & 0x7fff] = val; cycles -= 4; } uint8_t -t3100e_read(uint32_t addr, void *p) +t3100e_read(uint32_t addr, void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + const t3100e_t *t3100e = (t3100e_t *) priv; + cycles -= 4; return t3100e->vram[addr & 0x7fff]; @@ -242,7 +247,6 @@ void t3100e_text_row80(t3100e_t *t3100e) { uint32_t cols[2]; - int c; uint8_t chr; uint8_t attr; int drawcursor; @@ -287,12 +291,12 @@ t3100e_text_row80(t3100e_t *t3100e) cols[0] = normcols[attr][0]; } if (drawcursor) { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); } } else { - for (c = 0; c < 8; c++) - ((uint32_t *) buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) + (buffer32->line[t3100e->displine])[(x << 3) + c] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; } ++ma; } @@ -349,11 +353,11 @@ t3100e_text_row40(t3100e_t *t3100e) } if (drawcursor) { for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t3100e->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); + (buffer32->line[t3100e->displine])[(x << 4) + c * 2] = (buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (amber ^ black); } } else { for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t3100e->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + (buffer32->line[t3100e->displine])[(x << 4) + c * 2] = (buffer32->line[t3100e->displine])[(x << 4) + c * 2 + 1] = cols[(fontdatm[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; } } ++ma; @@ -386,8 +390,8 @@ t3100e_cgaline6(t3100e_t *t3100e) ink = (dat & 0x80) ? fg : bg; if (!(t3100e->cga.cgamode & 8)) ink = black; - ((uint32_t *) buffer32->line[t3100e->displine])[x * 8 + c] = ink; - dat = dat << 1; + (buffer32->line[t3100e->displine])[x * 8 + c] = ink; + dat = dat << 1; } } } @@ -445,18 +449,21 @@ t3100e_cgaline4(t3100e_t *t3100e) case 3: ink0 = ink1 = amber; break; + + default: + break; } - ((uint32_t *) buffer32->line[t3100e->displine])[x * 8 + 2 * c] = ink0; - ((uint32_t *) buffer32->line[t3100e->displine])[x * 8 + 2 * c + 1] = ink1; - dat = dat << 2; + (buffer32->line[t3100e->displine])[x * 8 + 2 * c] = ink0; + (buffer32->line[t3100e->displine])[x * 8 + 2 * c + 1] = ink1; + dat = dat << 2; } } } void -t3100e_poll(void *p) +t3100e_poll(void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; if (t3100e->video_options != st_video_options) { t3100e->video_options = st_video_options; @@ -646,7 +653,7 @@ t3100e_recalcattrs(t3100e_t *t3100e) } void * -t3100e_init(const device_t *info) +t3100e_init(UNUSED(const device_t *info)) { t3100e_t *t3100e = malloc(sizeof(t3100e_t)); memset(t3100e, 0, sizeof(t3100e_t)); @@ -680,18 +687,18 @@ t3100e_init(const device_t *info) } void -t3100e_close(void *p) +t3100e_close(void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; free(t3100e->vram); free(t3100e); } void -t3100e_speed_changed(void *p) +t3100e_speed_changed(void *priv) { - t3100e_t *t3100e = (t3100e_t *) p; + t3100e_t *t3100e = (t3100e_t *) priv; t3100e_recalctimings(t3100e); } diff --git a/src/machine/m_elt.c b/src/machine/m_elt.c index fb7919f26..573095223 100644 --- a/src/machine/m_elt.c +++ b/src/machine/m_elt.c @@ -50,11 +50,13 @@ #include <86box/rom.h> #include <86box/video.h> #include <86box/vid_cga.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> static void -elt_vid_off_poll(void *p) +elt_vid_off_poll(void *priv) { - cga_t *cga = p; + cga_t *cga = priv; uint8_t hdisp = cga->crtc[1]; /* Don't display anything. @@ -65,9 +67,9 @@ elt_vid_off_poll(void *p) } static void -sysstat_out(uint16_t port, uint8_t val, void *p) +sysstat_out(UNUSED(uint16_t port), uint8_t val, void *priv) { - cga_t *cga = p; + cga_t *cga = priv; switch (val) { case 0: @@ -88,10 +90,10 @@ sysstat_out(uint16_t port, uint8_t val, void *p) } static uint8_t -sysstat_in(uint16_t port, void *p) +sysstat_in(UNUSED(uint16_t port), void *priv) { - cga_t *cga = p; - uint8_t ret = 0x0a; /* No idea what these bits are */ + const cga_t *cga = priv; + uint8_t ret = 0x0a; /* No idea what these bits are */ /* External CRT. We don't emulate the LCD/CRT switching, let's just * frivolously use this bit to indicate we're using the LCD if the @@ -103,9 +105,9 @@ sysstat_in(uint16_t port, void *p) } static void -elt_vid_out(uint16_t addr, uint8_t val, void *p) +elt_vid_out(uint16_t addr, uint8_t val, void *priv) { - cga_t *cga = p; + cga_t *cga = priv; /* The Equity LT chipset's CRTC contains more registers than the * regular CGA. The BIOS writes one of them, register 36 (0x24). @@ -122,22 +124,25 @@ elt_vid_out(uint16_t addr, uint8_t val, void *p) case 0x3d1: if (cga->crtcreg >= 32) return; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + default: cga->crtcreg &= 31; - cga_out(addr, val, p); + cga_out(addr, val, priv); } } static uint8_t -elt_vid_in(uint16_t addr, void *p) +elt_vid_in(uint16_t addr, void *priv) { - cga_t *cga = p; + cga_t *cga = priv; /* Just make sure we don't ever let regular CGA code run with crtcreg * pointing out of crtcregs[] bounds. */ cga->crtcreg &= 31; - return cga_in(addr, p); + return cga_in(addr, priv); } static void diff --git a/src/machine/m_europc.c b/src/machine/m_europc.c index 615d6ff7b..e541cf718 100644 --- a/src/machine/m_europc.c +++ b/src/machine/m_europc.c @@ -104,6 +104,7 @@ #include <86box/hdc.h> #include <86box/video.h> #include <86box/machine.h> +#include <86box/plat_unused.h> #define EUROPC_DEBUG 0 /* current debugging level */ @@ -125,7 +126,7 @@ #define MRTC_CHECK_HI 0x0e /* Checksum, high byte */ #define MRTC_CTRLSTAT 0x0f /* RTC control/status, binary */ -typedef struct { +typedef struct europc_t { uint16_t jim; /* JIM base address */ uint8_t regs[16]; /* JIM internal regs (8) */ @@ -372,13 +373,17 @@ jim_set(europc_t *sys, uint8_t reg, uint8_t val) switch (val) { case 0x1f: /* 0001 1111 */ case 0x0b: /* 0000 1011 */ - // europc_jim.mode=AGA_MONO; +#if 0 + europc_jim.mode=AGA_MONO; +#endif europc_log("EuroPC: AGA Monochrome mode!\n"); break; case 0x18: /* 0001 1000 */ case 0x1a: /* 0001 1010 */ - // europc_jim.mode=AGA_COLOR; +#if 0 + europc_jim.mode=AGA_COLOR; +#endif break; case 0x0e: /* 0000 1100 */ @@ -392,7 +397,9 @@ jim_set(europc_t *sys, uint8_t reg, uint8_t val) break; default: - // europc_jim.mode=AGA_OFF; +#if 0 + europc_jim.mode=AGA_OFF; +#endif break; } break; @@ -400,15 +407,21 @@ jim_set(europc_t *sys, uint8_t reg, uint8_t val) case 4: /* CPU Speed control */ switch (val & 0xc0) { case 0x00: /* 4.77 MHz */ - // cpu_set_clockscale(0, 1.0/2); +#if 0 + cpu_set_clockscale(0, 1.0/2); +#endif break; case 0x40: /* 7.16 MHz */ - // cpu_set_clockscale(0, 3.0/4); +#if 0 + cpu_set_clockscale(0, 3.0/4); +#endif break; default: /* 9.54 MHz */ - // cpu_set_clockscale(0, 1);break; +#if 0 + cpu_set_clockscale(0, 1);break; +#endif break; } break; @@ -465,6 +478,9 @@ jim_write(uint16_t addr, uint8_t val, void *priv) sys->nvr_stat = 0; nvr_dosave++; break; + + default: + break; } break; @@ -511,6 +527,9 @@ jim_read(uint16_t addr, void *priv) r = (sys->nvr.regs[sys->nvr_addr] & 0x0f); sys->nvr_stat = 0; break; + + default: + break; } break; @@ -528,7 +547,7 @@ jim_read(uint16_t addr, void *priv) /* Initialize the mainboard 'device' of the machine. */ static void * -europc_boot(const device_t *info) +europc_boot(UNUSED(const device_t *info)) { europc_t *sys = &europc; uint8_t b; @@ -573,6 +592,9 @@ europc_boot(const device_t *info) case 640: b |= 0x00; break; + + default: + break; } sys->nvr.regs[MRTC_CONF_C] = b; @@ -590,6 +612,9 @@ europc_boot(const device_t *info) case 2: /* 8088, 9.56 MHz */ b |= 0x80; break; + + default: + break; } sys->nvr.regs[MRTC_CONF_D] = b; @@ -642,7 +667,7 @@ europc_boot(const device_t *info) } static void -europc_close(void *priv) +europc_close(UNUSED(void *priv)) { nvr_t *nvr = &europc.nvr; diff --git a/src/machine/m_pcjr.c b/src/machine/m_pcjr.c index c2163746b..f8c50a931 100644 --- a/src/machine/m_pcjr.c +++ b/src/machine/m_pcjr.c @@ -49,6 +49,7 @@ #include <86box/video.h> #include <86box/vid_cga_comp.h> #include <86box/machine.h> +#include <86box/plat_unused.h> #define PCJR_RGB 0 #define PCJR_COMPOSITE 1 @@ -62,7 +63,7 @@ #define STAT_IFULL 0x02 #define STAT_OFULL 0x01 -typedef struct { +typedef struct pcjr_t { /* Video Controller stuff. */ mem_mapping_t mapping; uint8_t crtc[32]; @@ -73,20 +74,28 @@ typedef struct { int memctrl; uint8_t stat; int addr_mode; - uint8_t *vram, - *b8000; - int linepos, displine; - int sc, vc; - int dispon; - int con, coff, cursoron, blink; - int vsynctime; - int fullchange; - int vadj; - uint16_t ma, maback; - uint64_t dispontime, dispofftime; - pc_timer_t timer; - int firstline, lastline; - int composite; + uint8_t *vram; + uint8_t *b8000; + int linepos; + int displine; + int sc; + int vc; + int dispon; + int con; + int coff; + int cursoron; + int blink; + int vsynctime; + int fullchange; + int vadj; + uint16_t ma; + uint16_t maback; + uint64_t dispontime; + uint64_t dispofftime; + pc_timer_t timer; + int firstline; + int lastline; + int composite; /* Keyboard Controller stuff. */ int latched; @@ -145,9 +154,9 @@ recalc_timings(pcjr_t *pcjr) } static void -vid_out(uint16_t addr, uint8_t val, void *p) +vid_out(uint16_t addr, uint8_t val, void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + pcjr_t *pcjr = (pcjr_t *) priv; uint8_t old; switch (addr) { @@ -184,13 +193,16 @@ vid_out(uint16_t addr, uint8_t val, void *p) pcjr->addr_mode = val >> 6; recalc_address(pcjr); break; + + default: + break; } } static uint8_t -vid_in(uint16_t addr, void *p) +vid_in(uint16_t addr, void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + pcjr_t *pcjr = (pcjr_t *) priv; uint8_t ret = 0xff; switch (addr) { @@ -207,15 +219,18 @@ vid_in(uint16_t addr, void *p) pcjr->stat ^= 0x10; ret = pcjr->stat; break; + + default: + break; } return ret; } static void -vid_write(uint32_t addr, uint8_t val, void *p) +vid_write(uint32_t addr, uint8_t val, void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + pcjr_t *pcjr = (pcjr_t *) priv; if (pcjr->memctrl == -1) return; @@ -224,9 +239,9 @@ vid_write(uint32_t addr, uint8_t val, void *p) } static uint8_t -vid_read(uint32_t addr, void *p) +vid_read(uint32_t addr, void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + const pcjr_t *pcjr = (pcjr_t *) priv; if (pcjr->memctrl == -1) return 0xff; @@ -235,13 +250,12 @@ vid_read(uint32_t addr, void *p) } static void -vid_poll(void *p) +vid_poll(void *priv) { - pcjr_t *pcjr = (pcjr_t *) p; + pcjr_t *pcjr = (pcjr_t *) priv; uint16_t ca = (pcjr->crtc[15] | (pcjr->crtc[14] << 8)) & 0x3fff; int drawcursor; int x; - int c; int xs_temp; int ys_temp; int oldvc; @@ -268,8 +282,8 @@ vid_poll(void *p) } pcjr->lastline = pcjr->displine; cols[0] = (pcjr->array[2] & 0xf) + 16; - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[pcjr->displine])[c] = cols[0]; + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[pcjr->displine])[c] = cols[0]; if (pcjr->array[0] & 1) { buffer32->line[pcjr->displine << 1][c + (pcjr->crtc[1] << 3) + 8] = buffer32->line[(pcjr->displine << 1) + 1][c + (pcjr->crtc[1] << 3) + 8] = cols[0]; } else { @@ -288,6 +302,9 @@ vid_poll(void *p) case 3: /*High resolution graphics*/ offset = (pcjr->sc & 3) * 0x2000; break; + + default: + break; } switch ((pcjr->array[0] & 0x13) | ((pcjr->array[3] & 0x08) << 5)) { case 0x13: /*320x200x16*/ @@ -314,7 +331,7 @@ vid_poll(void *p) for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { chr = (dat >> 7) & 1; chr |= ((dat >> 14) & 2); buffer32->line[pcjr->displine << 1][(x << 3) + 8 + c] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + 8 + c] = pcjr->array[(chr & pcjr->array[1]) + 16] + 16; @@ -337,16 +354,16 @@ vid_poll(void *p) cols[0] = pcjr->array[((attr >> 4) & pcjr->array[1]) + 16] + 16; } if (pcjr->sc & 8) { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[0]; } } else { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } if (drawcursor) { - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { buffer32->line[pcjr->displine << 1][(x << 3) + c + 8] ^= 15; buffer32->line[(pcjr->displine << 1) + 1][(x << 3) + c + 8] ^= 15; } @@ -370,17 +387,17 @@ vid_poll(void *p) } pcjr->ma++; if (pcjr->sc & 8) { - for (c = 0; c < 8; c++) { - buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[0]; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[0]; } } else { - for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][pcjr->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } if (drawcursor) { - for (c = 0; c < 16; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + c + 8] ^= 15; + for (uint8_t c = 0; c < 16; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + c + 8] ^= 15; buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + c + 8] ^= 15; } } @@ -394,8 +411,8 @@ vid_poll(void *p) for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - for (c = 0; c < 8; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; + for (uint8_t c = 0; c < 8; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[pcjr->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; dat <<= 2; } } @@ -406,12 +423,15 @@ vid_poll(void *p) for (x = 0; x < pcjr->crtc[1]; x++) { dat = (pcjr->vram[((pcjr->ma << 1) & mask) + offset] << 8) | pcjr->vram[((pcjr->ma << 1) & mask) + offset + 1]; pcjr->ma++; - for (c = 0; c < 16; c++) { - buffer32->line[(pcjr->displine << 1)][(x << 4) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; + for (uint8_t c = 0; c < 16; c++) { + buffer32->line[pcjr->displine << 1][(x << 4) + c + 8] = buffer32->line[(pcjr->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; dat <<= 1; } } break; + + default: + break; } } else { if (pcjr->array[3] & 4) { @@ -438,7 +458,7 @@ vid_poll(void *p) else x = (pcjr->crtc[1] << 4) + 16; if (pcjr->composite) { - Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[(pcjr->displine << 1)]); + Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[pcjr->displine << 1]); Composite_Process(pcjr->array[0], 0, x >> 2, buffer32->line[(pcjr->displine << 1) + 1]); } else { video_process_8(x, pcjr->displine << 1); @@ -550,7 +570,7 @@ vid_poll(void *p) pcjr->sc &= 31; pcjr->ma = pcjr->maback; } - if ((pcjr->sc == (pcjr->crtc[10] & 31) || ((pcjr->crtc[8] & 3) == 3 && pcjr->sc == ((pcjr->crtc[10] & 31) >> 1)))) + if (pcjr->sc == (pcjr->crtc[10] & 31) || ((pcjr->crtc[8] & 3) == 3 && pcjr->sc == ((pcjr->crtc[10] & 31) >> 1))) pcjr->con = 1; } } @@ -591,6 +611,9 @@ kbd_write(uint16_t port, uint8_t val, void *priv) case 0x60: sn76489_mute = 0; break; + + default: + break; } break; @@ -598,6 +621,9 @@ kbd_write(uint16_t port, uint8_t val, void *priv) nmi_mask = val & 0x80; pit_devs[0].set_using_timer(pit_devs[0].data, 1, !(val & 0x20)); break; + + default: + break; } } @@ -637,6 +663,9 @@ kbd_read(uint16_t port, void *priv) pcjr->latched = 0; ret = 0; break; + + default: + break; } return ret; @@ -765,7 +794,7 @@ const device_t pcjr_device = { }; int -machine_pcjr_init(const machine_t *model) +machine_pcjr_init(UNUSED(const machine_t *model)) { int display_type; pcjr_t *pcjr; diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index e3675e74b..d2c9f80ba 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -153,6 +153,9 @@ ps1_write(uint16_t port, uint8_t val, void *priv) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps->ps1_102 = val; @@ -174,6 +177,9 @@ ps1_write(uint16_t port, uint8_t val, void *priv) case 0x0190: ps->ps1_190 = val; break; + + default: + break; } } diff --git a/src/machine/m_ps1_hdc.c b/src/machine/m_ps1_hdc.c index bd0c8851d..225ae04a5 100644 --- a/src/machine/m_ps1_hdc.c +++ b/src/machine/m_ps1_hdc.c @@ -161,54 +161,54 @@ enum { * block is transferred. */ #pragma pack(push, 1) -typedef struct { +typedef struct ssb_t { /* Status byte 0. */ - uint8_t track_0 : 1, /* T0 */ - mbz1 : 1, /* 0 */ - mbz2 : 1, /* 0 */ - cylinder_err : 1, /* CE */ - write_fault : 1, /* WF */ - mbz3 : 1, /* 0 */ - seek_end : 1, /* SE */ - not_ready : 1; /* NR */ + uint8_t track_0 : 1; /* T0 */ + uint8_t mbz1 : 1; /* 0 */ + uint8_t mbz2 : 1; /* 0 */ + uint8_t cylinder_err : 1; /* CE */ + uint8_t write_fault : 1; /* WF */ + uint8_t mbz3 : 1; /* 0 */ + uint8_t seek_end : 1; /* SE */ + uint8_t not_ready : 1; /* NR */ /* Status byte 1. */ - uint8_t id_not_found : 1, /* ID */ - mbz4 : 1, /* 0 */ - mbz5 : 1, /* 0 */ - wrong_cyl : 1, /* WC */ - all_bit_set : 1, /* BT */ - mark_not_found : 1, /* AM */ - ecc_crc_err : 1, /* ET */ - ecc_crc_field : 1; /* EF */ + uint8_t id_not_found : 1; /* ID */ + uint8_t mbz4 : 1; /* 0 */ + uint8_t mbz5 : 1; /* 0 */ + uint8_t wrong_cyl : 1; /* WC */ + uint8_t all_bit_set : 1; /* BT */ + uint8_t mark_not_found : 1; /* AM */ + uint8_t ecc_crc_err : 1; /* ET */ + uint8_t ecc_crc_field : 1; /* EF */ /* Status byte 2. */ - uint8_t headsel_state : 4, /* headsel state[4] */ - defective_sector : 1, /* DS */ - retried_ok : 1, /* RG */ - need_reset : 1, /* RR */ + uint8_t headsel_state : 4; /* headsel state[4] */ + uint8_t defective_sector : 1; /* DS */ + uint8_t retried_ok : 1; /* RG */ + uint8_t need_reset : 1; /* RR */ #if 1 - valid : 1; /* 0 (abused as VALID) */ + uint8_t valid : 1; /* 0 (abused as VALID) */ #else - mbz6 : 1; /* 0 */ + uint8_t mbz6 : 1; /* 0 */ #endif /* Most recent ID field seen. */ - uint8_t last_cyl_low; /* Cyl_Low[8] */ - uint8_t last_head : 4, /* HD[4] */ - mbz7 : 1, /* 0 */ - last_cyl_high : 2, /* Cyl_high[2] */ - last_def_sect : 1; /* DS */ - uint8_t last_sect; /* Sect[8] */ + uint8_t last_cyl_low; /* Cyl_Low[8] */ + uint8_t last_head : 4; /* HD[4] */ + uint8_t mbz7 : 1; /* 0 */ + uint8_t last_cyl_high : 2; /* Cyl_high[2] */ + uint8_t last_def_sect : 1; /* DS */ + uint8_t last_sect; /* Sect[8] */ uint8_t sect_size; /* Size[8] = 02 */ /* Current position. */ - uint8_t curr_cyl_high : 2, /* Cyl_High_[2] */ - mbz8 : 1, /* 0 */ - mbz9 : 1, /* 0 */ - curr_head : 4; /* HD_2[4] */ - uint8_t curr_cyl_low; /* Cyl_Low_2[8] */ + uint8_t curr_cyl_high : 2; /* Cyl_High_[2] */ + uint8_t mbz8 : 1; /* 0 */ + uint8_t mbz9 : 1; /* 0 */ + uint8_t curr_head : 4; /* HD_2[4] */ + uint8_t curr_cyl_low; /* Cyl_Low_2[8] */ uint8_t sect_corr; /* sectors corrected */ @@ -290,21 +290,21 @@ typedef struct { * bits 0. */ #pragma pack(push, 1) -typedef struct { - uint8_t cyl_high : 2, /* cylinder [9:8] bits */ - defective_sector : 1, /* DS */ - mbz1 : 1, /* 0 */ - head : 4; /* head number */ +typedef struct fcb_t { + uint8_t cyl_high : 2; /* cylinder [9:8] bits */ + uint8_t defective_sector : 1; /* DS */ + uint8_t mbz1 : 1; /* 0 */ + uint8_t head : 4; /* head number */ - uint8_t cyl_low; /* cylinder [7:0] bits */ + uint8_t cyl_low; /* cylinder [7:0] bits */ - uint8_t sector; /* sector number */ + uint8_t sector; /* sector number */ - uint8_t mbz2 : 1, /* 0 */ - mbo : 1, /* 1 */ - mbz3 : 6; /* 000000 */ + uint8_t mbz2 : 1; /* 0 */ + uint8_t mbo : 1; /* 1 */ + uint8_t mbz3 : 6; /* 000000 */ - uint8_t fill; /* filler byte */ + uint8_t fill; /* filler byte */ } fcb_t; #pragma pack(pop) @@ -316,31 +316,31 @@ typedef struct { * through a DMA or PIO operation. */ #pragma pack(push, 1) -typedef struct { - uint8_t ec_p : 1, /* EC/P (ecc/park) */ - mbz1 : 1, /* 0 */ - auto_seek : 1, /* AS (auto-seek) */ - no_data : 1, /* ND (no data) */ - cmd : 4; /* command code[4] */ +typedef struct ccb_t{ + uint8_t ec_p : 1; /* EC/P (ecc/park) */ + uint8_t mbz1 : 1; /* 0 */ + uint8_t auto_seek : 1; /* AS (auto-seek) */ + uint8_t no_data : 1; /* ND (no data) */ + uint8_t cmd : 4; /* command code[4] */ - uint8_t cyl_high : 2, /* cylinder [9:8] bits */ - mbz2 : 2, /* 00 */ - head : 4; /* head number */ + uint8_t cyl_high : 2; /* cylinder [9:8] bits */ + uint8_t mbz2 : 2; /* 00 */ + uint8_t head : 4; /* head number */ uint8_t cyl_low; /* cylinder [7:0] bits */ uint8_t sector; /* sector number */ - uint8_t mbz3 : 1, /* 0 */ - mbo1 : 1, /* 1 */ - mbz4 : 6; /* 000000 */ + uint8_t mbz3 : 1; /* 0 */ + uint8_t mbo1 : 1; /* 1 */ + uint8_t mbz4 : 6; /* 000000 */ uint8_t count; /* blk count/interleave */ } ccb_t; #pragma pack(pop) /* Define the hard drive geometry table. */ -typedef struct { +typedef struct geom_t { uint16_t cyl; uint8_t hpc; uint8_t spt; @@ -349,54 +349,54 @@ typedef struct { } geom_t; /* Define an attached drive. */ -typedef struct { - int8_t id, /* drive ID on bus */ - present, /* drive is present */ - hdd_num, /* index to global disk table */ - type; /* drive type ID */ +typedef struct drive_t { + int8_t id; /* drive ID on bus */ + int8_t present; /* drive is present */ + int8_t hdd_num; /* index to global disk table */ + int8_t type; /* drive type ID */ uint16_t cur_cyl; /* last known position of heads */ - uint8_t spt, /* active drive parameters */ - hpc; + uint8_t spt; /* active drive parameters */ + uint8_t hpc; uint16_t tracks; - uint8_t cfg_spt, /* configured drive parameters */ - cfg_hpc; + uint8_t cfg_spt; /* configured drive parameters */ + uint8_t cfg_hpc; uint16_t cfg_tracks; } drive_t; -typedef struct { +typedef struct hdc_t { uint16_t base; /* controller base I/O address */ int8_t irq; /* controller IRQ channel */ int8_t dma; /* controller DMA channel */ /* Registers. */ - uint8_t attn, /* ATTENTION register */ - ctrl, /* Control register (ACR) */ - status, /* Status register (ASR) */ - intstat; /* Interrupt Status register (ISR) */ + uint8_t attn; /* ATTENTION register */ + uint8_t ctrl; /* Control register (ACR) */ + uint8_t status; /* Status register (ASR) */ + uint8_t intstat; /* Interrupt Status register (ISR) */ uint8_t *reg_91; /* handle to system board's register 0x91 */ /* Controller state. */ uint64_t callback; pc_timer_t timer; - int8_t state, /* controller state */ - reset; /* reset state counter */ + int8_t state; /* controller state */ + int8_t reset; /* reset state counter */ /* Data transfer. */ - int16_t buf_idx, /* buffer index and pointer */ - buf_len; + int16_t buf_idx; /* buffer index and pointer */ + int16_t buf_len; uint8_t *buf_ptr; /* Current operation parameters. */ - ssb_t ssb; /* sense block */ - ccb_t ccb; /* command control block */ - uint16_t track; /* requested track# */ - uint8_t head, /* requested head# */ - sector; /* requested sector# */ - int count; /* requested sector count */ + ssb_t ssb; /* sense block */ + ccb_t ccb; /* command control block */ + uint16_t track; /* requested track# */ + uint8_t head; /* requested head# */ + uint8_t sector; /* requested sector# */ + int count; /* requested sector count */ drive_t drives[XTA_NUM]; /* the attached drive(s) */ @@ -602,8 +602,10 @@ do_seek(hdc_t *dev, drive_t *drive, uint16_t cyl) static void do_format(hdc_t *dev, drive_t *drive, ccb_t *ccb) { - int start_cyl, end_cyl; - int intr = 0, val; + int start_cyl; + int end_cyl; + int intr = 0; + int val; off64_t addr; #if 0 fcb_t *fcb; @@ -697,8 +699,9 @@ do_fmt: /* Done with this track. */ dev->state = STATE_FDONE; - /*FALLTHROUGH*/ - +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case STATE_FDONE: /* One more track done. */ if (++start_cyl == end_cyl) { @@ -712,6 +715,9 @@ do_fmt: /* This saves us a LOT of code. */ dev->state = STATE_FINIT; goto do_fmt; + + default: + break; } /* If we errored out, go back idle. */ @@ -870,6 +876,9 @@ do_send: /* This saves us a LOT of code. */ dev->state = STATE_SEND; goto do_send; + + default: + break; } break; @@ -1012,6 +1021,9 @@ do_recv: /* This saves us a LOT of code. */ dev->state = STATE_RECV; goto do_recv; + + default: + break; } break; @@ -1050,7 +1062,7 @@ do_recv: static void hdc_send_ssb(hdc_t *dev) { - drive_t *drive; + const drive_t *drive; /* We only support one drive, really, but ohwell. */ drive = &dev->drives[0]; @@ -1125,6 +1137,9 @@ hdc_read(uint16_t port, void *priv) ret = dev->intstat; dev->intstat = 0x00; break; + + default: + break; } return ret; @@ -1231,11 +1246,14 @@ hdc_write(uint16_t port, uint8_t val, void *priv) set_intr(dev, 1); } break; + + default: + break; } } static void * -ps1_hdc_init(const device_t *info) +ps1_hdc_init(UNUSED(const device_t *info)) { drive_t *drive; hdc_t *dev; @@ -1304,8 +1322,8 @@ ps1_hdc_init(const device_t *info) static void ps1_hdc_close(void *priv) { - hdc_t *dev = (hdc_t *) priv; - drive_t *drive; + hdc_t *dev = (hdc_t *) priv; + const drive_t *drive; /* Remove the I/O handler. */ io_removehandler(dev->base, 5, diff --git a/src/machine/m_ps2_isa.c b/src/machine/m_ps2_isa.c index af4fc5849..fa9c5acc2 100644 --- a/src/machine/m_ps2_isa.c +++ b/src/machine/m_ps2_isa.c @@ -72,6 +72,9 @@ ps2_write(uint16_t port, uint8_t val, void *priv) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2->ps2_102 = val; @@ -93,6 +96,9 @@ ps2_write(uint16_t port, uint8_t val, void *priv) case 0x0190: ps2->ps2_190 = val; break; + + default: + break; } } @@ -131,6 +137,9 @@ ps2_read(uint16_t port, void *priv) case 0x0190: temp = ps2->ps2_190; break; + + default: + break; } return temp; diff --git a/src/machine/m_ps2_mca.c b/src/machine/m_ps2_mca.c index c43f7ef9b..b93f332db 100644 --- a/src/machine/m_ps2_mca.c +++ b/src/machine/m_ps2_mca.c @@ -68,15 +68,16 @@ #include <86box/serial.h> #include <86box/video.h> #include <86box/machine.h> +#include <86box/plat_unused.h> -static struct -{ +static struct ps2_t { uint8_t adapter_setup; uint8_t option[4]; uint8_t pos_vga; uint8_t setup; uint8_t sys_ctrl_port_a; - uint8_t subaddr_lo, subaddr_hi; + uint8_t subaddr_lo; + uint8_t subaddr_hi; uint8_t memory_bank[8]; @@ -88,11 +89,12 @@ static struct mem_mapping_t cache_mapping; uint8_t (*planar_read)(uint16_t port); - void (*planar_write)(uint16_t port, uint8_t val); + void (*planar_write)(uint16_t port, uint8_t val); uint8_t mem_regs[3]; - uint32_t split_addr, split_size; + uint32_t split_addr; + uint32_t split_size; uint32_t split_phys; uint8_t mem_pos_regs[8]; @@ -158,7 +160,7 @@ ps2_mca_log(const char *fmt, ...) #endif static uint8_t -ps2_read_cache_ram(uint32_t addr, void *priv) +ps2_read_cache_ram(uint32_t addr, UNUSED(void *priv)) { ps2_mca_log("ps2_read_cache_ram: addr=%08x %i %04x:%04x\n", addr, ps2_cache_valid[addr >> 3], CS, cpu_state.pc); if (!ps2_cache_valid[addr >> 3]) { @@ -170,7 +172,7 @@ ps2_read_cache_ram(uint32_t addr, void *priv) return ps2_cache[addr]; } static uint16_t -ps2_read_cache_ramw(uint32_t addr, void *priv) +ps2_read_cache_ramw(uint32_t addr, UNUSED(void *priv)) { ps2_mca_log("ps2_read_cache_ramw: addr=%08x %i %04x:%04x\n", addr, ps2_cache_valid[addr >> 3], CS, cpu_state.pc); if (!ps2_cache_valid[addr >> 3]) { @@ -182,7 +184,7 @@ ps2_read_cache_ramw(uint32_t addr, void *priv) return *(uint16_t *) &ps2_cache[addr]; } static uint32_t -ps2_read_cache_raml(uint32_t addr, void *priv) +ps2_read_cache_raml(uint32_t addr, UNUSED(void *priv)) { ps2_mca_log("ps2_read_cache_raml: addr=%08x %i %04x:%04x\n", addr, ps2_cache_valid[addr >> 3], CS, cpu_state.pc); if (!ps2_cache_valid[addr >> 3]) { @@ -194,7 +196,7 @@ ps2_read_cache_raml(uint32_t addr, void *priv) return *(uint32_t *) &ps2_cache[addr]; } static void -ps2_write_cache_ram(uint32_t addr, uint8_t val, void *priv) +ps2_write_cache_ram(uint32_t addr, uint8_t val, UNUSED(void *priv)) { ps2_mca_log("ps2_write_cache_ram: addr=%08x val=%02x %04x:%04x %i\n", addr, val, CS, cpu_state.pc); ps2_cache[addr] = val; @@ -268,6 +270,9 @@ model_50_read(uint16_t port) return ps2.subaddr_lo; case 0x107: return ps2.subaddr_hi; + + default: + break; } return 0xff; } @@ -292,6 +297,9 @@ model_55sx_read(uint16_t port) return ps2.subaddr_lo; case 0x107: return ps2.subaddr_hi; + + default: + break; } return 0xff; } @@ -316,6 +324,9 @@ model_70_type3_read(uint16_t port) return ps2.subaddr_lo; case 0x107: return ps2.subaddr_hi; + + default: + break; } return 0xff; } @@ -340,6 +351,9 @@ model_80_read(uint16_t port) return ps2.subaddr_lo; case 0x107: return ps2.subaddr_hi; + + default: + break; } return 0xff; } @@ -373,6 +387,9 @@ model_50_write(uint16_t port, uint8_t val) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2.option[0] = val; @@ -392,6 +409,9 @@ model_50_write(uint16_t port, uint8_t val) case 0x107: ps2.subaddr_hi = val; break; + + default: + break; } } @@ -458,11 +478,12 @@ model_55sx_mem_recalc(void) mem_set_mem_state(0xe0000, 0x20000, state); - /* if (!(ps2.option[3] & 0x08)) - { +#if 0 + if (!(ps2.option[3] & 0x08)) { ps2_mca_log("Memory not yet configured\n"); return; - } */ + } +#endif ps2_mca_log("Enable shadow mapping at %06X-%06X\n", (mem_size * 1024), (mem_size * 1024) + (remap_size * 1024) - 1); @@ -503,6 +524,9 @@ model_55sx_write(uint16_t port, uint8_t val) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2.option[0] = val; @@ -529,6 +553,9 @@ model_55sx_write(uint16_t port, uint8_t val) case 0x107: ps2.subaddr_hi = val; break; + + default: + break; } } @@ -560,6 +587,9 @@ model_70_type3_write(uint16_t port, uint8_t val) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2.option[0] = val; @@ -581,6 +611,9 @@ model_70_type3_write(uint16_t port, uint8_t val) case 0x107: ps2.subaddr_hi = val; break; + + default: + break; } } @@ -612,6 +645,9 @@ model_80_write(uint16_t port, uint8_t val) case 2: lpt1_init(LPT2_ADDR); break; + + default: + break; } } ps2.option[0] = val; @@ -631,17 +667,22 @@ model_80_write(uint16_t port, uint8_t val) case 0x107: ps2.subaddr_hi = val; break; + + default: + break; } } uint8_t -ps2_mca_read(uint16_t port, void *p) +ps2_mca_read(uint16_t port, UNUSED(void *priv)) { uint8_t temp; switch (port) { case 0x91: - // fatal("Read 91 setup=%02x adapter=%02x\n", ps2.setup, ps2.adapter_setup); +#if 0 + fatal("Read 91 setup=%02x adapter=%02x\n", ps2.setup, ps2.adapter_setup); +#endif if (!(ps2.setup & PS2_SETUP_IO)) temp = 0x00; else if (!(ps2.setup & PS2_SETUP_VGA)) @@ -740,7 +781,7 @@ ps2_mca_read(uint16_t port, void *p) } static void -ps2_mca_write(uint16_t port, uint8_t val, void *p) +ps2_mca_write(uint16_t port, uint8_t val, UNUSED(void *priv)) { ps2_mca_log("ps2_write: port=%04x val=%02x %04x:%04x\n", port, val, CS, cpu_state.pc); @@ -763,7 +804,7 @@ ps2_mca_write(uint16_t port, uint8_t val, void *p) case 0x101: if (!(ps2.setup & PS2_SETUP_IO)) ps2.planar_write(port, val); - else if ((ps2.setup & PS2_SETUP_VGA) && (ps2.setup & PS2_SETUP_VGA) && (ps2.adapter_setup & PS2_ADAPTER_SETUP)) + else if ((ps2.setup & PS2_SETUP_VGA) && (ps2.adapter_setup & PS2_ADAPTER_SETUP)) mca_write(port, val); break; case 0x102: @@ -804,6 +845,9 @@ ps2_mca_write(uint16_t port, uint8_t val, void *p) else if (ps2.adapter_setup & PS2_ADAPTER_SETUP) mca_write(port, val); break; + + default: + break; } } @@ -824,13 +868,13 @@ ps2_mca_board_common_init(void) } static uint8_t -ps2_mem_expansion_read(int port, void *p) +ps2_mem_expansion_read(int port, UNUSED(void *priv)) { return ps2.mem_pos_regs[port & 7]; } static void -ps2_mem_expansion_write(int port, uint8_t val, void *p) +ps2_mem_expansion_write(int port, uint8_t val, UNUSED(void *priv)) { if (port < 0x102 || port == 0x104) return; @@ -844,7 +888,7 @@ ps2_mem_expansion_write(int port, uint8_t val, void *p) } static uint8_t -ps2_mem_expansion_feedb(void *p) +ps2_mem_expansion_feedb(UNUSED(void *priv)) { return (ps2.mem_pos_regs[2] & 1); } @@ -888,6 +932,9 @@ ps2_mca_mem_fffc_init(int start_mb) case 8: ps2.mem_pos_regs[4] = 0xaa; /* 10 10 10 10 = 2 2 2 2 */ break; + + default: + break; } mca_add(ps2_mem_expansion_read, ps2_mem_expansion_write, ps2_mem_expansion_feedb, NULL, NULL); @@ -988,9 +1035,6 @@ ps2_mca_board_model_55sx_init(int has_sec_nvram, int slots) ps2.memory_bank[1] = 0x61; break; case 6: - ps2.memory_bank[0] = 0x01; - ps2.memory_bank[1] = 0x51; - break; case 7: /*Not supported*/ ps2.memory_bank[0] = 0x01; ps2.memory_bank[1] = 0x51; @@ -999,6 +1043,9 @@ ps2_mca_board_model_55sx_init(int has_sec_nvram, int slots) ps2.memory_bank[0] = 0x01; ps2.memory_bank[1] = 0x01; break; + + default: + break; } mca_init(slots); @@ -1071,18 +1118,21 @@ mem_encoding_update(void) } static uint8_t -mem_encoding_read(uint16_t addr, void *p) +mem_encoding_read(uint16_t addr, UNUSED(void *priv)) { switch (addr) { case 0xe0: return ps2.mem_regs[0]; case 0xe1: return ps2.mem_regs[1]; + + default: + break; } return 0xff; } static void -mem_encoding_write(uint16_t addr, uint8_t val, void *p) +mem_encoding_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { switch (addr) { case 0xe0: @@ -1091,12 +1141,15 @@ mem_encoding_write(uint16_t addr, uint8_t val, void *p) case 0xe1: ps2.mem_regs[1] = val; break; + + default: + break; } mem_encoding_update(); } static uint8_t -mem_encoding_read_cached(uint16_t addr, void *p) +mem_encoding_read_cached(uint16_t addr, UNUSED(void *priv)) { switch (addr) { case 0xe0: @@ -1105,12 +1158,15 @@ mem_encoding_read_cached(uint16_t addr, void *p) return ps2.mem_regs[1]; case 0xe2: return ps2.mem_regs[2]; + + default: + break; } return 0xff; } static void -mem_encoding_write_cached(uint16_t addr, uint8_t val, void *p) +mem_encoding_write_cached(uint16_t addr, uint8_t val, UNUSED(void *priv)) { uint8_t old; @@ -1145,6 +1201,9 @@ mem_encoding_write_cached(uint16_t addr, uint8_t val, void *p) ram_mid_mapping.flags &= ~MEM_MAPPING_ROM_WS; #endif break; + + default: + break; } ps2_mca_log("mem_encoding_write: addr=%02x val=%02x %04x:%04x %02x %02x\n", addr, val, CS, cpu_state.pc, ps2.mem_regs[1], ps2.mem_regs[2]); mem_encoding_update(); @@ -1253,7 +1312,7 @@ ps2_mca_board_model_70_type34_init(int is_type4, int slots) } static void -ps2_mca_board_model_80_type2_init(int is486) +ps2_mca_board_model_80_type2_init(int is486ps2) { ps2_mca_board_common_init(); @@ -1313,7 +1372,7 @@ ps2_mca_board_model_80_type2_init(int is486) NULL); mem_mapping_disable(&ps2.split_mapping); - if ((mem_size > 4096) && !is486) { + if ((mem_size > 4096) && !is486ps2) { /* Only 4 MB supported on planar, create a memory expansion card for the rest */ if (mem_size > 12288) ps2_mca_mem_d071_init(4); diff --git a/src/machine/m_tandy.c b/src/machine/m_tandy.c index 24ecc654a..5784eb4df 100644 --- a/src/machine/m_tandy.c +++ b/src/machine/m_tandy.c @@ -43,6 +43,7 @@ #include <86box/video.h> #include <86box/vid_cga_comp.h> #include <86box/machine.h> +#include <86box/plat_unused.h> enum { TANDY_RGB = 0, @@ -62,7 +63,7 @@ enum { EEPROM_WRITE }; -typedef struct { +typedef struct t1kvid_t { mem_mapping_t mapping; mem_mapping_t vram_mapping; @@ -72,36 +73,41 @@ typedef struct { int array_index; uint8_t array[256]; int memctrl; - uint8_t mode, col; + uint8_t mode; + uint8_t col; uint8_t stat; - uint8_t *vram, *b8000; + uint8_t *vram; + uint8_t *b8000; uint32_t b8000_mask; uint32_t b8000_limit; uint8_t planar_ctrl; - int linepos, - displine; - int sc, vc; - int dispon; - int con, coff, - cursoron, - blink; + int linepos; + int displine; + int sc; + int vc; + int dispon; + int con; + int coff; + int cursoron; + int blink; int fullchange; int vsynctime; int vadj; - uint16_t ma, maback; + uint16_t ma; + uint16_t maback; - uint64_t dispontime, - dispofftime; + uint64_t dispontime; + uint64_t dispofftime; pc_timer_t timer; - int firstline, - lastline; + int firstline; + int lastline; int composite; } t1kvid_t; -typedef struct { +typedef struct t1keep_t { char *path; int state; @@ -112,7 +118,7 @@ typedef struct { uint16_t store[64]; } t1keep_t; -typedef struct { +typedef struct tandy_t { mem_mapping_t ram_mapping; mem_mapping_t rom_mapping; /* SL2 */ @@ -573,15 +579,18 @@ vid_out(uint16_t addr, uint8_t val, void *priv) vid->planar_ctrl = val; recalc_mapping(dev); break; + + default: + break; } } static uint8_t vid_in(uint16_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; - t1kvid_t *vid = dev->vid; - uint8_t ret = 0xff; + const tandy_t *dev = (tandy_t *) priv; + const t1kvid_t *vid = dev->vid; + uint8_t ret = 0xff; if ((addr >= 0x3d0) && (addr <= 0x3d7)) addr = (addr & 0xff9) | 0x004; @@ -598,6 +607,9 @@ vid_in(uint16_t addr, void *priv) case 0x03da: ret = vid->stat; break; + + default: + break; } return ret; @@ -627,8 +639,8 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t vid_read(uint32_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; - t1kvid_t *vid = dev->vid; + const tandy_t *dev = (tandy_t *) priv; + const t1kvid_t *vid = dev->vid; if (vid->memctrl == -1) return 0xff; @@ -696,7 +708,7 @@ vid_poll(void *priv) } 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; + 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; } @@ -773,7 +785,7 @@ vid_poll(void *priv) } if (drawcursor) { for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 3) + c + 8] ^= 15; + buffer32->line[vid->displine << 1][(x << 3) + c + 8] ^= 15; buffer32->line[(vid->displine << 1) + 1][(x << 3) + c + 8] ^= 15; } } @@ -796,19 +808,19 @@ vid_poll(void *priv) vid->ma++; if (vid->sc & 8) { for (c = 0; c < 8; c++) - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = cols[0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = cols[0]; } else { for (c = 0; c < 8; c++) { if (vid->sc == 8) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][7] & (1 << (c ^ 7))) ? 1 : 0]; } else { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[(fontdat[chr][vid->sc & 7] & (1 << (c ^ 7))) ? 1 : 0]; } } } if (drawcursor) { for (c = 0; c < 16; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + c + 8] ^= 15; + buffer32->line[vid->displine << 1][(x << 4) + c + 8] ^= 15; buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] ^= 15; } } @@ -837,7 +849,7 @@ vid_poll(void *priv) dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000) + 1]; vid->ma++; for (c = 0; c < 8; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1)][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; + buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 8] = buffer32->line[vid->displine << 1][(x << 4) + (c << 1) + 1 + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + (c << 1) + 1 + 8] = cols[dat >> 14]; dat <<= 2; } } @@ -848,7 +860,7 @@ vid_poll(void *priv) dat = (vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000)] << 8) | vid->vram[((vid->ma << 1) & 0x1fff) + ((vid->sc & 1) * 0x2000) + 1]; vid->ma++; for (c = 0; c < 16; c++) { - buffer32->line[(vid->displine << 1)][(x << 4) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; + buffer32->line[vid->displine << 1][(x << 4) + c + 8] = buffer32->line[(vid->displine << 1) + 1][(x << 4) + c + 8] = cols[dat >> 15]; dat <<= 1; } } @@ -879,7 +891,7 @@ vid_poll(void *priv) else x = (vid->crtc[1] << 4) + 16; if (!dev->is_sl2 && vid->composite) { - Composite_Process(vid->mode, 0, x >> 2, buffer32->line[(vid->displine << 1)]); + Composite_Process(vid->mode, 0, x >> 2, buffer32->line[vid->displine << 1]); Composite_Process(vid->mode, 0, x >> 2, buffer32->line[(vid->displine << 1) + 1]); } else { video_process_8(x, vid->displine << 1); @@ -967,7 +979,7 @@ vid_poll(void *priv) if (!enable_overscan) xs_temp -= 16; - if (((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get())) { + if ((xs_temp != xsize) || (ys_temp != ysize) || video_force_resize_get()) { xsize = xs_temp; ysize = ys_temp; set_screen_size(xsize, ysize + (enable_overscan ? 16 : 0)); @@ -1021,7 +1033,7 @@ vid_poll(void *priv) vid->sc &= 31; vid->ma = vid->maback; } - if ((vid->sc == (vid->crtc[10] & 31) || ((vid->crtc[8] & 3) == 3 && vid->sc == ((vid->crtc[10] & 31) >> 1)))) + if (vid->sc == (vid->crtc[10] & 31) || ((vid->crtc[8] & 3) == 3 && vid->sc == ((vid->crtc[10] & 31) >> 1))) vid->con = 1; } } @@ -1139,7 +1151,7 @@ const device_t vid_device_sl = { }; static void -eep_write(uint16_t addr, uint8_t val, void *priv) +eep_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { t1keep_t *eep = (t1keep_t *) priv; @@ -1166,6 +1178,9 @@ eep_write(uint16_t addr, uint8_t val, void *priv) eep->state = EEPROM_GET_OPERATION; eep->count = 0; break; + + default: + break; } break; @@ -1211,6 +1226,9 @@ eep_write(uint16_t addr, uint8_t val, void *priv) eep->store[eep->addr] = eep->data; } break; + + default: + break; } eep->clk = val & 4; @@ -1233,6 +1251,9 @@ eep_init(const device_t *info) case TYPE_TANDY1000SL2: eep->path = "tandy1000sl2.bin"; break; + + default: + break; } f = nvr_fopen(eep->path, "rb"); @@ -1319,14 +1340,18 @@ tandy_write(uint16_t addr, uint8_t val, void *priv) dev->rom_offset = ((val ^ 4) & 7) * 0x10000; mem_mapping_set_exec(&dev->rom_mapping, &dev->rom[dev->rom_offset]); + break; + + default: + break; } } static uint8_t tandy_read(uint16_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; - uint8_t ret = 0xff; + const tandy_t *dev = (tandy_t *) priv; + uint8_t ret = 0xff; switch (addr) { case 0x00a0: @@ -1340,6 +1365,9 @@ tandy_read(uint16_t addr, void *priv) case 0xffea: ret = (dev->rom_bank ^ 0x10); break; + + default: + break; } return ret; @@ -1348,7 +1376,7 @@ tandy_read(uint16_t addr, void *priv) static void write_ram(uint32_t addr, uint8_t val, void *priv) { - tandy_t *dev = (tandy_t *) priv; + const tandy_t *dev = (tandy_t *) priv; ram[dev->base + (addr & 0x1ffff)] = val; } @@ -1356,7 +1384,7 @@ write_ram(uint32_t addr, uint8_t val, void *priv) static uint8_t read_ram(uint32_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; + const tandy_t *dev = (tandy_t *) priv; return (ram[dev->base + (addr & 0x1ffff)]); } @@ -1364,8 +1392,8 @@ read_ram(uint32_t addr, void *priv) static uint8_t read_rom(uint32_t addr, void *priv) { - tandy_t *dev = (tandy_t *) priv; - uint32_t addr2 = (addr & 0xffff) + dev->rom_offset; + const tandy_t *dev = (tandy_t *) priv; + uint32_t addr2 = (addr & 0xffff) + dev->rom_offset; return (dev->rom[addr2]); } @@ -1475,6 +1503,9 @@ machine_tandy1k_init(const machine_t *model, int type) device_add(&pssj_device); device_add(&eep_1000sl2_device); break; + + default: + break; } standalone_gameport_type = &gameport_device; diff --git a/src/machine/m_v86p.c b/src/machine/m_v86p.c index 62b6e4834..54af9b053 100644 --- a/src/machine/m_v86p.c +++ b/src/machine/m_v86p.c @@ -52,7 +52,7 @@ int machine_v86p_init(const machine_t *model) { int ret; - int rom = 0; + int rom_id = 0; ret = bios_load_interleavedr("roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_122089_Even.rom", "roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_122089_Odd.rom", @@ -60,7 +60,7 @@ machine_v86p_init(const machine_t *model) if (!ret) { /* Try an older version of the BIOS. */ - rom = 1; + rom_id = 1; ret = bios_load_interleavedr("roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_090489_Even.rom", "roms/machines/v86p/INTEL8086AWD_BIOS_S3.1_V86P_090489_Odd.rom", 0x000f8000, 65536, 0); @@ -68,7 +68,7 @@ machine_v86p_init(const machine_t *model) if (!ret) { /* Try JVERNET's BIOS. */ - rom = 2; + rom_id = 2; ret = bios_load_linear("roms/machines/v86p/V86P.ROM", 0x000f0000, 65536, 0); } @@ -76,7 +76,7 @@ machine_v86p_init(const machine_t *model) if (bios_only || !ret) return ret; - if (rom == 2) + if (rom_id == 2) loadfont("roms/machines/v86p/V86P.FON", 8); else loadfont("roms/machines/v86p/v86pfont.rom", 8); diff --git a/src/machine/m_xt_laserxt.c b/src/machine/m_xt_laserxt.c index 59db0cbe0..87c2fe362 100644 --- a/src/machine/m_xt_laserxt.c +++ b/src/machine/m_xt_laserxt.c @@ -19,6 +19,7 @@ #include <86box/fdc_ext.h> #include <86box/gameport.h> #include <86box/keyboard.h> +#include <86box/plat_unused.h> static int laserxt_emspage[4]; static int laserxt_emscontrol[4]; @@ -37,7 +38,7 @@ get_laserxt_ems_addr(uint32_t addr) } static void -laserxt_write(uint16_t port, uint8_t val, void *priv) +laserxt_write(uint16_t port, uint8_t val, UNUSED(void *priv)) { uint32_t paddr; uint32_t vaddr; @@ -73,11 +74,14 @@ laserxt_write(uint16_t port, uint8_t val, void *priv) mem_mapping_set_addr(&laserxt_ems_mapping[3], 0xCC000 + (((laserxt_ems_baseaddr_index + 1) & 0x0C) << 14), 0x4000); flushmmucache(); break; + + default: + break; } } static uint8_t -laserxt_read(uint16_t port, void *priv) +laserxt_read(uint16_t port, UNUSED(void *priv)) { switch (port) { case 0x0208: @@ -90,13 +94,15 @@ laserxt_read(uint16_t port, void *priv) case 0x8209: case 0xC209: return laserxt_emscontrol[port >> 14]; + + default: break; } return 0xff; } static void -mem_write_laserxtems(uint32_t addr, uint8_t val, void *priv) +mem_write_laserxtems(uint32_t addr, uint8_t val, UNUSED(void *priv)) { addr = get_laserxt_ems_addr(addr); if (addr < (mem_size << 10)) @@ -104,7 +110,7 @@ mem_write_laserxtems(uint32_t addr, uint8_t val, void *priv) } static uint8_t -mem_read_laserxtems(uint32_t addr, void *priv) +mem_read_laserxtems(uint32_t addr, UNUSED(void *priv)) { uint8_t val = 0xFF; addr = get_laserxt_ems_addr(addr); diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c index 4d6522295..0a638ce37 100644 --- a/src/machine/m_xt_olivetti.c +++ b/src/machine/m_xt_olivetti.c @@ -57,6 +57,7 @@ #include <86box/vid_ogc.h> #include <86box/vid_colorplus.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> #define STAT_PARITY 0x80 #define STAT_RTIMEOUT 0x40 @@ -115,7 +116,7 @@ enum MM58274_ADDR { static struct tm intclk; -typedef struct { +typedef struct m24_kbd_t { /* Keyboard stuff. */ int wantirq; uint8_t command; @@ -123,18 +124,20 @@ typedef struct { uint8_t out; uint8_t output_port; uint8_t id; - int param, - param_total; + int param; + int param_total; uint8_t params[16]; uint8_t scan[7]; /* Mouse stuff. */ int mouse_mode; - int x, y, b; + int x; + int y; + int b; pc_timer_t send_delay_timer; } m24_kbd_t; -typedef struct { +typedef struct m19_vid_t { ogc_t ogc; colorplus_t colorplus; int mode; @@ -439,7 +442,7 @@ mm58274_write(uint16_t addr, uint8_t val, void *priv) static uint8_t mm58274_read(uint16_t addr, void *priv) { - nvr_t *nvr = (nvr_t *) priv; + const nvr_t *nvr = (nvr_t *) priv; addr &= 0x0f; @@ -635,6 +638,10 @@ m24_kbd_write(uint16_t port, uint8_t val, void *priv) if (val == 0x02) m24_kbd_adddata(0x00); + break; + + default: + break; } } @@ -725,7 +732,7 @@ m24_kbd_reset(void *priv) } static int -ms_poll(int x, int y, int z, int b, void *priv) +ms_poll(int x, int y, UNUSED(int z), int b, void *priv) { m24_kbd_t *m24_kbd = (m24_kbd_t *) priv; @@ -1492,12 +1499,16 @@ m19_vid_init(m19_vid_t *vid) { device_context(&m19_vid_device); - /* int display_type; */ +#if 0 + int display_type; +#endif vid->mode = OLIVETTI_OGC_MODE; video_inform(VIDEO_FLAG_TYPE_CGA, &timing_m19_vid); - /* display_type = device_get_config_int("display_type"); */ +#if 0 + display_type = device_get_config_int("display_type"); +#endif /* OGC emulation part begin */ loadfont_ex("roms/machines/m19/BIOS.BIN", 1, 90); @@ -1508,7 +1519,9 @@ m19_vid_init(m19_vid_t *vid) vid->ogc.cga.vram = malloc(0x8000); - /* cga_comp_init(vid->ogc.cga.revision); */ +#if 0 + cga_comp_init(vid->ogc.cga.revision); +#endif vid->ogc.cga.rgb_type = device_get_config_int("rgb_type"); cga_palette = (vid->ogc.cga.rgb_type << 1); @@ -1525,11 +1538,15 @@ m19_vid_init(m19_vid_t *vid) /* Plantronics emulation part begin*/ /* composite is not working yet */ vid->colorplus.cga.composite = 0; //(display_type != CGA_RGB); - /* vid->colorplus.cga.snow_enabled = device_get_config_int("snow_enabled"); */ +#if 0 + vid->colorplus.cga.snow_enabled = device_get_config_int("snow_enabled"); +#endif vid->colorplus.cga.vram = malloc(0x8000); - /* vid->colorplus.cga.cgamode = 0x1; */ +#if 0 + vid->colorplus.cga.cgamode = 0x1; +#endif /* Plantronics emulation part end*/ timer_add(&vid->ogc.cga.timer, ogc_poll, &vid->ogc, 1); @@ -1602,7 +1619,7 @@ const device_t m19_vid_device = { }; static uint8_t -m24_read(uint16_t port, void *priv) +m24_read(uint16_t port, UNUSED(void *priv)) { uint8_t ret = 0x00; int fdd_count = 0; @@ -1706,13 +1723,16 @@ m24_read(uint16_t port, void *priv) /* 1 = 720 kB (3.5"), 0 = 360 kB (5.25") */ ret |= (fdd_doublestep_40(0) || fdd_doublestep_40(1)) ? 0x1 : 0x0; break; + + default: + break; } return ret; } static uint8_t -m240_read(uint16_t port, void *priv) +m240_read(uint16_t port, UNUSED(void *priv)) { uint8_t ret = 0x00; int fdd_count = 0; @@ -1761,6 +1781,9 @@ m240_read(uint16_t port, void *priv) ret |= fdd_doublestep_40(1) ? 0x40 : 0x00; ret |= fdd_doublestep_40(0) ? 0x20 : 0x00; break; + + default: + break; } return ret; diff --git a/src/machine/m_xt_philips.c b/src/machine/m_xt_philips.c index bc1b6f792..4caff1431 100644 --- a/src/machine/m_xt_philips.c +++ b/src/machine/m_xt_philips.c @@ -39,9 +39,9 @@ #include <86box/chipset.h> #include <86box/io.h> #include <86box/video.h> +#include <86box/plat_unused.h> -typedef struct -{ +typedef struct philips_t { uint8_t reg; } philips_t; @@ -80,6 +80,9 @@ philips_write(uint16_t port, uint8_t val, void *priv) else cpu_dynamic_switch(0); break; + + default: + break; } philips_log("Philips XT Mainboard: Write %02x at %02x\n", val, port); @@ -100,6 +103,9 @@ philips_read(uint16_t port, void *priv) case 0xc0: ret = dev->reg; break; + + default: + break; } philips_log("Philips XT Mainboard: Read %02x at %02x\n", ret, port); @@ -116,7 +122,7 @@ philips_close(void *priv) } static void * -philips_init(const device_t *info) +philips_init(UNUSED(const device_t *info)) { philips_t *dev = (philips_t *) malloc(sizeof(philips_t)); memset(dev, 0, sizeof(philips_t)); diff --git a/src/machine/m_xt_t1000.c b/src/machine/m_xt_t1000.c index 755840599..2880f4201 100644 --- a/src/machine/m_xt_t1000.c +++ b/src/machine/m_xt_t1000.c @@ -135,7 +135,7 @@ enum TC8521_ADDR { TC8521_LEAPYEAR = 0x1B }; -typedef struct { +typedef struct t1000_t { /* ROM drive */ uint8_t *romdrive; uint8_t rom_ctl; @@ -237,7 +237,7 @@ tc8521_time_get(uint8_t *regs, struct tm *tm) /* This is called every second through the NVR/RTC hook. */ static void -tc8521_tick(nvr_t *nvr) +tc8521_tick(UNUSED(nvr_t *nvr)) { t1000_log("TC8521: ping\n"); } @@ -288,8 +288,8 @@ tc8521_write(uint16_t addr, uint8_t val, void *priv) static uint8_t tc8521_read(uint16_t addr, void *priv) { - nvr_t *nvr = (nvr_t *) priv; - uint8_t page; + const nvr_t *nvr = (nvr_t *) priv; + uint8_t page; /* Get to the correct register page. */ addr &= 0x0f; @@ -336,7 +336,7 @@ tc8521_init(nvr_t *nvr, int size) /* Given an EMS page ID, return its physical address in RAM. */ static uint32_t -ems_execaddr(t1000_t *sys, int pg, uint16_t val) +ems_execaddr(t1000_t *sys, UNUSED(int pg), uint16_t val) { if (!(val & 0x80)) return 0; /* Bit 7 reset => not mapped */ @@ -360,7 +360,7 @@ ems_execaddr(t1000_t *sys, int pg, uint16_t val) static uint8_t ems_in(uint16_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; #if 0 t1000_log("ems_in(%04x)=%02x\n", addr, sys->ems_reg[(addr >> 14) & 3]); @@ -467,7 +467,7 @@ addr_to_page(uint32_t addr) static uint8_t ems_read_ram(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; int pg = addr_to_page(addr); if (pg < 0) @@ -480,8 +480,8 @@ ems_read_ram(uint32_t addr, void *priv) static uint16_t ems_read_ramw(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) return 0xff; @@ -501,8 +501,8 @@ ems_read_ramw(uint32_t addr, void *priv) static uint32_t ems_read_raml(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) return 0xff; @@ -515,8 +515,8 @@ ems_read_raml(uint32_t addr, void *priv) static void ems_write_ram(uint32_t addr, uint8_t val, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -531,8 +531,8 @@ ems_write_ram(uint32_t addr, uint8_t val, void *priv) static void ems_write_ramw(uint32_t addr, uint16_t val, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -555,8 +555,8 @@ ems_write_ramw(uint32_t addr, uint16_t val, void *priv) static void ems_write_raml(uint32_t addr, uint32_t val, void *priv) { - t1000_t *sys = (t1000_t *) priv; - int pg = addr_to_page(addr); + const t1000_t *sys = (t1000_t *) priv; + int pg = addr_to_page(addr); if (pg < 0) return; @@ -571,8 +571,8 @@ ems_write_raml(uint32_t addr, uint32_t val, void *priv) static uint8_t read_ctl(uint16_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; - uint8_t ret = 0xff; + const t1000_t *sys = (t1000_t *) priv; + uint8_t ret = 0xff; switch (addr & 0x0f) { case 1: @@ -595,6 +595,9 @@ read_ctl(uint16_t addr, void *priv) case 0x52: ret = (sys->is_640k ? 0x80 : 0); break; + + default: + break; } break; @@ -656,8 +659,14 @@ write_ctl(uint16_t addr, uint8_t val, void *priv) case 0x52: ems_set_640k(sys, val); break; + + default: + break; } break; + + default: + break; } } @@ -689,6 +698,9 @@ t1000_read_nvram(uint16_t addr, void *priv) tmp |= 0x2e; /* Bits 5, 3, 2, 1 always 1 */ tmp |= (sys->nvr_active & 0x40) >> 6; /* Ready state */ break; + + default: + break; } return tmp; @@ -733,13 +745,16 @@ t1000_write_nvram(uint16_t addr, uint8_t val, void *priv) if (val == 0x80) sys->nvr_addr = -1; break; + + default: + break; } } static uint8_t read_t1200_nvram(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; return sys->t1200_nvram[addr & 0x7FF]; } @@ -757,15 +772,15 @@ write_t1200_nvram(uint32_t addr, uint8_t value, void *priv) /* Port 0xC8 controls the ROM drive */ static uint8_t -t1000_read_rom_ctl(uint16_t addr, void *priv) +t1000_read_rom_ctl(UNUSED(uint16_t addr), void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; return (sys->rom_ctl); } static void -t1000_write_rom_ctl(uint16_t addr, uint8_t val, void *priv) +t1000_write_rom_ctl(UNUSED(uint16_t addr), uint8_t val, void *priv) { t1000_t *sys = (t1000_t *) priv; @@ -785,7 +800,7 @@ t1000_write_rom_ctl(uint16_t addr, uint8_t val, void *priv) static uint8_t t1000_read_rom(uint32_t addr, void *priv) { - t1000_t *sys = (t1000_t *) priv; + const t1000_t *sys = (t1000_t *) priv; if (!sys->romdrive) return 0xff; diff --git a/src/machine/m_xt_t1000_vid.c b/src/machine/m_xt_t1000_vid.c index 45a15649d..006698869 100644 --- a/src/machine/m_xt_t1000_vid.c +++ b/src/machine/m_xt_t1000_vid.c @@ -51,12 +51,14 @@ #include <86box/video.h> #include <86box/vid_cga.h> #include <86box/m_xt_t1000.h> +#include <86box/plat_unused.h> #define T1000_XSIZE 640 #define T1000_YSIZE 200 /* Mapping of attributes to colours */ -static uint32_t blue, grey; +static uint32_t blue; +static uint32_t grey; static uint8_t boldcols[256]; /* Which attributes use the bold font */ static uint32_t blinkcols[256][2]; static uint32_t normcols[256][2]; @@ -124,14 +126,14 @@ typedef struct t1000_t { } t1000_t; static void t1000_recalctimings(t1000_t *t1000); -static void t1000_write(uint32_t addr, uint8_t val, void *p); -static uint8_t t1000_read(uint32_t addr, void *p); +static void t1000_write(uint32_t addr, uint8_t val, void *priv); +static uint8_t t1000_read(uint32_t addr, void *priv); static void t1000_recalcattrs(t1000_t *t1000); static void -t1000_out(uint16_t addr, uint8_t val, void *p) +t1000_out(uint16_t addr, uint8_t val, void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; switch (addr) { /* Emulated CRTC, register select */ case 0x3d0: @@ -158,21 +160,20 @@ t1000_out(uint16_t addr, uint8_t val, void *p) t1000_recalctimings(t1000); return; - /* CGA control register */ - case 0x3D8: - cga_out(addr, val, &t1000->cga); - return; - /* CGA colour register */ - case 0x3D9: + case 0x3D8: /* CGA control register */ + case 0x3D9: /* CGA colour register */ cga_out(addr, val, &t1000->cga); return; + + default: + break; } } static uint8_t -t1000_in(uint16_t addr, void *p) +t1000_in(uint16_t addr, void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; uint8_t val; switch (addr) { @@ -186,24 +187,29 @@ t1000_in(uint16_t addr, void *p) val |= 0x20; /* LCD / CRT */ return val; } + break; + + default: + break; } return cga_in(addr, &t1000->cga); } static void -t1000_write(uint32_t addr, uint8_t val, void *p) +t1000_write(uint32_t addr, uint8_t val, void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; t1000->vram[addr & 0x3fff] = val; cycles -= 4; } static uint8_t -t1000_read(uint32_t addr, void *p) +t1000_read(uint32_t addr, void *priv) { - t1000_t *t1000 = (t1000_t *) p; + const t1000_t *t1000 = (t1000_t *) priv; + cycles -= 4; return t1000->vram[addr & 0x3fff]; @@ -213,7 +219,8 @@ static void t1000_recalctimings(t1000_t *t1000) { double disptime; - double _dispontime, _dispofftime; + double _dispontime; + double _dispofftime; if (!t1000->internal) { cga_recalctimings(&t1000->cga); @@ -231,7 +238,6 @@ static void t1000_text_row80(t1000_t *t1000) { uint32_t cols[2]; - int c; uint8_t chr; uint8_t attr; int drawcursor; @@ -277,12 +283,12 @@ t1000_text_row80(t1000_t *t1000) cols[0] = normcols[attr][0]; } if (drawcursor) { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); } } else { - for (c = 0; c < 8; c++) - ((uint32_t *) buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) + (buffer32->line[t1000->displine])[(x << 3) + c] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; } ++ma; } @@ -293,8 +299,8 @@ static void t1000_text_row40(t1000_t *t1000) { uint32_t cols[2]; - int x, c; - uint8_t chr, attr; + uint8_t chr; + uint8_t attr; int drawcursor; int cursorline; int bold; @@ -313,7 +319,7 @@ t1000_text_row40(t1000_t *t1000) } else { cursorline = ((t1000->cga.crtc[10] & 0x0F) <= sc) && ((t1000->cga.crtc[11] & 0x0F) >= sc); } - for (x = 0; x < 40; x++) { + for (uint8_t x = 0; x < 40; x++) { chr = t1000->vram[(addr + 2 * x) & 0x3FFF]; attr = t1000->vram[(addr + 2 * x + 1) & 0x3FFF]; drawcursor = ((ma == ca) && cursorline && (t1000->cga.cgamode & 8) && (t1000->cga.cgablink & 16)); @@ -338,12 +344,12 @@ t1000_text_row40(t1000_t *t1000) cols[0] = normcols[attr][0]; } if (drawcursor) { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t1000->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[t1000->displine])[(x << 4) + c * 2] = (buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0] ^ (blue ^ grey); } } else { - for (c = 0; c < 8; c++) { - ((uint32_t *) buffer32->line[t1000->displine])[(x << 4) + c * 2] = ((uint32_t *) buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; + for (uint8_t c = 0; c < 8; c++) { + (buffer32->line[t1000->displine])[(x << 4) + c * 2] = (buffer32->line[t1000->displine])[(x << 4) + c * 2 + 1] = cols[(fontdat[bold][sc] & (1 << (c ^ 7))) ? 1 : 0]; } } ++ma; @@ -354,7 +360,6 @@ t1000_text_row40(t1000_t *t1000) static void t1000_cgaline6(t1000_t *t1000) { - int x, c; uint8_t dat; uint32_t ink = 0; uint16_t addr; @@ -365,15 +370,15 @@ t1000_cgaline6(t1000_t *t1000) addr = ((t1000->displine) & 1) * 0x2000 + (t1000->displine >> 1) * 80 + ((ma & ~1) << 1); - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = t1000->vram[addr & 0x3FFF]; addr++; - for (c = 0; c < 8; c++) { + for (uint8_t c = 0; c < 8; c++) { ink = (dat & 0x80) ? fg : bg; if (!(t1000->cga.cgamode & 8)) ink = grey; - ((uint32_t *) buffer32->line[t1000->displine])[x * 8 + c] = ink; + (buffer32->line[t1000->displine])[x * 8 + c] = ink; dat = dat << 1; } } @@ -384,19 +389,20 @@ t1000_cgaline6(t1000_t *t1000) static void t1000_cgaline4(t1000_t *t1000) { - int x, c; - uint8_t dat, pattern; - uint32_t ink0, ink1; + uint8_t dat; + uint8_t pattern; + uint32_t ink0; + uint32_t ink1; uint16_t addr; uint16_t ma = (t1000->cga.crtc[13] | (t1000->cga.crtc[12] << 8)) & 0x3fff; addr = ((t1000->displine) & 1) * 0x2000 + (t1000->displine >> 1) * 80 + ((ma & ~1) << 1); - for (x = 0; x < 80; x++) { + for (uint8_t x = 0; x < 80; x++) { dat = t1000->vram[addr & 0x3FFF]; addr++; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { pattern = (dat & 0xC0) >> 6; if (!(t1000->cga.cgamode & 8)) pattern = 0; @@ -428,17 +434,17 @@ t1000_cgaline4(t1000_t *t1000) ink0 = ink1 = blue; break; } - ((uint32_t *) buffer32->line[t1000->displine])[x * 8 + 2 * c] = ink0; - ((uint32_t *) buffer32->line[t1000->displine])[x * 8 + 2 * c + 1] = ink1; - dat = dat << 2; + (buffer32->line[t1000->displine])[x * 8 + 2 * c] = ink0; + (buffer32->line[t1000->displine])[x * 8 + 2 * c + 1] = ink1; + dat = dat << 2; } } } static void -t1000_poll(void *p) +t1000_poll(void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; if (t1000->video_options != st_video_options || t1000->enabled != st_enabled) { t1000->video_options = st_video_options; @@ -643,7 +649,7 @@ t1000_recalcattrs(t1000_t *t1000) } static void * -t1000_init(const device_t *info) +t1000_init(UNUSED(const device_t *info)) { t1000_t *t1000 = malloc(sizeof(t1000_t)); memset(t1000, 0, sizeof(t1000_t)); @@ -681,18 +687,18 @@ t1000_init(const device_t *info) } static void -t1000_close(void *p) +t1000_close(void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; free(t1000->vram); free(t1000); } static void -t1000_speed_changed(void *p) +t1000_speed_changed(void *priv) { - t1000_t *t1000 = (t1000_t *) p; + t1000_t *t1000 = (t1000_t *) priv; t1000_recalctimings(t1000); } diff --git a/src/machine/m_xt_xi8088.c b/src/machine/m_xt_xi8088.c index 5bf958d8a..3f07e6a4e 100644 --- a/src/machine/m_xt_xi8088.c +++ b/src/machine/m_xt_xi8088.c @@ -24,6 +24,7 @@ #include <86box/video.h> #include <86box/machine.h> #include "cpu.h" +#include <86box/plat_unused.h> #include <86box/m_xt_xi8088.h> @@ -67,7 +68,7 @@ xi8088_bios_128kb(void) } static void * -xi8088_init(const device_t *info) +xi8088_init(UNUSED(const device_t *info)) { xi8088.turbo = 1; xi8088.turbo_setting = device_get_config_int("turbo_setting"); diff --git a/src/machine/m_xt_zenith.c b/src/machine/m_xt_zenith.c index e5cebe552..628b98e8b 100644 --- a/src/machine/m_xt_zenith.c +++ b/src/machine/m_xt_zenith.c @@ -46,6 +46,7 @@ #include <86box/machine.h> #include <86box/io.h> #include <86box/vid_cga.h> +#include <86box/plat_unused.h> typedef struct { mem_mapping_t scratchpad_mapping; @@ -53,21 +54,21 @@ typedef struct { } zenith_t; static uint8_t -zenith_scratchpad_read(uint32_t addr, void *p) +zenith_scratchpad_read(uint32_t addr, void *priv) { - zenith_t *dev = (zenith_t *) p; + zenith_t *dev = (zenith_t *) priv; return dev->scratchpad_ram[addr & 0x3fff]; } static void -zenith_scratchpad_write(uint32_t addr, uint8_t val, void *p) +zenith_scratchpad_write(uint32_t addr, uint8_t val, void *priv) { - zenith_t *dev = (zenith_t *) p; + zenith_t *dev = (zenith_t *) priv; dev->scratchpad_ram[addr & 0x3fff] = val; } static void * -zenith_scratchpad_init(const device_t *info) +zenith_scratchpad_init(UNUSED(const device_t *info)) { zenith_t *dev; @@ -85,9 +86,9 @@ zenith_scratchpad_init(const device_t *info) } static void -zenith_scratchpad_close(void *p) +zenith_scratchpad_close(void *priv) { - zenith_t *dev = (zenith_t *) p; + zenith_t *dev = (zenith_t *) priv; free(dev->scratchpad_ram); free(dev); diff --git a/src/machine/machine.c b/src/machine/machine.c index d48cbdf21..47e98e7b3 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -42,6 +42,7 @@ #include <86box/machine.h> #include <86box/isamem.h> #include <86box/pci.h> +#include <86box/plat_unused.h> int bios_only = 0; int machine; @@ -78,8 +79,10 @@ machine_init_ex(int m) gameport_instance_id = 0; /* Set up the architecture flags. */ - // AT = IS_AT(machine); - // PCI = IS_ARCH(machine, MACHINE_BUS_PCI); +#if 0 + AT = IS_AT(machine); + PCI = IS_ARCH(machine, MACHINE_BUS_PCI); +#endif cpu_set(); pc_speed_changed(); @@ -140,15 +143,15 @@ machine_init(void) int machine_available(int m) { - int ret; - device_t *d = (device_t *) machine_get_device(m); + int ret; + const device_t *dev = machine_get_device(m); bios_only = 1; - ret = device_available(d); + ret = device_available(dev); /* Do not check via machine_init_ex() if the device is not NULL and it has a CONFIG_BIOS field. */ - if ((d == NULL) || (ret != -1)) + if ((dev == NULL) || (ret != -1)) ret = machine_init_ex(m); bios_only = 0; @@ -167,7 +170,7 @@ pit_irq0_timer(int new_out, int old_out) } void -machine_common_init(const machine_t *model) +machine_common_init(UNUSED(const machine_t *model)) { /* System devices first. */ pic_init(); diff --git a/src/machine/machine_table.c b/src/machine/machine_table.c index 605c8a7d2..33268a463 100644 --- a/src/machine/machine_table.c +++ b/src/machine/machine_table.c @@ -34,6 +34,7 @@ #include <86box/keyboard.h> #include <86box/sound.h> #include <86box/video.h> +#include <86box/plat_unused.h> // Temporarily here till we move everything out into the right files extern const device_t pcjr_device; @@ -13029,7 +13030,7 @@ machine_get_p1(void) } void -machine_load_p1(int m) +machine_load_p1(UNUSED(int m)) { machine_p1 = machines[machine].kbc_p1; } @@ -13041,7 +13042,7 @@ machine_get_gpio(void) } void -machine_load_gpio(int m) +machine_load_gpio(UNUSED(int m)) { machine_gpio = machines[machine].gpio; } diff --git a/src/mem/catalyst_flash.c b/src/mem/catalyst_flash.c index 46294a60a..7cd40e9d7 100644 --- a/src/mem/catalyst_flash.c +++ b/src/mem/catalyst_flash.c @@ -70,8 +70,8 @@ static char flash_path[1024]; static uint8_t flash_read(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) priv; - uint8_t ret = 0xff; + const flash_t *dev = (flash_t *) priv; + uint8_t ret = 0xff; addr &= biosmask; @@ -98,10 +98,10 @@ flash_read(uint32_t addr, void *priv) } static uint16_t -flash_readw(uint32_t addr, void *p) +flash_readw(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) p; - uint16_t *q; + flash_t *dev = (flash_t *) priv; + const uint16_t *q; addr &= biosmask; @@ -111,10 +111,10 @@ flash_readw(uint32_t addr, void *p) } static uint32_t -flash_readl(uint32_t addr, void *p) +flash_readl(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) p; - uint32_t *q; + flash_t *dev = (flash_t *) priv; + const uint32_t *q; addr &= biosmask; @@ -124,9 +124,9 @@ flash_readl(uint32_t addr, void *p) } static void -flash_write(uint32_t addr, uint8_t val, void *p) +flash_write(uint32_t addr, uint8_t val, void *priv) { - flash_t *dev = (flash_t *) p; + flash_t *dev = (flash_t *) priv; addr &= biosmask; @@ -189,7 +189,7 @@ catalyst_flash_reset(void *priv) static void * catalyst_flash_init(UNUSED(const device_t *info)) { - FILE *f; + FILE *fp; flash_t *dev; dev = malloc(sizeof(flash_t)); @@ -207,24 +207,24 @@ catalyst_flash_init(UNUSED(const device_t *info)) dev->command = CMD_RESET; - f = nvr_fopen(flash_path, "rb"); - if (f) { - (void) !fread(dev->array, 0x20000, 1, f); - fclose(f); + fp = nvr_fopen(flash_path, "rb"); + if (fp) { + (void) !fread(dev->array, 0x20000, 1, fp); + fclose(fp); } return dev; } static void -catalyst_flash_close(void *p) +catalyst_flash_close(void *priv) { - FILE *f; - flash_t *dev = (flash_t *) p; + FILE *fp; + flash_t *dev = (flash_t *) priv; - f = nvr_fopen(flash_path, "wb"); - fwrite(dev->array, 0x20000, 1, f); - fclose(f); + fp = nvr_fopen(flash_path, "wb"); + fwrite(dev->array, 0x20000, 1, fp); + fclose(fp); free(dev->array); dev->array = NULL; diff --git a/src/mem/intel_flash.c b/src/mem/intel_flash.c index ce529670e..7949f302a 100644 --- a/src/mem/intel_flash.c +++ b/src/mem/intel_flash.c @@ -81,8 +81,8 @@ static char flash_path[1024]; static uint8_t flash_read(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) priv; - uint8_t ret = 0xff; + const flash_t *dev = (flash_t *) priv; + uint8_t ret = 0xff; if (dev->flags & FLAG_INV_A16) addr ^= 0x10000; @@ -112,9 +112,9 @@ flash_read(uint32_t addr, void *priv) static uint16_t flash_readw(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) priv; - uint16_t *q; - uint16_t ret = 0xffff; + flash_t *dev = (flash_t *) priv; + const uint16_t *q; + uint16_t ret = 0xffff; if (dev->flags & FLAG_INV_A16) addr ^= 0x10000; @@ -150,8 +150,8 @@ flash_readw(uint32_t addr, void *priv) static uint32_t flash_readl(uint32_t addr, void *priv) { - flash_t *dev = (flash_t *) priv; - uint32_t *q; + flash_t *dev = (flash_t *) priv; + const uint32_t *q; if (dev->flags & FLAG_INV_A16) addr ^= 0x10000; @@ -221,10 +221,9 @@ flash_write(uint32_t addr, uint8_t val, void *priv) } static void -flash_writew(uint32_t addr, uint16_t val, void *p) +flash_writew(uint32_t addr, uint16_t val, void *priv) { - flash_t *dev = (flash_t *) p; - int i; + flash_t *dev = (flash_t *) priv; uint32_t bb_mask = biosmask & 0xffffe000; if (biosmask == 0x7ffff) bb_mask &= 0xffff8000; @@ -239,7 +238,7 @@ flash_writew(uint32_t addr, uint16_t val, void *p) switch (dev->command) { case CMD_ERASE_SETUP: if (val == CMD_ERASE_CONFIRM) { - for (i = 0; i < 6; i++) { + for (uint8_t i = 0; i < 6; i++) { if ((i == dev->program_addr) && (addr >= dev->block_start[i]) && (addr <= dev->block_end[i])) memset(&(dev->array[dev->block_start[i]]), 0xff, dev->block_len[i]); } @@ -264,7 +263,7 @@ flash_writew(uint32_t addr, uint16_t val, void *p) dev->status = 0; break; case CMD_ERASE_SETUP: - for (i = 0; i < 7; i++) { + for (uint8_t i = 0; i < 7; i++) { if ((addr >= dev->block_start[i]) && (addr <= dev->block_end[i])) dev->program_addr = i; } @@ -292,7 +291,7 @@ flash_writel(UNUSED(uint32_t addr), UNUSED(uint32_t val), UNUSED(void *priv)) static void intel_flash_add_mappings(flash_t *dev) { - int max = 2; + uint8_t max = 2; uint32_t base; uint32_t fbase; uint32_t sub = 0x20000; @@ -305,7 +304,7 @@ intel_flash_add_mappings(flash_t *dev) max = 4; } - for (int i = 0; i < max; i++) { + for (uint8_t i = 0; i < max; i++) { if (biosmask == 0x7ffff) base = 0x80000 + (i << 16); else if (biosmask == 0x3ffff) @@ -348,7 +347,7 @@ intel_flash_reset(void *priv) static void * intel_flash_init(const device_t *info) { - FILE *f; + FILE *fp; flash_t *dev; uint8_t type = info->local & 0xff; @@ -513,19 +512,19 @@ intel_flash_init(const device_t *info) dev->command = CMD_READ_ARRAY; dev->status = 0; - f = nvr_fopen(flash_path, "rb"); - if (f) { - (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN1]]), dev->block_len[BLOCK_MAIN1], 1, f); + fp = nvr_fopen(flash_path, "rb"); + if (fp) { + (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN1]]), dev->block_len[BLOCK_MAIN1], 1, fp); if (dev->block_len[BLOCK_MAIN2]) - (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN2]]), dev->block_len[BLOCK_MAIN2], 1, f); + (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN2]]), dev->block_len[BLOCK_MAIN2], 1, fp); if (dev->block_len[BLOCK_MAIN3]) - (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN3]]), dev->block_len[BLOCK_MAIN3], 1, f); + (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN3]]), dev->block_len[BLOCK_MAIN3], 1, fp); if (dev->block_len[BLOCK_MAIN4]) - (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN4]]), dev->block_len[BLOCK_MAIN4], 1, f); + (void) !fread(&(dev->array[dev->block_start[BLOCK_MAIN4]]), dev->block_len[BLOCK_MAIN4], 1, fp); - (void) !fread(&(dev->array[dev->block_start[BLOCK_DATA1]]), dev->block_len[BLOCK_DATA1], 1, f); - (void) !fread(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, f); - fclose(f); + (void) !fread(&(dev->array[dev->block_start[BLOCK_DATA1]]), dev->block_len[BLOCK_DATA1], 1, fp); + (void) !fread(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, fp); + fclose(fp); } return dev; @@ -534,21 +533,21 @@ intel_flash_init(const device_t *info) static void intel_flash_close(void *priv) { - FILE *f; + FILE *fp; flash_t *dev = (flash_t *) priv; - f = nvr_fopen(flash_path, "wb"); - fwrite(&(dev->array[dev->block_start[BLOCK_MAIN1]]), dev->block_len[BLOCK_MAIN1], 1, f); + fp = nvr_fopen(flash_path, "wb"); + fwrite(&(dev->array[dev->block_start[BLOCK_MAIN1]]), dev->block_len[BLOCK_MAIN1], 1, fp); if (dev->block_len[BLOCK_MAIN2]) - fwrite(&(dev->array[dev->block_start[BLOCK_MAIN2]]), dev->block_len[BLOCK_MAIN2], 1, f); + fwrite(&(dev->array[dev->block_start[BLOCK_MAIN2]]), dev->block_len[BLOCK_MAIN2], 1, fp); if (dev->block_len[BLOCK_MAIN3]) - fwrite(&(dev->array[dev->block_start[BLOCK_MAIN3]]), dev->block_len[BLOCK_MAIN3], 1, f); + fwrite(&(dev->array[dev->block_start[BLOCK_MAIN3]]), dev->block_len[BLOCK_MAIN3], 1, fp); if (dev->block_len[BLOCK_MAIN4]) - fwrite(&(dev->array[dev->block_start[BLOCK_MAIN4]]), dev->block_len[BLOCK_MAIN4], 1, f); + fwrite(&(dev->array[dev->block_start[BLOCK_MAIN4]]), dev->block_len[BLOCK_MAIN4], 1, fp); - fwrite(&(dev->array[dev->block_start[BLOCK_DATA1]]), dev->block_len[BLOCK_DATA1], 1, f); - fwrite(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, f); - fclose(f); + fwrite(&(dev->array[dev->block_start[BLOCK_DATA1]]), dev->block_len[BLOCK_DATA1], 1, fp); + fwrite(&(dev->array[dev->block_start[BLOCK_DATA2]]), dev->block_len[BLOCK_DATA2], 1, fp); + fclose(fp); free(dev->array); dev->array = NULL; diff --git a/src/mem/mem.c b/src/mem/mem.c index 67c0b1e2e..419501a40 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -70,7 +70,7 @@ page_t *pages; /* RAM page table */ page_t **page_lookup; /* pagetable lookup */ uint32_t pages_sz; /* #pages in table */ -uint8_t *ram; +uint8_t *ram; /* the virtual RAM */ uint8_t *ram2; /* the virtual RAM */ uint8_t page_ff[4096]; uint32_t rammask; @@ -167,7 +167,7 @@ mem_log(const char *fmt, ...) int mem_addr_is_ram(uint32_t addr) { - mem_mapping_t *mapping = read_mapping[addr >> MEM_GRANULARITY_BITS]; + const mem_mapping_t *mapping = read_mapping[addr >> MEM_GRANULARITY_BITS]; return (mapping == &ram_low_mapping) || (mapping == &ram_high_mapping) || (mapping == &ram_mid_mapping) || (mapping == &ram_mid_mapping2) || (mapping == &ram_remapped_mapping); @@ -247,7 +247,7 @@ flushmmucache_nopc(void) void mem_flush_write_page(uint32_t addr, uint32_t virt) { - page_t *page_target = &pages[addr >> 12]; + const page_t *page_target = &pages[addr >> 12]; #if (!(defined __amd64__ || defined _M_X64 || defined __aarch64__ || defined _M_ARM64)) uint32_t a; #endif @@ -527,7 +527,7 @@ mmutranslate_noabrt_pae(uint32_t addr, int rw) addr4 = (temp & ~0xfffULL) + ((addr >> 9) & 0xff8); temp = rammap64(addr4) & 0x000000ffffffffffULL; - ; + temp3 = temp & temp4; if (!(temp & 1) || ((CPL == 3) && !(temp3 & 4) && !cpl_override) || (rw && !(temp3 & 2) && ((CPL == 3) || (cr0 & WP_FLAG)))) @@ -710,7 +710,7 @@ read_mem_b(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_b) - ret = map->read_b(addr, map->p); + ret = map->read_b(addr, map->priv); resub_cycles(old_cycles); @@ -733,9 +733,9 @@ read_mem_w(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_w) - ret = map->read_w(addr, map->p); + ret = map->read_w(addr, map->priv); else if (map && map->read_b) - ret = map->read_b(addr, map->p) | (map->read_b(addr + 1, map->p) << 8); + ret = map->read_b(addr, map->priv) | (map->read_b(addr + 1, map->priv) << 8); } resub_cycles(old_cycles); @@ -754,7 +754,7 @@ write_mem_b(uint32_t addr, uint8_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_b) - map->write_b(addr, val, map->p); + map->write_b(addr, val, map->priv); resub_cycles(old_cycles); } @@ -775,10 +775,10 @@ write_mem_w(uint32_t addr, uint16_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map) { if (map->write_w) - map->write_w(addr, val, map->p); + map->write_w(addr, val, map->priv); else if (map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); } } } @@ -817,7 +817,7 @@ readmembl(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_b) - return map->read_b(addr, map->p); + return map->read_b(addr, map->priv); return 0xff; } @@ -860,7 +860,7 @@ writemembl(uint32_t addr, uint8_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_b) - map->write_b(addr, val, map->p); + map->write_b(addr, val, map->priv); } /* Read a byte from memory without MMU translation - result of previous MMU translation passed as value. */ @@ -890,7 +890,7 @@ readmembl_no_mmut(uint32_t addr, uint32_t a64) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_b) - return map->read_b(addr, map->p); + return map->read_b(addr, map->priv); return 0xff; } @@ -929,7 +929,7 @@ writemembl_no_mmut(uint32_t addr, uint32_t a64, uint8_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_b) - map->write_b(addr, val, map->p); + map->write_b(addr, val, map->priv); } uint16_t @@ -988,10 +988,10 @@ readmemwl(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_w) - return map->read_w(addr, map->p); + return map->read_w(addr, map->priv); if (map && map->read_b) { - return map->read_b(addr, map->p) | ((uint16_t) (map->read_b(addr + 1, map->p)) << 8); + return map->read_b(addr, map->priv) | ((uint16_t) (map->read_b(addr + 1, map->priv)) << 8); } return 0xffff; @@ -1070,13 +1070,13 @@ writememwl(uint32_t addr, uint16_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_w) { - map->write_w(addr, val, map->p); + map->write_w(addr, val, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); return; } } @@ -1125,10 +1125,10 @@ readmemwl_no_mmut(uint32_t addr, uint32_t *a64) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_w) - return map->read_w(addr, map->p); + return map->read_w(addr, map->priv); if (map && map->read_b) { - return map->read_b(addr, map->p) | ((uint16_t) (map->read_b(addr + 1, map->p)) << 8); + return map->read_b(addr, map->priv) | ((uint16_t) (map->read_b(addr + 1, map->priv)) << 8); } return 0xffff; @@ -1190,13 +1190,13 @@ writememwl_no_mmut(uint32_t addr, uint32_t *a64, uint16_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_w) { - map->write_w(addr, val, map->p); + map->write_w(addr, val, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); return; } } @@ -1271,13 +1271,13 @@ readmemll(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_l) - return map->read_l(addr, map->p); + return map->read_l(addr, map->priv); if (map && map->read_w) - return map->read_w(addr, map->p) | ((uint32_t) (map->read_w(addr + 2, map->p)) << 16); + return map->read_w(addr, map->priv) | ((uint32_t) (map->read_w(addr + 2, map->priv)) << 16); if (map && map->read_b) - return map->read_b(addr, map->p) | ((uint32_t) (map->read_b(addr + 1, map->p)) << 8) | ((uint32_t) (map->read_b(addr + 2, map->p)) << 16) | ((uint32_t) (map->read_b(addr + 3, map->p)) << 24); + return map->read_b(addr, map->priv) | ((uint32_t) (map->read_b(addr + 1, map->priv)) << 8) | ((uint32_t) (map->read_b(addr + 2, map->priv)) << 16) | ((uint32_t) (map->read_b(addr + 3, map->priv)) << 24); return 0xffffffff; } @@ -1370,19 +1370,19 @@ writememll(uint32_t addr, uint32_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_l) { - map->write_l(addr, val, map->p); + map->write_l(addr, val, map->priv); return; } if (map && map->write_w) { - map->write_w(addr, val, map->p); - map->write_w(addr + 2, val >> 16, map->p); + map->write_w(addr, val, map->priv); + map->write_w(addr + 2, val >> 16, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); - map->write_b(addr + 2, val >> 16, map->p); - map->write_b(addr + 3, val >> 24, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); + map->write_b(addr + 2, val >> 16, map->priv); + map->write_b(addr + 3, val >> 24, map->priv); return; } } @@ -1431,13 +1431,13 @@ readmemll_no_mmut(uint32_t addr, uint32_t *a64) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_l) - return map->read_l(addr, map->p); + return map->read_l(addr, map->priv); if (map && map->read_w) - return map->read_w(addr, map->p) | ((uint32_t) (map->read_w(addr + 2, map->p)) << 16); + return map->read_w(addr, map->priv) | ((uint32_t) (map->read_w(addr + 2, map->priv)) << 16); if (map && map->read_b) - return map->read_b(addr, map->p) | ((uint32_t) (map->read_b(addr + 1, map->p)) << 8) | ((uint32_t) (map->read_b(addr + 2, map->p)) << 16) | ((uint32_t) (map->read_b(addr + 3, map->p)) << 24); + return map->read_b(addr, map->priv) | ((uint32_t) (map->read_b(addr + 1, map->priv)) << 8) | ((uint32_t) (map->read_b(addr + 2, map->priv)) << 16) | ((uint32_t) (map->read_b(addr + 3, map->priv)) << 24); return 0xffffffff; } @@ -1500,19 +1500,19 @@ writememll_no_mmut(uint32_t addr, uint32_t *a64, uint32_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_l) { - map->write_l(addr, val, map->p); + map->write_l(addr, val, map->priv); return; } if (map && map->write_w) { - map->write_w(addr, val, map->p); - map->write_w(addr + 2, val >> 16, map->p); + map->write_w(addr, val, map->priv); + map->write_w(addr + 2, val >> 16, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); - map->write_b(addr + 2, val >> 16, map->p); - map->write_b(addr + 3, val >> 24, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); + map->write_b(addr + 2, val >> 16, map->priv); + map->write_b(addr + 3, val >> 24, map->priv); return; } } @@ -1585,7 +1585,7 @@ readmemql(uint32_t addr) map = read_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->read_l) - return map->read_l(addr, map->p) | ((uint64_t) map->read_l(addr + 4, map->p) << 32); + return map->read_l(addr, map->priv) | ((uint64_t) map->read_l(addr + 4, map->priv) << 32); return readmemll(addr) | ((uint64_t) readmemll(addr + 4) << 32); } @@ -1680,26 +1680,26 @@ writememql(uint32_t addr, uint64_t val) map = write_mapping[addr >> MEM_GRANULARITY_BITS]; if (map && map->write_l) { - map->write_l(addr, val, map->p); - map->write_l(addr + 4, val >> 32, map->p); + map->write_l(addr, val, map->priv); + map->write_l(addr + 4, val >> 32, map->priv); return; } if (map && map->write_w) { - map->write_w(addr, val, map->p); - map->write_w(addr + 2, val >> 16, map->p); - map->write_w(addr + 4, val >> 32, map->p); - map->write_w(addr + 6, val >> 48, map->p); + map->write_w(addr, val, map->priv); + map->write_w(addr + 2, val >> 16, map->priv); + map->write_w(addr + 4, val >> 32, map->priv); + map->write_w(addr + 6, val >> 48, map->priv); return; } if (map && map->write_b) { - map->write_b(addr, val, map->p); - map->write_b(addr + 1, val >> 8, map->p); - map->write_b(addr + 2, val >> 16, map->p); - map->write_b(addr + 3, val >> 24, map->p); - map->write_b(addr + 4, val >> 32, map->p); - map->write_b(addr + 5, val >> 40, map->p); - map->write_b(addr + 6, val >> 48, map->p); - map->write_b(addr + 7, val >> 56, map->p); + map->write_b(addr, val, map->priv); + map->write_b(addr + 1, val >> 8, map->priv); + map->write_b(addr + 2, val >> 16, map->priv); + map->write_b(addr + 3, val >> 24, map->priv); + map->write_b(addr + 4, val >> 32, map->priv); + map->write_b(addr + 5, val >> 40, map->priv); + map->write_b(addr + 6, val >> 48, map->priv); + map->write_b(addr + 7, val >> 56, map->priv); return; } } @@ -1766,7 +1766,7 @@ mem_readb_phys(uint32_t addr) if (map->exec) ret = map->exec[(addr - map->base) & map->mask]; else if (map->read_b) - ret = map->read_b(addr, map->p); + ret = map->read_b(addr, map->priv); } return ret; @@ -1775,9 +1775,9 @@ mem_readb_phys(uint32_t addr) uint16_t mem_readw_phys(uint32_t addr) { - mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; - uint16_t ret; - uint16_t *p; + mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; + uint16_t ret; + const uint16_t *p; mem_logical_addr = 0xffffffff; @@ -1785,7 +1785,7 @@ mem_readw_phys(uint32_t addr) p = (uint16_t *) &(map->exec[(addr - map->base) & map->mask]); ret = *p; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->read_w)) - ret = map->read_w(addr, map->p); + ret = map->read_w(addr, map->priv); else { ret = mem_readb_phys(addr + 1) << 8; ret |= mem_readb_phys(addr); @@ -1797,9 +1797,9 @@ mem_readw_phys(uint32_t addr) uint32_t mem_readl_phys(uint32_t addr) { - mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; - uint32_t ret; - uint32_t *p; + mem_mapping_t *map = read_mapping_bus[addr >> MEM_GRANULARITY_BITS]; + uint32_t ret; + const uint32_t *p; mem_logical_addr = 0xffffffff; @@ -1807,7 +1807,7 @@ mem_readl_phys(uint32_t addr) p = (uint32_t *) &(map->exec[(addr - map->base) & map->mask]); ret = *p; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->read_l)) - ret = map->read_l(addr, map->p); + ret = map->read_l(addr, map->priv); else { ret = mem_readw_phys(addr + 2) << 16; ret |= mem_readw_phys(addr); @@ -1846,7 +1846,7 @@ mem_writeb_phys(uint32_t addr, uint8_t val) if (map->exec) map->exec[(addr - map->base) & map->mask] = val; else if (map->write_b) - map->write_b(addr, val, map->p); + map->write_b(addr, val, map->priv); } } @@ -1862,7 +1862,7 @@ mem_writew_phys(uint32_t addr, uint16_t val) p = (uint16_t *) &(map->exec[(addr - map->base) & map->mask]); *p = val; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->write_w)) - map->write_w(addr, val, map->p); + map->write_w(addr, val, map->priv); else { mem_writeb_phys(addr, val & 0xff); mem_writeb_phys(addr + 1, (val >> 8) & 0xff); @@ -1881,7 +1881,7 @@ mem_writel_phys(uint32_t addr, uint32_t val) p = (uint32_t *) &(map->exec[(addr - map->base) & map->mask]); *p = val; } else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->write_l)) - map->write_l(addr, val, map->p); + map->write_l(addr, val, map->priv); else { mem_writew_phys(addr, val & 0xffff); mem_writew_phys(addr + 2, (val >> 16) & 0xffff); @@ -1891,9 +1891,9 @@ mem_writel_phys(uint32_t addr, uint32_t val) void mem_write_phys(void *src, uint32_t addr, int transfer_size) { - uint8_t *pb; - uint16_t *pw; - uint32_t *pl; + const uint8_t *pb; + const uint16_t *pw; + const uint32_t *pl; if (transfer_size == 4) { pl = (uint32_t *) src; @@ -2183,7 +2183,7 @@ mem_write_ram(uint32_t addr, uint8_t val, UNUSED(void *priv)) } void -mem_write_ramw(uint32_t addr, uint16_t val, void *priv) +mem_write_ramw(uint32_t addr, uint16_t val, UNUSED(void *priv)) { #ifdef ENABLE_MEM_LOG if ((addr >= 0xa0000) && (addr <= 0xbffff)) @@ -2277,7 +2277,7 @@ mem_write_remapped(uint32_t addr, uint8_t val, UNUSED(void *priv)) } static void -mem_write_remappedw(uint32_t addr, uint16_t val, void *priv) +mem_write_remappedw(uint32_t addr, uint16_t val, UNUSED(void *priv)) { uint32_t oldaddr = addr; addr = 0xA0000 + (addr - remap_start_addr); @@ -2313,7 +2313,7 @@ mem_write_remapped2(uint32_t addr, uint8_t val, UNUSED(void *priv)) } static void -mem_write_remappedw2(uint32_t addr, uint16_t val, void *priv) +mem_write_remappedw2(uint32_t addr, uint16_t val, UNUSED(void *priv)) { uint32_t oldaddr = addr; addr = 0xD0000 + (addr - remap_start_addr2); @@ -2516,15 +2516,15 @@ void mem_mapping_set(mem_mapping_t *map, uint32_t base, uint32_t size, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p), + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv), uint8_t *exec, uint32_t fl, - void *p) + void *priv) { if (size != 0x00000000) map->enable = 1; @@ -2541,7 +2541,7 @@ mem_mapping_set(mem_mapping_t *map, map->write_l = write_l; map->exec = exec; map->flags = fl; - map->p = p; + map->priv = priv; map->next = NULL; mem_log("mem_mapping_add(): Linked list structure: %08X -> %08X -> %08X\n", map->prev, map, map->next); @@ -2554,15 +2554,15 @@ void mem_mapping_add(mem_mapping_t *map, uint32_t base, uint32_t size, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p), + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv), uint8_t *exec, uint32_t fl, - void *p) + void *priv) { /* Do a sanity check */ if ((base_mapping == NULL) && (last_mapping != NULL)) { @@ -2593,7 +2593,7 @@ mem_mapping_add(mem_mapping_t *map, last_mapping = map; mem_mapping_set(map, base, size, read_b, read_w, read_l, - write_b, write_w, write_l, exec, fl, p); + write_b, write_w, write_l, exec, fl, priv); } void @@ -2604,12 +2604,12 @@ mem_mapping_do_recalc(mem_mapping_t *map) void mem_mapping_set_handler(mem_mapping_t *map, - uint8_t (*read_b)(uint32_t addr, void *p), - uint16_t (*read_w)(uint32_t addr, void *p), - uint32_t (*read_l)(uint32_t addr, void *p), - void (*write_b)(uint32_t addr, uint8_t val, void *p), - void (*write_w)(uint32_t addr, uint16_t val, void *p), - void (*write_l)(uint32_t addr, uint32_t val, void *p)) + uint8_t (*read_b)(uint32_t addr, void *priv), + uint16_t (*read_w)(uint32_t addr, void *priv), + uint32_t (*read_l)(uint32_t addr, void *priv), + void (*write_b)(uint32_t addr, uint8_t val, void *priv), + void (*write_w)(uint32_t addr, uint16_t val, void *priv), + void (*write_l)(uint32_t addr, uint32_t val, void *priv)) { map->read_b = read_b; map->read_w = read_w; @@ -2653,9 +2653,9 @@ mem_mapping_set_mask(mem_mapping_t *map, uint32_t mask) } void -mem_mapping_set_p(mem_mapping_t *map, void *p) +mem_mapping_set_p(mem_mapping_t *map, void *priv) { - map->p = p; + map->priv = priv; } void diff --git a/src/mem/rom.c b/src/mem/rom.c index 2ace87de7..4a20e8ebc 100644 --- a/src/mem/rom.c +++ b/src/mem/rom.c @@ -138,13 +138,13 @@ rom_getfile(char *fn, char *s, int size) } int -rom_present(char *fn) +rom_present(const char *fn) { - FILE *f; + FILE *fp; - f = rom_fopen(fn, "rb"); - if (f != NULL) { - (void) fclose(f); + fp = rom_fopen(fn, "rb"); + if (fp != NULL) { + (void) fclose(fp); return 1; } @@ -154,7 +154,7 @@ rom_present(char *fn) uint8_t rom_read(uint32_t addr, void *priv) { - rom_t *rom = (rom_t *) priv; + const rom_t *rom = (rom_t *) priv; #ifdef ROM_TRACE if (rom->mapping.base == ROM_TRACE) @@ -205,10 +205,9 @@ rom_readl(uint32_t addr, void *priv) int rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *f = rom_fopen(fn, "rb"); - int i; + FILE *fp = rom_fopen(fn, "rb"); - if (f == NULL) { + if (fp == NULL) { rom_log("ROM: image '%s' not found\n", fn); return 0; } @@ -220,19 +219,19 @@ rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t addr &= 0x03ffff; if (ptr != NULL) { - if (fseek(f, off, SEEK_SET) == -1) + if (fseek(fp, off, SEEK_SET) == -1) fatal("rom_load_linear(): Error seeking to the beginning of the file\n"); - for (i = 0; i < (sz >> 1); i++) { - if (fread(ptr + (addr + (i << 1)), 1, 1, f) != 1) + for (int i = 0; i < (sz >> 1); i++) { + if (fread(ptr + (addr + (i << 1)), 1, 1, fp) != 1) fatal("rom_load_linear(): Error reading even data\n"); } - for (i = 0; i < (sz >> 1); i++) { - if (fread(ptr + (addr + (i << 1) + 1), 1, 1, f) != 1) + for (int i = 0; i < (sz >> 1); i++) { + if (fread(ptr + (addr + (i << 1) + 1), 1, 1, fp) != 1) fatal("rom_load_linear(): Error reading od data\n"); } } - (void) fclose(f); + (void) fclose(fp); return 1; } @@ -241,9 +240,9 @@ rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t int rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *f = rom_fopen(fn, "rb"); + FILE *fp = rom_fopen(fn, "rb"); - if (f == NULL) { + if (fp == NULL) { rom_log("ROM: image '%s' not found\n", fn); return 0; } @@ -255,13 +254,13 @@ rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) addr &= 0x03ffff; if (ptr != NULL) { - if (fseek(f, off, SEEK_SET) == -1) + if (fseek(fp, off, SEEK_SET) == -1) fatal("rom_load_linear(): Error seeking to the beginning of the file\n"); - if (fread(ptr + addr, 1, sz, f) > sz) + if (fread(ptr + addr, 1, sz, fp) > sz) fatal("rom_load_linear(): Error reading data\n"); } - (void) fclose(f); + (void) fclose(fp); return 1; } @@ -270,9 +269,9 @@ rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) int rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *f = rom_fopen(fn, "rb"); + FILE *fp = rom_fopen(fn, "rb"); - if (f == NULL) { + if (fp == NULL) { rom_log("ROM: image '%s' not found\n", fn); return 0; } @@ -284,22 +283,22 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t addr &= 0x03ffff; } - (void) fseek(f, 0, SEEK_END); - if (ftell(f) < sz) { - (void) fclose(f); + (void) fseek(fp, 0, SEEK_END); + if (ftell(fp) < sz) { + (void) fclose(fp); return 0; } if (ptr != NULL) { - if (fseek(f, off, SEEK_SET) == -1) + if (fseek(fp, off, SEEK_SET) == -1) fatal("rom_load_linear_inverted(): Error seeking to the beginning of the file\n"); - if (fread(ptr + addr + 0x10000, 1, sz >> 1, f) > (sz >> 1)) + if (fread(ptr + addr + 0x10000, 1, sz >> 1, fp) > (sz >> 1)) fatal("rom_load_linear_inverted(): Error reading the upper half of the data\n"); - if (fread(ptr + addr, sz >> 1, 1, f) > (sz >> 1)) + if (fread(ptr + addr, sz >> 1, 1, fp) > (sz >> 1)) fatal("rom_load_linear_inverted(): Error reading the lower half of the data\n"); } - (void) fclose(f); + (void) fclose(fp); return 1; } @@ -308,18 +307,18 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t int rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, int off, uint8_t *ptr) { - FILE *fl = rom_fopen(fnl, "rb"); - FILE *fh = rom_fopen(fnh, "rb"); + FILE *fpl = rom_fopen(fnl, "rb"); + FILE *fph = rom_fopen(fnh, "rb"); - if (fl == NULL || fh == NULL) { - if (fl == NULL) + if (fpl == NULL || fph == NULL) { + if (fpl == NULL) rom_log("ROM: image '%s' not found\n", fnl); else - (void) fclose(fl); - if (fh == NULL) + (void) fclose(fpl); + if (fph == NULL) rom_log("ROM: image '%s' not found\n", fnh); else - (void) fclose(fh); + (void) fclose(fph); return 0; } @@ -332,16 +331,16 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in } if (ptr != NULL) { - (void) fseek(fl, off, SEEK_SET); - (void) fseek(fh, off, SEEK_SET); + (void) fseek(fpl, off, SEEK_SET); + (void) fseek(fph, off, SEEK_SET); for (int c = 0; c < sz; c += 2) { - ptr[addr + c] = fgetc(fl) & 0xff; - ptr[addr + c + 1] = fgetc(fh) & 0xff; + ptr[addr + c] = fgetc(fpl) & 0xff; + ptr[addr + c + 1] = fgetc(fph) & 0xff; } } - (void) fclose(fh); - (void) fclose(fl); + (void) fclose(fph); + (void) fclose(fpl); return 1; } diff --git a/src/mem/row.c b/src/mem/row.c index 2152c1f54..ccd0325a4 100644 --- a/src/mem/row.c +++ b/src/mem/row.c @@ -30,11 +30,12 @@ #include <86box/mem.h> #include <86box/spd.h> #include <86box/row.h> - +#include <86box/plat_unused.h> /* 0 1 2 3 4 5 6 7 */ -static uint8_t rows_num, rows_default, - rows_bits; +static uint8_t rows_num; +static uint8_t rows_default; +static uint8_t rows_bits; static uint32_t row_unit; static uint8_t drb_defaults[16]; static row_t *rows; @@ -43,8 +44,8 @@ static row_t *rows; static uint8_t row_read(uint32_t addr, void *priv) { - row_t *dev = (row_t *) priv; - uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + const row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; addreadlookup(mem_logical_addr, new_addr); @@ -79,8 +80,8 @@ row_readl(uint32_t addr, void *priv) static void row_write(uint32_t addr, uint8_t val, void *priv) { - row_t *dev = (row_t *) priv; - uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + const row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; addwritelookup(mem_logical_addr, new_addr); mem_write_ramb_page(new_addr, val, &pages[addr >> 12]); @@ -90,8 +91,8 @@ row_write(uint32_t addr, uint8_t val, void *priv) static void row_writew(uint32_t addr, uint16_t val, void *priv) { - row_t *dev = (row_t *) priv; - uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + const row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; addwritelookup(mem_logical_addr, new_addr); mem_write_ramw_page(new_addr, val, &pages[addr >> 12]); @@ -101,8 +102,8 @@ row_writew(uint32_t addr, uint16_t val, void *priv) static void row_writel(uint32_t addr, uint32_t val, void *priv) { - row_t *dev = (row_t *) priv; - uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; + const row_t *dev = (row_t *) priv; + uint32_t new_addr = ((addr - dev->host_base) & dev->ram_mask) + dev->ram_base; addwritelookup(mem_logical_addr, new_addr); mem_write_raml_page(new_addr, val, &pages[addr >> 12]); @@ -112,7 +113,7 @@ row_writel(uint32_t addr, uint32_t val, void *priv) void row_allocate(uint8_t row_id, uint8_t set) { - uint32_t c, offset; + uint32_t offset; /* Do nothing if size is either zero or invalid. */ if ((rows[row_id].host_size == 0x00000000) || (rows[row_id].host_size == 0xffffffff)) @@ -121,7 +122,7 @@ row_allocate(uint8_t row_id, uint8_t set) if (rows[row_id].ram_size == 0x00000000) return; - for (c = (rows[row_id].host_base >> 12); c < ((rows[row_id].host_base + rows[row_id].host_size) >> 12); c++) { + for (uint32_t c = (rows[row_id].host_base >> 12); c < ((rows[row_id].host_base + rows[row_id].host_size) >> 12); c++) { offset = c - (rows[row_id].host_base >> 12); pages[c].mem = set ? (rows[row_id].buf + rows[row_id].ram_base + ((offset << 12) & rows[row_id].ram_mask)) : page_ff; @@ -129,22 +130,22 @@ row_allocate(uint8_t row_id, uint8_t set) pages[c].write_w = set ? mem_write_ramw_page : NULL; pages[c].write_l = set ? mem_write_raml_page : NULL; #ifdef USE_NEW_DYNAREC - pages[c].evict_prev = EVICT_NOT_IN_LIST; - pages[c].byte_dirty_mask = &byte_dirty_mask[offset * 64]; - pages[c].byte_code_present_mask = &byte_code_present_mask[offset * 64]; + pages[c].evict_prev = EVICT_NOT_IN_LIST; + pages[c].byte_dirty_mask = &byte_dirty_mask[offset * 64]; + pages[c].byte_code_present_mask = &byte_code_present_mask[offset * 64]; #endif } if (rows[row_id].host_base >= 0x00100000) { - mem_set_mem_state_both(rows[row_id].host_base, rows[row_id].host_base + rows[row_id].host_size, + mem_set_mem_state_both(rows[row_id].host_base, rows[row_id].host_base + rows[row_id].host_size, set ? (MEM_READ_INTERNAL | MEM_WRITE_INTERNAL) : (MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL)); } else { if (0x000a0000 > rows[row_id].host_base) { - mem_set_mem_state_both(rows[row_id].host_base, 0x000a0000 - rows[row_id].host_base, + mem_set_mem_state_both(rows[row_id].host_base, 0x000a0000 - rows[row_id].host_base, set ? (MEM_READ_INTERNAL | MEM_WRITE_INTERNAL) : (MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL)); } if ((rows[row_id].host_base + rows[row_id].host_size) > 0x00100000) { - mem_set_mem_state_both(0x00100000, (rows[row_id].host_base + rows[row_id].host_size) - 0x00100000, + mem_set_mem_state_both(0x00100000, (rows[row_id].host_base + rows[row_id].host_size) - 0x00100000, set ? (MEM_READ_INTERNAL | MEM_WRITE_INTERNAL) : (MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL)); } } @@ -208,15 +209,15 @@ row_set_boundary(uint8_t row_id, uint32_t boundary) void -row_reset(void *priv) +row_reset(UNUSED(void *priv)) { - int i; - uint32_t boundary, shift; + uint32_t boundary; + uint32_t shift; - for (i = (rows_num - 1); i >= 0; i--) + for (int8_t i = (rows_num - 1); i >= 0; i--) row_disable(i); - for (i = 0; i < rows_num; i++) { + for (uint8_t i = 0; i < rows_num; i++) { shift = (i & 1) << 2; boundary = ((uint32_t) drb_defaults[i]) + (((((uint32_t) drb_defaults[(i >> 1) + 8]) >> shift) & 0xf) << 8); row_set_boundary(i, boundary); @@ -225,7 +226,7 @@ row_reset(void *priv) void -row_close(void *priv) +row_close(UNUSED(void *priv)) { free(rows); rows = NULL; @@ -235,14 +236,18 @@ row_close(void *priv) void * row_init(const device_t *info) { - uint32_t cur_drb = 0, cur_drbe = 0; - uint32_t last_drb = 0, last_drbe = 0; - uint8_t phys_drbs[16]; - int i, max = info->local & 0xff; - int c; - uint32_t shift, drb; - uint32_t boundary, mask; - row_t *new_rows = NULL; + uint32_t cur_drb = 0; + uint32_t cur_drbe = 0; + uint32_t last_drb = 0; + uint32_t last_drbe = 0; + uint8_t phys_drbs[16]; + int i; + int max = info->local & 0xff; + uint32_t shift; + uint32_t drb; + uint32_t boundary; + uint32_t mask; + row_t *new_rows = NULL; rows_bits = ((info->local >> 24) & 0xff); mask = (1 << rows_bits) - 1; @@ -268,7 +273,7 @@ row_init(const device_t *info) mem_mapping_disable(&ram_2gb_mapping); #endif - for (c = 0; c < pages_sz; c++) { + for (uint32_t c = 0; c < pages_sz; c++) { pages[c].mem = page_ff; pages[c].write_b = NULL; pages[c].write_w = NULL; diff --git a/src/mem/smram.c b/src/mem/smram.c index 7a1fbb664..0532e2dd5 100644 --- a/src/mem/smram.c +++ b/src/mem/smram.c @@ -56,8 +56,8 @@ smram_log(const char *fmt, ...) static uint8_t smram_read(uint32_t addr, void *priv) { - smram_t *dev = (smram_t *) priv; - uint32_t new_addr = addr - dev->host_base + dev->ram_base; + const smram_t *dev = (smram_t *) priv; + uint32_t new_addr = addr - dev->host_base + dev->ram_base; if (new_addr >= (1 << 30)) return mem_read_ram_2gb(new_addr, priv); diff --git a/src/mem/spd.c b/src/mem/spd.c index 6d3e88a93..cbc9ac2b7 100644 --- a/src/mem/spd.c +++ b/src/mem/spd.c @@ -31,8 +31,8 @@ #define SPD_ROLLUP(x) ((x) >= 16 ? ((x) -15) : (x)) -int spd_present = 0; -spd_t *spd_modules[SPD_MAX_SLOTS]; +uint8_t spd_present = 0; +spd_t *spd_modules[SPD_MAX_SLOTS]; static const device_t spd_device; @@ -85,8 +85,8 @@ spd_init(UNUSED(const device_t *info)) int comp_ui16_rev(const void *elem1, const void *elem2) { - uint16_t a = *((uint16_t *) elem1); - uint16_t b = *((uint16_t *) elem2); + const uint16_t a = *((const uint16_t *) elem1); + const uint16_t b = *((const uint16_t *) elem2); return ((a > b) ? -1 : ((a < b) ? 1 : 0)); } @@ -548,8 +548,8 @@ spd_write_drbs_ali1621(uint8_t *regs, uint8_t reg_min, uint8_t reg_max) regs[drb + 3] |= 0x06; switch (size) { - case 4: default: + case 4: regs[drb + 2] = 0x00; break; case 8: diff --git a/src/mem/sst_flash.c b/src/mem/sst_flash.c index dbb91d358..22b147933 100644 --- a/src/mem/sst_flash.c +++ b/src/mem/sst_flash.c @@ -264,8 +264,8 @@ sst_page_write(void *priv) static uint8_t sst_read_id(uint32_t addr, void *priv) { - sst_t *dev = (sst_t *) priv; - uint8_t ret = 0x00; + const sst_t *dev = (sst_t *) priv; + uint8_t ret = 0x00; if ((addr & 0xffff) == 0) ret = dev->manufacturer; @@ -378,8 +378,8 @@ sst_write(uint32_t addr, uint8_t val, void *priv) static uint8_t sst_read(uint32_t addr, void *priv) { - sst_t *dev = (sst_t *) priv; - uint8_t ret = 0xff; + const sst_t *dev = (sst_t *) priv; + uint8_t ret = 0xff; addr &= 0x000fffff; diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 9f6d49a17..ce1bba325 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -16,20 +16,12 @@ set(net_sources) list(APPEND net_sources network.c net_pcap.c net_slirp.c net_dp8390.c net_3c501.c net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c net_event.c net_null.c) -option(SLIRP_EXTERNAL "Link against the system-provided libslirp library" ON) -mark_as_advanced(SLIRP_EXTERNAL) +find_package(PkgConfig REQUIRED) +pkg_check_modules(SLIRP REQUIRED IMPORTED_TARGET slirp) +target_link_libraries(86Box PkgConfig::SLIRP) -if(SLIRP_EXTERNAL) - find_package(PkgConfig REQUIRED) - pkg_check_modules(SLIRP REQUIRED IMPORTED_TARGET slirp) - target_link_libraries(86Box PkgConfig::SLIRP) - - if(WIN32) - target_link_libraries(PkgConfig::SLIRP INTERFACE wsock32 ws2_32 iphlpapi iconv) - endif() -else() - add_subdirectory(slirp) - target_link_libraries(86Box slirp) +if(WIN32) + target_link_libraries(PkgConfig::SLIRP INTERFACE wsock32 ws2_32 iphlpapi iconv) endif() if (HAIKU) diff --git a/src/network/net_3c501.c b/src/network/net_3c501.c index 0c73ea028..b3a903c7b 100644 --- a/src/network/net_3c501.c +++ b/src/network/net_3c501.c @@ -58,6 +58,7 @@ #include <86box/network.h> #include <86box/net_3c501.h> #include <86box/bswap.h> +#include <86box/plat_unused.h> /* Maximum number of times we report a link down to the guest (failure to send frame) */ #define ELNK_MAX_LINKDOWN_REPORTED 3 @@ -192,7 +193,7 @@ typedef struct ELNK_INTR_STAT { uint8_t unused : 5; } EL_INTR_STAT; -typedef struct { +typedef struct threec501_t { uint32_t base_address; int base_irq; uint32_t bios_addr; @@ -372,8 +373,8 @@ elnkR3HardReset(threec501_t *dev) static __inline int padr_match(threec501_t *dev, const uint8_t *buf) { - struct ether_header *hdr = (struct ether_header *) buf; - int result; + const struct ether_header *hdr = (struct ether_header *) buf; + int result; /* Checks own + broadcast as well as own + multicast. */ result = (dev->RcvCmd.adr_match >= EL_ADRM_BCAST) && !memcmp(hdr->ether_dhost, dev->aStationAddr, 6); @@ -387,9 +388,10 @@ padr_match(threec501_t *dev, const uint8_t *buf) static __inline int padr_bcast(threec501_t *dev, const uint8_t *buf) { - static uint8_t aBCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - struct ether_header *hdr = (struct ether_header *) buf; - int result = (dev->RcvCmd.adr_match == EL_ADRM_BCAST) && !memcmp(hdr->ether_dhost, aBCAST, 6); + static uint8_t aBCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + const struct ether_header *hdr = (struct ether_header *) buf; + int result = (dev->RcvCmd.adr_match == EL_ADRM_BCAST) && !memcmp(hdr->ether_dhost, aBCAST, 6); + return result; } @@ -401,6 +403,7 @@ padr_mcast(threec501_t *dev, const uint8_t *buf) { struct ether_header *hdr = (struct ether_header *) buf; int result = (dev->RcvCmd.adr_match == EL_ADRM_MCAST) && ETHER_IS_MULTICAST(hdr->ether_dhost); + return result; } @@ -692,7 +695,6 @@ elnkAsyncTransmit(threec501_t *dev) #ifdef ENABLE_3COM501_LOG threec501_log("3Com501: illegal giant frame (%u bytes) -> signalling error\n", cb); #endif - ; } } else { /* Signal a transmit error pretending there was a collision. */ @@ -921,6 +923,9 @@ threec501_read(uint16_t addr, void *priv) retval = dev->abPacketBuf[ELNK_GP(dev)]; dev->uGPBufPtr = (dev->uGPBufPtr + 1) & ELNK_GP_MASK; break; + + default: + break; } elnkUpdateIrq(dev); @@ -1007,6 +1012,9 @@ threec501_write(uint16_t addr, uint8_t value, void *priv) dev->abPacketBuf[ELNK_GP(dev)] = value; dev->uGPBufPtr = (dev->uGPBufPtr + 1) & ELNK_GP_MASK; break; + + default: + break; } #ifdef ENABLE_3COM501_LOG @@ -1068,7 +1076,7 @@ elnkR3TimerRestore(void *priv) } static void * -threec501_nic_init(const device_t *info) +threec501_nic_init(UNUSED(const device_t *info)) { uint32_t mac; threec501_t *dev; diff --git a/src/network/net_3c503.c b/src/network/net_3c503.c index ce4650456..d01b423ae 100644 --- a/src/network/net_3c503.c +++ b/src/network/net_3c503.c @@ -62,8 +62,9 @@ #include <86box/net_dp8390.h> #include <86box/net_3c503.h> #include <86box/bswap.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct threec503_t { dp8390_t *dp8390; mem_mapping_t ram_mapping; uint32_t base_address; @@ -129,6 +130,9 @@ threec503_interrupt(void *priv, int set) case 5: dev->regs.idcfr = 0x80; break; + + default: + break; } if (set) @@ -151,7 +155,7 @@ threec503_ram_write(uint32_t addr, uint8_t val, void *priv) static uint8_t threec503_ram_read(uint32_t addr, void *priv) { - threec503_t *dev = (threec503_t *) priv; + const threec503_t *dev = (threec503_t *) priv; if ((addr & 0x3fff) >= 0x2000) return 0xff; @@ -174,6 +178,9 @@ threec503_set_drq(threec503_t *dev) case 3: dev->regs.idcfr = 4; break; + + default: + break; } } @@ -223,6 +230,9 @@ threec503_nic_lo_read(uint16_t addr, void *priv) case 0x03: retval = 0xff; break; + + default: + break; } break; @@ -237,6 +247,9 @@ threec503_nic_lo_read(uint16_t addr, void *priv) case 0x03: retval = 0xff; break; + + default: + break; } return retval; @@ -272,6 +285,9 @@ threec503_nic_lo_write(uint16_t addr, uint8_t val, void *priv) case 0x03: break; + + default: + break; } break; @@ -279,6 +295,9 @@ threec503_nic_lo_write(uint16_t addr, uint8_t val, void *priv) case 0x02: case 0x03: break; + + default: + break; } threec503_log("3Com503: write addr %x, value %x\n", addr, val); @@ -338,7 +357,6 @@ threec503_nic_hi_read(uint16_t addr, void *priv) } return dev->regs.bcfr; - break; case 0x04: switch (dev->bios_addr) { @@ -357,10 +375,12 @@ threec503_nic_hi_read(uint16_t addr, void *priv) case 0xc8000: dev->regs.pcfr = 0x10; break; + + default: + break; } return dev->regs.pcfr; - break; case 0x05: return dev->regs.gacfr; @@ -397,6 +417,9 @@ threec503_nic_hi_read(uint16_t addr, void *priv) threec503_set_drq(dev); return dp8390_chipmem_read(dev->dp8390, dev->regs.da++, 1); + + default: + break; } return 0; @@ -527,6 +550,9 @@ threec503_nic_hi_write(uint16_t addr, uint8_t val, void *priv) dp8390_chipmem_write(dev->dp8390, dev->regs.da++, val, 1); break; + + default: + break; } } @@ -543,7 +569,7 @@ threec503_nic_ioset(threec503_t *dev, uint16_t addr) } static void * -threec503_nic_init(const device_t *info) +threec503_nic_init(UNUSED(const device_t *info)) { uint32_t mac; threec503_t *dev; @@ -605,7 +631,9 @@ threec503_nic_init(const device_t *info) threec503_ram_read, NULL, NULL, threec503_ram_write, NULL, NULL, NULL, MEM_MAPPING_EXTERNAL, dev); - // mem_mapping_disable(&dev->ram_mapping); +#if 0 + mem_mapping_disable(&dev->ram_mapping); +#endif dev->regs.gacfr = 0x09; /* Start with RAM mapping enabled. */ /* Attach ourselves to the network module. */ diff --git a/src/network/net_dp8390.c b/src/network/net_dp8390.c index a1fa4b336..1e50ddd45 100644 --- a/src/network/net_dp8390.c +++ b/src/network/net_dp8390.c @@ -29,6 +29,7 @@ #include <86box/timer.h> #include <86box/network.h> #include <86box/net_dp8390.h> +#include <86box/plat_unused.h> static void dp8390_tx(dp8390_t *dev, uint32_t val); static int dp8390_rx_common(void *priv, uint8_t *buf, int io_len); @@ -62,10 +63,10 @@ static int mcast_index(const void *dst) { #define POLYNOMIAL 0x04c11db6 - uint32_t crc = 0xffffffffL; - int carry; - uint8_t b; - uint8_t *ep = (uint8_t *) dst; + uint32_t crc = 0xffffffffL; + int carry; + uint8_t b; + const uint8_t *ep = (uint8_t *) dst; for (int8_t i = 6; --i >= 0;) { b = *ep++; @@ -242,7 +243,7 @@ dp8390_write_cr(dp8390_t *dev, uint32_t val) } static void -dp8390_tx(dp8390_t *dev, uint32_t val) +dp8390_tx(dp8390_t *dev, UNUSED(uint32_t val)) { dev->CR.tx_packet = 0; dev->TSR.tx_ok = 1; @@ -408,7 +409,7 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len) int dp8390_rx(void *priv, uint8_t *buf, int io_len) { - dp8390_t *dev = (dp8390_t *) priv; + const dp8390_t *dev = (dp8390_t *) priv; if ((dev->DCR.loop == 0) || (dev->TCR.loop_cntl != 0)) return 0; @@ -506,7 +507,7 @@ dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len) } void -dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) +dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { uint8_t val2; @@ -697,7 +698,7 @@ dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) /* Handle reads/writes to the first page of the DS8390 register file. */ uint32_t -dp8390_page1_read(dp8390_t *dev, uint32_t off, unsigned int len) +dp8390_page1_read(dp8390_t *dev, uint32_t off, UNUSED(unsigned int len)) { dp8390_log("DP8390: Page1 read from register 0x%02x, len=%u\n", off, len); @@ -734,7 +735,7 @@ dp8390_page1_read(dp8390_t *dev, uint32_t off, unsigned int len) } void -dp8390_page1_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) +dp8390_page1_write(dp8390_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { dp8390_log("DP8390: Page1 write to register 0x%02x, len=%u, value=0x%04x\n", off, len, val); @@ -778,7 +779,7 @@ dp8390_page1_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) /* Handle reads/writes to the second page of the DS8390 register file. */ uint32_t -dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len) +dp8390_page2_read(dp8390_t *dev, uint32_t off, UNUSED(unsigned int len)) { dp8390_log("DP8390: Page2 read from register 0x%02x, len=%u\n", off, len); @@ -835,7 +836,7 @@ dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len) } void -dp8390_page2_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len) +dp8390_page2_write(dp8390_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { /* Maybe all writes here should be BX_PANIC()'d, since they affect internal operation, but let them through for now @@ -999,7 +1000,7 @@ dp8390_soft_reset(dp8390_t *dev) } static void * -dp8390_init(const device_t *info) +dp8390_init(UNUSED(const device_t *info)) { dp8390_t *dp8390 = (dp8390_t *) malloc(sizeof(dp8390_t)); memset(dp8390, 0, sizeof(dp8390_t)); diff --git a/src/network/net_event.c b/src/network/net_event.c index 6e68f1fe3..c39c12254 100644 --- a/src/network/net_event.c +++ b/src/network/net_event.c @@ -7,6 +7,7 @@ #endif #include <86box/net_event.h> +#include <86box/plat_unused.h> #ifndef _WIN32 static void @@ -40,7 +41,7 @@ net_event_set(net_evt_t *event) } void -net_event_clear(net_evt_t *event) +net_event_clear(UNUSED(net_evt_t *event)) { #ifdef _WIN32 /* Do nothing on WIN32 since we use an auto-reset event */ diff --git a/src/network/net_ne2000.c b/src/network/net_ne2000.c index 263d38970..80dc4ec27 100644 --- a/src/network/net_ne2000.c +++ b/src/network/net_ne2000.c @@ -68,6 +68,8 @@ #include <86box/net_ne2000.h> #include <86box/bswap.h> #include <86box/isapnp.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> /* ROM BIOS file paths. */ #define ROM_PATH_NE1000 "roms/network/ne1000/ne1000.rom" @@ -93,28 +95,33 @@ static uint8_t rtl8019as_pnp_rom[] = { 0x79, 0x00 /* end tag, dummy checksum (filled in by isapnp_add_card) */ }; -typedef struct { +typedef struct nic_t { dp8390_t *dp8390; const char *name; int board; - int is_pci, is_mca, is_8bit; + int is_pci; + int is_mca; + int is_8bit; uint32_t base_address; int base_irq; - uint32_t bios_addr, - bios_size, - bios_mask; - int card; /* PCI card slot */ - int has_bios, pad; - bar_t pci_bar[2]; - uint8_t pci_regs[PCI_REGSIZE]; - uint8_t eeprom[128]; /* for RTL8029AS */ - rom_t bios_rom; - void *pnp_card; - uint8_t pnp_csnsav; - uint8_t maclocal[6]; /* configured MAC (local) address */ + uint32_t bios_addr; + uint32_t bios_size; + uint32_t bios_mask; + int card; /* PCI card slot */ + int has_bios; + int pad; + bar_t pci_bar[2]; + uint8_t pci_regs[PCI_REGSIZE]; + uint8_t eeprom[128]; /* for RTL8029AS */ + rom_t bios_rom; + void *pnp_card; + uint8_t pnp_csnsav; + uint8_t maclocal[6]; /* configured MAC (local) address */ /* RTL8019AS/RTL8029AS registers */ - uint8_t config0, config2, config3; + uint8_t config0; + uint8_t config2; + uint8_t config3; uint8_t _9346cr; uint32_t pad0; @@ -143,7 +150,7 @@ nelog(int lvl, const char *fmt, ...) static void nic_interrupt(void *priv, int set) { - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; if (dev->is_pci) { if (set) @@ -308,7 +315,7 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) /* Writes to this page are illegal. */ static uint32_t -page3_read(nic_t *dev, uint32_t off, unsigned int len) +page3_read(nic_t *dev, uint32_t off, UNUSED(unsigned int len)) { if (dev->board >= NE2K_RTL8019AS) switch (off) { @@ -346,7 +353,7 @@ page3_read(nic_t *dev, uint32_t off, unsigned int len) } static void -page3_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) +page3_write(nic_t *dev, uint32_t off, uint32_t val, UNUSED(unsigned len)) { if (dev->board >= NE2K_RTL8019AS) { nelog(3, "%s: Page2 write to register 0x%02x, len=%u, value=0x%04x\n", @@ -521,7 +528,7 @@ nic_pnp_read_vendor_reg(uint8_t ld, uint8_t reg, void *priv) if (ld != 0) return 0x00; - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; switch (reg) { case 0xF0: @@ -535,6 +542,9 @@ nic_pnp_read_vendor_reg(uint8_t ld, uint8_t reg, void *priv) case 0xF5: return dev->pnp_csnsav; + + default: + break; } return 0x00; @@ -623,10 +633,10 @@ nic_update_bios(nic_t *dev) } static uint8_t -nic_pci_read(int func, int addr, void *priv) +nic_pci_read(UNUSED(int func), int addr, void *priv) { - nic_t *dev = (nic_t *) priv; - uint8_t ret = 0x00; + const nic_t *dev = (nic_t *) priv; + uint8_t ret = 0x00; switch (addr) { case 0x00: /* PCI_VID_LO */ @@ -707,6 +717,9 @@ nic_pci_read(int func, int addr, void *priv) case 0x3D: /* PCI_IPR */ ret = dev->pci_regs[addr]; break; + + default: + break; } nelog(2, "%s: PCI_Read(%d, %04x) = %02x\n", dev->name, func, addr, ret); @@ -715,7 +728,7 @@ nic_pci_read(int func, int addr, void *priv) } static void -nic_pci_write(int func, int addr, uint8_t val, void *priv) +nic_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { nic_t *dev = (nic_t *) priv; uint8_t valxor; @@ -737,7 +750,9 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) case 0x10: /* PCI_BAR */ val &= 0xe0; /* 0xe0 acc to RTL DS */ val |= 0x01; /* re-enable IOIN bit */ - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x11: /* PCI_BAR */ case 0x12: /* PCI_BAR */ @@ -767,7 +782,9 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) case 0x32: /* PCI_ROMBAR */ case 0x33: /* PCI_ROMBAR */ dev->pci_bar[1].addr_regs[addr & 3] = val; - /* dev->pci_bar[1].addr_regs[1] &= dev->bios_mask; */ +#if 0 + dev->pci_bar[1].addr_regs[1] &= dev->bios_mask; +#endif dev->pci_bar[1].addr &= 0xffff8001; dev->bios_addr = dev->pci_bar[1].addr & 0xffff8000; nic_update_bios(dev); @@ -778,6 +795,9 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) dev->base_irq = val; dev->pci_regs[addr] = dev->base_irq; return; + + default: + break; } } @@ -823,7 +843,7 @@ nic_rom_init(nic_t *dev, char *s) static uint8_t nic_mca_read(int port, void *priv) { - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; return (dev->pos_regs[port & 7]); } @@ -888,7 +908,7 @@ nic_mca_write(int port, uint8_t val, void *priv) static uint8_t nic_mca_feedb(void *priv) { - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; return (dev->pos_regs[2] & 0x01); } @@ -1000,6 +1020,9 @@ nic_init(const device_t *info) dp8390_set_id(dev->dp8390, 0x50, (dev->board == NE2K_RTL8019AS) ? 0x70 : 0x43); dp8390_mem_alloc(dev->dp8390, 0x4000, 0x8000); break; + + default: + break; } memcpy(dev->dp8390->physaddr, dev->maclocal, sizeof(dev->maclocal)); diff --git a/src/network/net_null.c b/src/network/net_null.c index 27a0d4da7..6fb3f3440 100644 --- a/src/network/net_null.c +++ b/src/network/net_null.c @@ -37,6 +37,7 @@ #include <86box/timer.h> #include <86box/network.h> #include <86box/net_event.h> +#include <86box/plat_unused.h> enum { NET_EVENT_STOP = 0, @@ -53,7 +54,7 @@ enum { #define NULL_PKT_BATCH NET_QUEUE_LEN -typedef struct { +typedef struct net_null_t { uint8_t mac_addr[6]; netcard_t *card; thread_t *poll_tid; @@ -158,7 +159,7 @@ net_null_thread(void *priv) #endif void * -net_null_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, char *netdrv_errbuf) +net_null_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv), UNUSED(char *netdrv_errbuf)) { net_null_log("Null Network: Init\n"); diff --git a/src/network/net_pcap.c b/src/network/net_pcap.c index b9e2f32e8..4981fb9a3 100644 --- a/src/network/net_pcap.c +++ b/src/network/net_pcap.c @@ -247,7 +247,7 @@ net_pcap_in(void *pcap, uint8_t *bufp, int len) if (pcap == NULL) return; - f_pcap_sendpacket((void *) pcap, bufp, len); + f_pcap_sendpacket(pcap, bufp, len); } void @@ -268,7 +268,7 @@ net_pcap_thread(void *priv) HANDLE events[NET_EVENT_MAX]; events[NET_EVENT_STOP] = net_event_get_handle(&pcap->stop_event); events[NET_EVENT_TX] = net_event_get_handle(&pcap->tx_event); - events[NET_EVENT_RX] = f_pcap_getevent((void *) pcap->pcap); + events[NET_EVENT_RX] = f_pcap_getevent(pcap->pcap); bool run = true; @@ -296,6 +296,9 @@ net_pcap_thread(void *priv) case NET_EVENT_RX: f_pcap_dispatch(pcap->pcap, PCAP_PKT_BATCH, net_pcap_rx_handler, (u_char *) pcap); break; + + default: + break; } } @@ -467,22 +470,22 @@ net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, char * return NULL; } - if (f_pcap_setnonblock((void *) pcap->pcap, 1, errbuf) != 0) + if (f_pcap_setnonblock(pcap->pcap, 1, errbuf) != 0) pcap_log("PCAP: failed nonblock %s\n", errbuf); - if (f_pcap_set_immediate_mode((void *) pcap->pcap, 1) != 0) + if (f_pcap_set_immediate_mode(pcap->pcap, 1) != 0) pcap_log("PCAP: error setting immediate mode\n"); - if (f_pcap_set_promisc((void *) pcap->pcap, 1) != 0) + if (f_pcap_set_promisc(pcap->pcap, 1) != 0) pcap_log("PCAP: error enabling promiscuous mode\n"); - if (f_pcap_set_snaplen((void *) pcap->pcap, NET_MAX_FRAME) != 0) + if (f_pcap_set_snaplen(pcap->pcap, NET_MAX_FRAME) != 0) pcap_log("PCAP: error setting snaplen\n"); - if (f_pcap_activate((void *) pcap->pcap) != 0) { + if (f_pcap_activate(pcap->pcap) != 0) { snprintf(errbuf_prep, NET_DRV_ERRBUF_SIZE, "%s", (char *)f_pcap_geterr(pcap->pcap)); net_pcap_error(netdrv_errbuf, errbuf_prep); - f_pcap_close((void *) pcap->pcap); + f_pcap_close(pcap->pcap); free(pcap); return NULL; } @@ -494,18 +497,18 @@ net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, char * "( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); - if (f_pcap_compile((void *) pcap->pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { - if (f_pcap_setfilter((void *) pcap->pcap, &fp) != 0) { + if (f_pcap_compile(pcap->pcap, &fp, filter_exp, 0, 0xffffffff) != -1) { + if (f_pcap_setfilter(pcap->pcap, &fp) != 0) { snprintf(errbuf_prep, NET_DRV_ERRBUF_SIZE, "Error installing filter (%s)\n", filter_exp); net_pcap_error(netdrv_errbuf, errbuf_prep); - f_pcap_close((void *) pcap->pcap); + f_pcap_close(pcap->pcap); free(pcap); return NULL; } } else { - snprintf(errbuf_prep, NET_DRV_ERRBUF_SIZE, "Could not compile filter (%s) : %s!\n", filter_exp, (char *)f_pcap_geterr((void *) pcap->pcap)); + snprintf(errbuf_prep, NET_DRV_ERRBUF_SIZE, "Could not compile filter (%s) : %s!\n", filter_exp, (char *)f_pcap_geterr(pcap->pcap)); net_pcap_error(netdrv_errbuf, errbuf_prep); - f_pcap_close((void *) pcap->pcap); + f_pcap_close(pcap->pcap); free(pcap); return NULL; } @@ -554,7 +557,7 @@ net_pcap_close(void *priv) f_pcap_sendqueue_destroy((void *) pcap->pcap_queue); #endif /* OK, now shut down Pcap itself. */ - f_pcap_close((void *) pcap->pcap); + f_pcap_close(pcap->pcap); net_event_close(&pcap->tx_event); net_event_close(&pcap->stop_event); diff --git a/src/network/net_pcnet.c b/src/network/net_pcnet.c index b1ea475ae..85d2cb8bb 100644 --- a/src/network/net_pcnet.c +++ b/src/network/net_pcnet.c @@ -47,6 +47,7 @@ #include <86box/network.h> #include <86box/net_pcnet.h> #include <86box/bswap.h> +#include <86box/plat_unused.h> /* PCI info. */ #define PCI_VENDID 0x1022 /* AMD */ @@ -744,11 +745,12 @@ static const uint32_t crctab[256] = }; static __inline int -padr_match(nic_t *dev, const uint8_t *buf, int size) +padr_match(nic_t *dev, const uint8_t *buf, UNUSED(int size)) { - struct ether_header *hdr = (struct ether_header *) buf; - int result; - uint8_t padr[6]; + const struct ether_header *hdr = (struct ether_header *) buf; + int result; + uint8_t padr[6]; + padr[0] = dev->aCSR[12] & 0xff; padr[1] = dev->aCSR[12] >> 8; padr[2] = dev->aCSR[13] & 0xff; @@ -768,19 +770,22 @@ padr_match(nic_t *dev, const uint8_t *buf, int size) } static __inline int -padr_bcast(nic_t *dev, const uint8_t *buf, size_t size) +padr_bcast(nic_t *dev, const uint8_t *buf, UNUSED(size_t size)) { - static uint8_t aBCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - struct ether_header *hdr = (struct ether_header *) buf; - int result = !CSR_DRCVBC(dev) && !memcmp(hdr->ether_dhost, aBCAST, 6); + static uint8_t aBCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + const struct ether_header *hdr = (struct ether_header *) buf; + int result = !CSR_DRCVBC(dev) && !memcmp(hdr->ether_dhost, aBCAST, 6); + pcnet_log(3, "%s: padr_bcast result=%d\n", dev->name, result); + return result; } static int -ladr_match(nic_t *dev, const uint8_t *buf, size_t size) +ladr_match(nic_t *dev, const uint8_t *buf, UNUSED(size_t size)) { - struct ether_header *hdr = (struct ether_header *) buf; + const struct ether_header *hdr = (struct ether_header *) buf; + if ((hdr->ether_dhost[0] & 0x01) && ((uint64_t *) &dev->aCSR[8])[0] != 0LL) { int index; uint8_t ladr[8]; @@ -861,6 +866,9 @@ pcnetSoftReset(nic_t *dev) dev->aCSR[88] = 0x3003; dev->aCSR[89] = 0x0262; break; + + default: + break; } dev->aCSR[94] = 0x0000; @@ -1263,14 +1271,14 @@ pcnetReceiveNoSync(void *priv, uint8_t *buf, int size) ++; pcnet_log(2, "%s: pcnetReceiveNoSync: packet missed\n", dev->name); } else { - RTNETETHERHDR *pEth = (RTNETETHERHDR *) buf; - int fStrip = 0; - size_t len_802_3; - uint8_t *src = &dev->abRecvBuf[8]; - uint32_t crda = CSR_CRDA(dev); - uint32_t next_crda; - RMD rmd; - RMD next_rmd; + const RTNETETHERHDR *pEth = (RTNETETHERHDR *) buf; + int fStrip = 0; + size_t len_802_3; + uint8_t *src = &dev->abRecvBuf[8]; + uint32_t crda = CSR_CRDA(dev); + uint32_t next_crda; + RMD rmd; + RMD next_rmd; /* * Ethernet framing considers these two octets to be @@ -1297,8 +1305,8 @@ pcnetReceiveNoSync(void *priv, uint8_t *buf, int size) while (size < 60) src[size++] = 0; - uint32_t fcs = UINT32_MAX; - uint8_t *p = src; + uint32_t fcs = UINT32_MAX; + const uint8_t *p = src; while (p != &src[size]) CRC(fcs, *p++); @@ -1308,7 +1316,7 @@ pcnetReceiveNoSync(void *priv, uint8_t *buf, int size) size += 4; } - cbPacket = (int) size; + cbPacket = size; pcnetRmdLoad(dev, &rmd, PHYSADDR(dev, crda), 0); /* if (!CSR_LAPPEN(dev)) */ @@ -1680,9 +1688,9 @@ pcnetPollRxTx(nic_t *dev) } static void -pcnetPollTimer(void *p) +pcnetPollTimer(void *priv) { - nic_t *dev = (nic_t *) p; + nic_t *dev = (nic_t *) priv; timer_advance_u64(&dev->timer, 2000 * TIMER_USEC); @@ -2223,6 +2231,9 @@ pcnet_word_write(nic_t *dev, uint32_t addr, uint16_t val) case 0x06: pcnet_bcr_writew(dev, dev->u32RAP, val); break; + + default: + break; } } } @@ -2238,6 +2249,9 @@ pcnet_byte_read(nic_t *dev, uint32_t addr) pcnetSoftReset(dev); val = 0; break; + + default: + break; } } @@ -2275,6 +2289,9 @@ pcnet_word_read(nic_t *dev, uint32_t addr) case 0x06: val = pcnet_bcr_readw(dev, dev->u32RAP); break; + + default: + break; } } @@ -2302,6 +2319,9 @@ pcnet_dword_write(nic_t *dev, uint32_t addr, uint32_t val) case 0x0c: pcnet_bcr_writew(dev, dev->u32RAP, val & 0xffff); break; + + default: + break; } } else if ((addr & 0x0f) == 0) { /* switch device to dword i/o mode */ @@ -2334,6 +2354,9 @@ pcnet_dword_read(nic_t *dev, uint32_t addr) case 0x0c: val = pcnet_bcr_readw(dev, dev->u32RAP); break; + + default: + break; } } @@ -2540,9 +2563,9 @@ pcnet_ioset(nic_t *dev, uint16_t addr, int len) } static void -pcnet_pci_write(int func, int addr, uint8_t val, void *p) +pcnet_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - nic_t *dev = (nic_t *) p; + nic_t *dev = (nic_t *) priv; uint8_t valxor; pcnet_log(4, "%s: Write value %02X to register %02X\n", dev->name, val, addr & 0xff); @@ -2616,13 +2639,16 @@ pcnet_pci_write(int func, int addr, uint8_t val, void *p) dev->base_irq = val; pcnet_pci_regs[addr] = val; return; + + default: + break; } } static uint8_t -pcnet_pci_read(int func, int addr, void *p) +pcnet_pci_read(UNUSED(int func), int addr, void *priv) { - nic_t *dev = (nic_t *) p; + const nic_t *dev = (nic_t *) priv; pcnet_log(4, "%s: Read to register %02X\n", dev->name, addr & 0xff); @@ -2687,6 +2713,9 @@ pcnet_pci_read(int func, int addr, void *p) return 0x06; case 0x3F: return 0xff; + + default: + break; } return 0; @@ -2731,7 +2760,7 @@ pcnet_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) static uint8_t pcnet_pnp_read_vendor_reg(uint8_t ld, uint8_t reg, void *priv) { - nic_t *dev = (nic_t *) priv; + const nic_t *dev = (nic_t *) priv; if (!ld && (reg == 0xf0)) return dev->aPROM[50]; diff --git a/src/network/net_plip.c b/src/network/net_plip.c index 58274e62a..f622d455b 100644 --- a/src/network/net_plip.c +++ b/src/network/net_plip.c @@ -35,6 +35,7 @@ #include <86box/timer.h> #include <86box/network.h> #include <86box/net_plip.h> +#include <86box/plat_unused.h> enum { PLIP_START = 0x00, @@ -57,20 +58,28 @@ enum { PLIP_END = 0x40 }; -typedef struct -{ +typedef struct plip_t { uint8_t mac[6]; void *lpt; pc_timer_t rx_timer; pc_timer_t timeout_timer; - uint8_t status, ctrl; + uint8_t status; + uint8_t ctrl; - uint8_t state, ack, tx_checksum, tx_checksum_calc, *tx_pkt; - uint16_t tx_len, tx_ptr; + uint8_t state; + uint8_t ack; + uint8_t tx_checksum; + uint8_t tx_checksum_calc; + uint8_t *tx_pkt; + uint16_t tx_len; + uint16_t tx_ptr; - uint8_t *rx_pkt, rx_checksum, rx_return_state; - uint16_t rx_len, rx_ptr; + uint8_t *rx_pkt; + uint8_t rx_checksum; + uint8_t rx_return_state; + uint16_t rx_len; + uint16_t rx_ptr; netcard_t *card; } plip_t; @@ -334,6 +343,9 @@ plip_write_data(uint8_t val, void *priv) /* Disengage timeout timer. */ timer_disable(&dev->timeout_timer); return; + + default: + break; } /* Engage timeout timer unless otherwise specified. */ @@ -356,7 +368,7 @@ plip_write_ctrl(uint8_t val, void *priv) static uint8_t plip_read_status(void *priv) { - plip_t *dev = (plip_t *) priv; + const plip_t *dev = (plip_t *) priv; plip_log(3, "PLIP: read_status() = %02X\n", dev->status); @@ -454,7 +466,7 @@ plip_lpt_init(void *lpt) } static void * -plip_net_init(const device_t *info) +plip_net_init(UNUSED(const device_t *info)) { plip_log(1, "PLIP: net_init()"); diff --git a/src/network/net_slirp.c b/src/network/net_slirp.c index 9e979c380..6aff76a90 100644 --- a/src/network/net_slirp.c +++ b/src/network/net_slirp.c @@ -58,7 +58,7 @@ enum { NET_EVENT_MAX }; -typedef struct { +typedef struct net_slirp_t { Slirp *slirp; uint8_t mac_addr[6]; netcard_t *card; /* netcard attached to us */ @@ -68,9 +68,10 @@ typedef struct { netpkt_t pkt; netpkt_t pkt_tx_v[SLIRP_PKT_BATCH]; #ifdef _WIN32 - HANDLE sock_event; + HANDLE sock_event; #else - uint32_t pfd_len, pfd_size; + uint32_t pfd_len; + uint32_t pfd_size; struct pollfd *pfd; #endif } net_slirp_t; @@ -94,19 +95,19 @@ slirp_log(const char *fmt, ...) #endif static void -net_slirp_guest_error(const char *msg, void *opaque) +net_slirp_guest_error(UNUSED(const char *msg), UNUSED(void *opaque)) { slirp_log("SLiRP: guest_error(): %s\n", msg); } static int64_t -net_slirp_clock_get_ns(void *opaque) +net_slirp_clock_get_ns(UNUSED(void *opaque)) { return (int64_t) ((double) tsc / cpuclock * 1000000000.0); } static void * -net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, void *opaque) +net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, UNUSED(void *opaque)) { pc_timer_t *timer = malloc(sizeof(pc_timer_t)); timer_add(timer, cb, cb_opaque, 0); @@ -114,14 +115,14 @@ net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, void *opaque) } static void -net_slirp_timer_free(void *timer, void *opaque) +net_slirp_timer_free(void *timer, UNUSED(void *opaque)) { timer_stop(timer); free(timer); } static void -net_slirp_timer_mod(void *timer, int64_t expire_timer, void *opaque) +net_slirp_timer_mod(void *timer, int64_t expire_timer, UNUSED(void *opaque)) { timer_on_auto(timer, expire_timer * 1000); } @@ -384,7 +385,7 @@ static int slirp_card_num = 2; /* Initialize SLiRP for use. */ void * -net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, void *priv, char *netdrv_errbuf) +net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, UNUSED(void *priv), char *netdrv_errbuf) { slirp_log("SLiRP: initializing...\n"); net_slirp_t *slirp = calloc(1, sizeof(net_slirp_t)); @@ -493,15 +494,3 @@ const netdrv_t net_slirp_drv = { &net_slirp_init, &net_slirp_close }; - -/* Stubs to stand in for the parts of libslirp we skip compiling. */ -void ncsi_input(void *slirp, const uint8_t *pkt, int pkt_len) {} -void ip6_init(void *slirp) {} -void in6_compute_ethaddr(struct in6_addr ip, uint8_t *eth) {} -bool in6_equal(const void *a, const void *b) { return 0; } -const struct in6_addr in6addr_any = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }; -const struct in6_addr in6addr_loopback = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }; -void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, - uint8_t ethaddr[6]) {} /* IPv6 */ -bool ndp_table_search(void *slirp, struct in6_addr ip_addr, uint8_t *out_ethaddr) { return 0; } -void tftp_input(void *srcsas, void *m) {} diff --git a/src/network/net_vde.c b/src/network/net_vde.c index 5bcf1ffff..afeeaac9c 100644 --- a/src/network/net_vde.c +++ b/src/network/net_vde.c @@ -62,15 +62,15 @@ static volatile void *libvde_handle = NULL; //+ // VDE connection structure //- -typedef struct { - void *vdeconn; // VDEPLUG Connection - netcard_t *card; // NIC linked to - thread_t *poll_tid; // Polling thread - net_evt_t tx_event; // Packets to transmit event - net_evt_t stop_event; // Stop thread event - netpkt_t pkt; // Packet read/sent - netpkt_t pktv[VDE_PKT_BATCH]; // Packet queue - uint8_t mac_addr[6]; // MAC Address +typedef struct net_vde_t { + void *vdeconn; // VDEPLUG Connection + netcard_t *card; // NIC linked to + thread_t *poll_tid; // Polling thread + net_evt_t tx_event; // Packets to transmit event + net_evt_t stop_event; // Stop thread event + netpkt_t pkt; // Packet read/sent + netpkt_t pktv[VDE_PKT_BATCH]; // Packet queue + uint8_t mac_addr[6]; // MAC Address } net_vde_t; //+ @@ -221,7 +221,7 @@ void net_vde_close(void *priv) { free(vde->pktv[i].data); } free(vde->pkt.data); - f_vde_close((void *) vde->vdeconn); + f_vde_close(vde->vdeconn); net_event_close(&vde->tx_event); net_event_close(&vde->stop_event); free(vde); diff --git a/src/network/net_wd8003.c b/src/network/net_wd8003.c index 385f4332a..61c35986d 100644 --- a/src/network/net_wd8003.c +++ b/src/network/net_wd8003.c @@ -64,6 +64,8 @@ #include <86box/net_dp8390.h> #include <86box/net_wd8003.h> #include <86box/bswap.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #include "cpu.h" @@ -98,12 +100,14 @@ #define WE_ID_EXTRA_RAM 0x40 #define WE_ID_BUS_MCA 0x80 -typedef struct { +typedef struct wd_t { dp8390_t *dp8390; mem_mapping_t ram_mapping; - uint32_t ram_addr, ram_size; + uint32_t ram_addr; + uint32_t ram_size; uint8_t maclocal[6]; /* configured MAC (local) address */ - uint8_t bit16, pad; + uint8_t bit16; + uint8_t pad; int board; const char *name; uint32_t base_address; @@ -113,11 +117,12 @@ typedef struct { uint8_t pos_regs[8]; /* Memory for WD cards*/ - uint8_t msr, /* Memory Select Register (MSR) */ - icr, /* Interface Configuration Register (ICR) */ - irr, /* Interrupt Request Register (IRR) */ - laar, /* LA Address Register (read by Windows 98!) */ - if_chip, board_chip; + uint8_t msr; /* Memory Select Register (MSR) */ + uint8_t icr; /* Interface Configuration Register (ICR) */ + uint8_t irr; /* Interrupt Request Register (IRR) */ + uint8_t laar; /* LA Address Register (read by Windows 98!) */ + uint8_t if_chip; + uint8_t board_chip; } wd_t; #ifdef ENABLE_WD_LOG @@ -143,7 +148,7 @@ static const int we_int_table[4] = { 2, 3, 4, 7 }; static void wd_interrupt(void *priv, int set) { - wd_t *dev = (wd_t *) priv; + const wd_t *dev = (wd_t *) priv; if (!(dev->irr & WE_IRR_ENABLE_IRQ)) return; @@ -176,7 +181,7 @@ wd_soft_reset(void *priv) static uint8_t wd_ram_read(uint32_t addr, void *priv) { - wd_t *dev = (wd_t *) priv; + const wd_t *dev = (wd_t *) priv; wdlog("WD80x3: RAM Read: addr=%06x, val=%02x\n", addr & (dev->ram_size - 1), dev->dp8390->mem[addr & (dev->ram_size - 1)]); return dev->dp8390->mem[addr & (dev->ram_size - 1)]; @@ -280,6 +285,9 @@ wd_smc_read(wd_t *dev, uint32_t off) retval = 0xff - (checksum & 0xff); break; + + default: + break; } wdlog("%s: ASIC read addr=0x%02x, value=0x%04x\n", @@ -513,7 +521,7 @@ wd_io_remove(wd_t *dev, uint16_t addr) static uint8_t wd_mca_read(int port, void *priv) { - wd_t *dev = (wd_t *) priv; + const wd_t *dev = (wd_t *) priv; return (dev->pos_regs[port & 7]); } @@ -602,6 +610,9 @@ wd_8013epa_mca_write(int port, uint8_t val, void *priv) case 0x0c: dev->irq = 14; break; + + default: + break; } if (dev->pos_regs[3] & 0x10) @@ -629,7 +640,7 @@ wd_8013epa_mca_write(int port, uint8_t val, void *priv) } static uint8_t -wd_mca_feedb(void *priv) +wd_mca_feedb(UNUSED(void *priv)) { return 1; } @@ -724,6 +735,9 @@ wd_init(const device_t *info) /* Ethernet, MCA, 5x3 interface chip, RAM 16k */ case WD8003EA: dev->board_chip = WE_ID_SOFT_CONFIG; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif /* Ethernet, MCA, no interface chip, RAM 16k */ case WD8003ETA: dev->board_chip |= WE_TYPE_WD8013EBT | WE_ID_BUS_MCA; @@ -740,6 +754,9 @@ wd_init(const device_t *info) dev->pos_regs[1] = 0x61; dev->bit16 = 3; break; + + default: + break; } dev->irr |= WE_IRR_ENABLE_IRQ; diff --git a/src/network/pcap_if.c b/src/network/pcap_if.c index 19abb74c3..1d3e39221 100644 --- a/src/network/pcap_if.c +++ b/src/network/pcap_if.c @@ -176,7 +176,7 @@ start_cap(char *dev) char temp[PCAP_ERRBUF_SIZE]; struct pcap_pkthdr *hdr; const unsigned char *pkt; - struct tm *ltime; + const struct tm *ltime; time_t now; pcap_t *pcap; int rc; diff --git a/src/network/slirp/CMakeLists.txt b/src/network/slirp/CMakeLists.txt deleted file mode 100644 index 60993ad84..000000000 --- a/src/network/slirp/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# -# 86Box A hypervisor and IBM PC system emulator that specializes in -# running old operating systems and software designed for IBM -# PC systems and compatibles from 1981 through fairly recent -# system designs based on the PCI bus. -# -# This file is part of the 86Box distribution. -# -# CMake build script. -# -# Authors: David Hrdlička, -# -# Copyright 2020-2021 David Hrdlička. -# - -add_library(slirp STATIC arp_table.c bootp.c cksum.c dhcpv6.c dnssearch.c if.c - ip_icmp.c ip_input.c ip_output.c - ip6_icmp.c ip6_input.c ip6_output.c - mbuf.c misc.c sbuf.c slirp.c socket.c - tcp_input.c tcp_output.c tcp_subr.c tcp_timer.c - udp.c udp6.c - util.c version.c) - -if(WIN32) - target_link_libraries(slirp wsock32 iphlpapi) -endif() - -if(APPLE) - target_link_libraries(slirp resolv) -endif() - -# tinyglib conflicts with the real GLib used by Qt, let's just be safe -if(QT AND UNIX AND NOT APPLE) - set(SLIRP_TINYGLIB OFF) -endif() - -option(SLIRP_TINYGLIB "Use a minimal GLib stub (`tinyglib`) with SLiRP" ON) - -if(SLIRP_TINYGLIB) - target_sources(slirp PRIVATE tinyglib.c) -else() - find_package(PkgConfig REQUIRED) - pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) - target_link_libraries(slirp PkgConfig::GLIB) - - target_compile_definitions(slirp PRIVATE TINYGLIB_USE_GLIB) -endif() diff --git a/src/network/slirp/arp_table.c b/src/network/slirp/arp_table.c deleted file mode 100644 index d0c9111d6..000000000 --- a/src/network/slirp/arp_table.c +++ /dev/null @@ -1,104 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * ARP table - * - * Copyright (c) 2011 AdaCore - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "slirp.h" - -#include - -void arp_table_add(Slirp *slirp, uint32_t ip_addr, - const uint8_t ethaddr[ETH_ALEN]) -{ - const uint32_t broadcast_addr = - ~slirp->vnetwork_mask.s_addr | slirp->vnetwork_addr.s_addr; - ArpTable *arptbl = &slirp->arp_table; - int i; -/* - char ethaddr_str[ETH_ADDRSTRLEN]; - char addr[INET_ADDRSTRLEN]; - - DEBUG_CALL("arp_table_add"); - DEBUG_ARG("ip = %s", inet_ntop(AF_INET, &(struct in_addr){ .s_addr = ip_addr }, - addr, sizeof(addr))); - DEBUG_ARG("hw addr = %s", slirp_ether_ntoa(ethaddr, ethaddr_str, - sizeof(ethaddr_str))); -*/ - - if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) { - /* Do not register broadcast addresses */ - return; - } - - /* Search for an entry */ - for (i = 0; i < ARP_TABLE_SIZE; i++) { - if (arptbl->table[i].ar_sip == ip_addr) { - /* Update the entry */ - memcpy(arptbl->table[i].ar_sha, ethaddr, ETH_ALEN); - return; - } - } - - /* No entry found, create a new one */ - arptbl->table[arptbl->next_victim].ar_sip = ip_addr; - memcpy(arptbl->table[arptbl->next_victim].ar_sha, ethaddr, ETH_ALEN); - arptbl->next_victim = (arptbl->next_victim + 1) % ARP_TABLE_SIZE; -} - -bool arp_table_search(Slirp *slirp, uint32_t ip_addr, - uint8_t out_ethaddr[ETH_ALEN]) -{ - const uint32_t broadcast_addr = - ~slirp->vnetwork_mask.s_addr | slirp->vnetwork_addr.s_addr; - ArpTable *arptbl = &slirp->arp_table; - int i; -/* - char ethaddr_str[ETH_ADDRSTRLEN]; - char addr[INET_ADDRSTRLEN]; - - DEBUG_CALL("arp_table_search"); - DEBUG_ARG("ip = %s", inet_ntop(AF_INET, &(struct in_addr){ .s_addr = ip_addr }, - addr, sizeof(addr))); -*/ - - /* If broadcast address */ - if (ip_addr == 0 || ip_addr == 0xffffffff || ip_addr == broadcast_addr) { - /* return Ethernet broadcast address */ - memset(out_ethaddr, 0xff, ETH_ALEN); - return 1; - } - - for (i = 0; i < ARP_TABLE_SIZE; i++) { - if (arptbl->table[i].ar_sip == ip_addr) { - memcpy(out_ethaddr, arptbl->table[i].ar_sha, ETH_ALEN); -/* - DEBUG_ARG("found hw addr = %s", - slirp_ether_ntoa(out_ethaddr, ethaddr_str, - sizeof(ethaddr_str))); -*/ - return 1; - } - } - - return 0; -} diff --git a/src/network/slirp/bootp.c b/src/network/slirp/bootp.c deleted file mode 100644 index a0eb17a9d..000000000 --- a/src/network/slirp/bootp.c +++ /dev/null @@ -1,398 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * QEMU BOOTP/DHCP server - * - * Copyright (c) 2004 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "slirp.h" - -#if defined(_WIN32) -/* Windows ntohl() returns an u_long value. - * Add a type cast to match the format strings. */ -#define ntohl(n) ((uint32_t)ntohl(n)) -#endif - -/* XXX: only DHCP is supported */ - -#define LEASE_TIME (24 * 3600) - -#define UEFI_HTTP_VENDOR_CLASS_ID "HTTPClient" - -static const uint8_t rfc1533_cookie[] = { RFC1533_COOKIE }; - -#define DPRINTF(fmt, ...) DEBUG_CALL(fmt, ##__VA_ARGS__) - -static BOOTPClient *get_new_addr(Slirp *slirp, struct in_addr *paddr, - const uint8_t *macaddr) -{ - BOOTPClient *bc; - int i; - - for (i = 0; i < NB_BOOTP_CLIENTS; i++) { - bc = &slirp->bootp_clients[i]; - if (!bc->allocated || !memcmp(macaddr, bc->macaddr, 6)) - goto found; - } - return NULL; -found: - bc = &slirp->bootp_clients[i]; - bc->allocated = 1; - paddr->s_addr = slirp->vdhcp_startaddr.s_addr + htonl(i); - return bc; -} - -static BOOTPClient *request_addr(Slirp *slirp, const struct in_addr *paddr, - const uint8_t *macaddr) -{ - uint32_t req_addr = ntohl(paddr->s_addr); - uint32_t dhcp_addr = ntohl(slirp->vdhcp_startaddr.s_addr); - BOOTPClient *bc; - - if (req_addr >= dhcp_addr && req_addr < (dhcp_addr + NB_BOOTP_CLIENTS)) { - bc = &slirp->bootp_clients[req_addr - dhcp_addr]; - if (!bc->allocated || !memcmp(macaddr, bc->macaddr, 6)) { - bc->allocated = 1; - return bc; - } - } - return NULL; -} - -static BOOTPClient *find_addr(Slirp *slirp, struct in_addr *paddr, - const uint8_t *macaddr) -{ - BOOTPClient *bc; - int i; - - for (i = 0; i < NB_BOOTP_CLIENTS; i++) { - if (!memcmp(macaddr, slirp->bootp_clients[i].macaddr, 6)) - goto found; - } - return NULL; -found: - bc = &slirp->bootp_clients[i]; - bc->allocated = 1; - paddr->s_addr = slirp->vdhcp_startaddr.s_addr + htonl(i); - return bc; -} - -static void dhcp_decode(const struct bootp_t *bp, - const uint8_t *bp_end, - int *pmsg_type, - struct in_addr *preq_addr) -{ - const uint8_t *p; - int len, tag; - - *pmsg_type = 0; - preq_addr->s_addr = htonl(0L); - - p = bp->bp_vend; - if (memcmp(p, rfc1533_cookie, 4) != 0) - return; - p += 4; - while (p < bp_end) { - tag = p[0]; - if (tag == RFC1533_PAD) { - p++; - } else if (tag == RFC1533_END) { - break; - } else { - p++; - if (p >= bp_end) - break; - len = *p++; - if (p + len > bp_end) { - break; - } - DPRINTF("dhcp: tag=%d len=%d\n", tag, len); - - switch (tag) { - case RFC2132_MSG_TYPE: - if (len >= 1) - *pmsg_type = p[0]; - break; - case RFC2132_REQ_ADDR: - if (len >= 4) { - memcpy(&(preq_addr->s_addr), p, 4); - } - break; - default: - break; - } - p += len; - } - } - if (*pmsg_type == DHCPREQUEST && preq_addr->s_addr == htonl(0L) && - bp->bp_ciaddr.s_addr) { - memcpy(&(preq_addr->s_addr), &bp->bp_ciaddr, 4); - } -} - -static void bootp_reply(Slirp *slirp, - const struct bootp_t *bp, - const uint8_t *bp_end) -{ - BOOTPClient *bc = NULL; - struct mbuf *m; - struct bootp_t *rbp; - struct sockaddr_in saddr, daddr; - struct in_addr preq_addr; - int dhcp_msg_type, val; - uint8_t *q; - uint8_t *end; - uint8_t client_ethaddr[ETH_ALEN]; - - /* extract exact DHCP msg type */ - dhcp_decode(bp, bp_end, &dhcp_msg_type, &preq_addr); - DPRINTF("bootp packet op=%d msgtype=%d", bp->bp_op, dhcp_msg_type); - if (preq_addr.s_addr != htonl(0L)) - DPRINTF(" req_addr=%08" PRIx32 "\n", ntohl(preq_addr.s_addr)); - else { - DPRINTF("\n"); - } - - if (dhcp_msg_type == 0) - dhcp_msg_type = DHCPREQUEST; /* Force reply for old BOOTP clients */ - - if (dhcp_msg_type != DHCPDISCOVER && dhcp_msg_type != DHCPREQUEST) - return; - - /* Get client's hardware address from bootp request */ - memcpy(client_ethaddr, bp->bp_hwaddr, ETH_ALEN); - - m = m_get(slirp); - if (!m) { - return; - } - m->m_data += IF_MAXLINKHDR; - m_inc(m, sizeof(struct bootp_t) + DHCP_OPT_LEN); - rbp = (struct bootp_t *)m->m_data; - m->m_data += sizeof(struct udpiphdr); - memset(rbp, 0, sizeof(struct bootp_t) + DHCP_OPT_LEN); - - if (dhcp_msg_type == DHCPDISCOVER) { - if (preq_addr.s_addr != htonl(0L)) { - bc = request_addr(slirp, &preq_addr, client_ethaddr); - if (bc) { - daddr.sin_addr = preq_addr; - } - } - if (!bc) { - new_addr: - bc = get_new_addr(slirp, &daddr.sin_addr, client_ethaddr); - if (!bc) { - DPRINTF("no address left\n"); - return; - } - } - memcpy(bc->macaddr, client_ethaddr, ETH_ALEN); - } else if (preq_addr.s_addr != htonl(0L)) { - bc = request_addr(slirp, &preq_addr, client_ethaddr); - if (bc) { - daddr.sin_addr = preq_addr; - memcpy(bc->macaddr, client_ethaddr, ETH_ALEN); - } else { - /* DHCPNAKs should be sent to broadcast */ - daddr.sin_addr.s_addr = 0xffffffff; - } - } else { - bc = find_addr(slirp, &daddr.sin_addr, bp->bp_hwaddr); - if (!bc) { - /* if never assigned, behaves as if it was already - assigned (windows fix because it remembers its address) */ - goto new_addr; - } - } - - /* Update ARP table for this IP address */ - arp_table_add(slirp, daddr.sin_addr.s_addr, client_ethaddr); - - saddr.sin_addr = slirp->vhost_addr; - saddr.sin_port = htons(BOOTP_SERVER); - - daddr.sin_port = htons(BOOTP_CLIENT); - - rbp->bp_op = BOOTP_REPLY; - rbp->bp_xid = bp->bp_xid; - rbp->bp_htype = 1; - rbp->bp_hlen = 6; - memcpy(rbp->bp_hwaddr, bp->bp_hwaddr, ETH_ALEN); - - rbp->bp_yiaddr = daddr.sin_addr; /* Client IP address */ - rbp->bp_siaddr = saddr.sin_addr; /* Server IP address */ - - q = rbp->bp_vend; - end = rbp->bp_vend + DHCP_OPT_LEN; - memcpy(q, rfc1533_cookie, 4); - q += 4; - - if (bc) { - DPRINTF("%s addr=%08" PRIx32 "\n", - (dhcp_msg_type == DHCPDISCOVER) ? "offered" : "ack'ed", - ntohl(daddr.sin_addr.s_addr)); - - if (dhcp_msg_type == DHCPDISCOVER) { - *q++ = RFC2132_MSG_TYPE; - *q++ = 1; - *q++ = DHCPOFFER; - } else /* DHCPREQUEST */ { - *q++ = RFC2132_MSG_TYPE; - *q++ = 1; - *q++ = DHCPACK; - } - - if (slirp->bootp_filename) { - g_assert(strlen(slirp->bootp_filename) < sizeof(rbp->bp_file)); - strcpy(rbp->bp_file, slirp->bootp_filename); - } - - *q++ = RFC2132_SRV_ID; - *q++ = 4; - memcpy(q, &saddr.sin_addr, 4); - q += 4; - - *q++ = RFC1533_NETMASK; - *q++ = 4; - memcpy(q, &slirp->vnetwork_mask, 4); - q += 4; - - if (!slirp->restricted) { - *q++ = RFC1533_GATEWAY; - *q++ = 4; - memcpy(q, &saddr.sin_addr, 4); - q += 4; - - *q++ = RFC1533_DNS; - *q++ = 4; - memcpy(q, &slirp->vnameserver_addr, 4); - q += 4; - } - - *q++ = RFC2132_LEASE_TIME; - *q++ = 4; - val = htonl(LEASE_TIME); - memcpy(q, &val, 4); - q += 4; - - if (*slirp->client_hostname) { - val = strlen(slirp->client_hostname); - if (q + val + 2 >= end) { - g_warning("DHCP packet size exceeded, " - "omitting host name option."); - } else { - *q++ = RFC1533_HOSTNAME; - *q++ = val; - memcpy(q, slirp->client_hostname, val); - q += val; - } - } - - if (slirp->vdomainname) { - val = strlen(slirp->vdomainname); - if (q + val + 2 >= end) { - g_warning("DHCP packet size exceeded, " - "omitting domain name option."); - } else { - *q++ = RFC1533_DOMAINNAME; - *q++ = val; - memcpy(q, slirp->vdomainname, val); - q += val; - } - } - - if (slirp->tftp_server_name) { - val = strlen(slirp->tftp_server_name); - if (q + val + 2 >= end) { - g_warning("DHCP packet size exceeded, " - "omitting tftp-server-name option."); - } else { - *q++ = RFC2132_TFTP_SERVER_NAME; - *q++ = val; - memcpy(q, slirp->tftp_server_name, val); - q += val; - } - } - - if (slirp->vdnssearch) { - val = slirp->vdnssearch_len; - if (q + val >= end) { - g_warning("DHCP packet size exceeded, " - "omitting domain-search option."); - } else { - memcpy(q, slirp->vdnssearch, val); - q += val; - } - } - - /* this allows to support UEFI HTTP boot: according to the UEFI - specification, DHCP server must send vendor class identifier option - set to "HTTPClient" string, when responding to DHCP requests as part - of the UEFI HTTP boot - - we assume that, if the bootfile parameter was configured as an http - URL, the user intends to perform UEFI HTTP boot, so send this option - automatically */ - if (slirp->bootp_filename && g_str_has_prefix(slirp->bootp_filename, "http://")) { - val = strlen(UEFI_HTTP_VENDOR_CLASS_ID); - if (q + val + 2 >= end) { - g_warning("DHCP packet size exceeded, " - "omitting vendor class id option."); - } else { - *q++ = RFC2132_VENDOR_CLASS_ID; - *q++ = val; - memcpy(q, UEFI_HTTP_VENDOR_CLASS_ID, val); - q += val; - } - } - } else { - static const char nak_msg[] = "requested address not available"; - - DPRINTF("nak'ed addr=%08" PRIx32 "\n", ntohl(preq_addr.s_addr)); - - *q++ = RFC2132_MSG_TYPE; - *q++ = 1; - *q++ = DHCPNAK; - - *q++ = RFC2132_MESSAGE; - *q++ = sizeof(nak_msg) - 1; - memcpy(q, nak_msg, sizeof(nak_msg) - 1); - q += sizeof(nak_msg) - 1; - } - assert(q < end); - *q++ = RFC1533_END; - - daddr.sin_addr.s_addr = 0xffffffffu; - - assert(q <= end); - - m->m_len = sizeof(struct bootp_t) + (end - rbp->bp_vend) - sizeof(struct ip) - sizeof(struct udphdr); - udp_output(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); -} - -void bootp_input(struct mbuf *m) -{ - struct bootp_t *bp = mtod_check(m, sizeof(struct bootp_t)); - - if (!m->slirp->disable_dhcp && bp && bp->bp_op == BOOTP_REQUEST) { - bootp_reply(m->slirp, bp, m_end(m)); - } -} diff --git a/src/network/slirp/bootp.h b/src/network/slirp/bootp.h deleted file mode 100644 index cf7797fac..000000000 --- a/src/network/slirp/bootp.h +++ /dev/null @@ -1,130 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* bootp/dhcp defines */ - -#ifndef SLIRP_BOOTP_H -#define SLIRP_BOOTP_H - -#define BOOTP_SERVER 67 -#define BOOTP_CLIENT 68 - -#define BOOTP_REQUEST 1 -#define BOOTP_REPLY 2 - -#define RFC1533_COOKIE 99, 130, 83, 99 -#define RFC1533_PAD 0 -#define RFC1533_NETMASK 1 -#define RFC1533_TIMEOFFSET 2 -#define RFC1533_GATEWAY 3 -#define RFC1533_TIMESERVER 4 -#define RFC1533_IEN116NS 5 -#define RFC1533_DNS 6 -#define RFC1533_LOGSERVER 7 -#define RFC1533_COOKIESERVER 8 -#define RFC1533_LPRSERVER 9 -#define RFC1533_IMPRESSSERVER 10 -#define RFC1533_RESOURCESERVER 11 -#define RFC1533_HOSTNAME 12 -#define RFC1533_BOOTFILESIZE 13 -#define RFC1533_MERITDUMPFILE 14 -#define RFC1533_DOMAINNAME 15 -#define RFC1533_SWAPSERVER 16 -#define RFC1533_ROOTPATH 17 -#define RFC1533_EXTENSIONPATH 18 -#define RFC1533_IPFORWARDING 19 -#define RFC1533_IPSOURCEROUTING 20 -#define RFC1533_IPPOLICYFILTER 21 -#define RFC1533_IPMAXREASSEMBLY 22 -#define RFC1533_IPTTL 23 -#define RFC1533_IPMTU 24 -#define RFC1533_IPMTUPLATEAU 25 -#define RFC1533_INTMTU 26 -#define RFC1533_INTLOCALSUBNETS 27 -#define RFC1533_INTBROADCAST 28 -#define RFC1533_INTICMPDISCOVER 29 -#define RFC1533_INTICMPRESPOND 30 -#define RFC1533_INTROUTEDISCOVER 31 -#define RFC1533_INTROUTESOLICIT 32 -#define RFC1533_INTSTATICROUTES 33 -#define RFC1533_LLTRAILERENCAP 34 -#define RFC1533_LLARPCACHETMO 35 -#define RFC1533_LLETHERNETENCAP 36 -#define RFC1533_TCPTTL 37 -#define RFC1533_TCPKEEPALIVETMO 38 -#define RFC1533_TCPKEEPALIVEGB 39 -#define RFC1533_NISDOMAIN 40 -#define RFC1533_NISSERVER 41 -#define RFC1533_NTPSERVER 42 -#define RFC1533_VENDOR 43 -#define RFC1533_NBNS 44 -#define RFC1533_NBDD 45 -#define RFC1533_NBNT 46 -#define RFC1533_NBSCOPE 47 -#define RFC1533_XFS 48 -#define RFC1533_XDM 49 - -#define RFC2132_REQ_ADDR 50 -#define RFC2132_LEASE_TIME 51 -#define RFC2132_MSG_TYPE 53 -#define RFC2132_SRV_ID 54 -#define RFC2132_PARAM_LIST 55 -#define RFC2132_MESSAGE 56 -#define RFC2132_MAX_SIZE 57 -#define RFC2132_RENEWAL_TIME 58 -#define RFC2132_REBIND_TIME 59 -#define RFC2132_VENDOR_CLASS_ID 60 -#define RFC2132_TFTP_SERVER_NAME 66 - -#define DHCPDISCOVER 1 -#define DHCPOFFER 2 -#define DHCPREQUEST 3 -#define DHCPACK 5 -#define DHCPNAK 6 - -#define RFC1533_VENDOR_MAJOR 0 -#define RFC1533_VENDOR_MINOR 0 - -#define RFC1533_VENDOR_MAGIC 128 -#define RFC1533_VENDOR_ADDPARM 129 -#define RFC1533_VENDOR_ETHDEV 130 -#define RFC1533_VENDOR_HOWTO 132 -#define RFC1533_VENDOR_MNUOPTS 160 -#define RFC1533_VENDOR_SELECTION 176 -#define RFC1533_VENDOR_MOTD 184 -#define RFC1533_VENDOR_NUMOFMOTD 8 -#define RFC1533_VENDOR_IMG 192 -#define RFC1533_VENDOR_NUMOFIMG 16 - -#define RFC1533_END 255 -#define BOOTP_VENDOR_LEN 64 -#define DHCP_OPT_LEN 312 - -struct bootp_t { - struct ip ip; - struct udphdr udp; - uint8_t bp_op; - uint8_t bp_htype; - uint8_t bp_hlen; - uint8_t bp_hops; - uint32_t bp_xid; - uint16_t bp_secs; - uint16_t unused; - struct in_addr bp_ciaddr; - struct in_addr bp_yiaddr; - struct in_addr bp_siaddr; - struct in_addr bp_giaddr; - uint8_t bp_hwaddr[16]; - uint8_t bp_sname[64]; - char bp_file[128]; - uint8_t bp_vend[]; -}; - -typedef struct { - uint16_t allocated; - uint8_t macaddr[6]; -} BOOTPClient; - -#define NB_BOOTP_CLIENTS 16 - -void bootp_input(struct mbuf *m); - -#endif diff --git a/src/network/slirp/cksum.c b/src/network/slirp/cksum.c deleted file mode 100644 index b1cb97b7e..000000000 --- a/src/network/slirp/cksum.c +++ /dev/null @@ -1,179 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1988, 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)in_cksum.c 8.1 (Berkeley) 6/10/93 - * in_cksum.c,v 1.2 1994/08/02 07:48:16 davidg Exp - */ - -#include "slirp.h" - -/* - * Checksum routine for Internet Protocol family headers (Portable Version). - * - * This routine is very heavily used in the network - * code and should be modified for each CPU to be as fast as possible. - * - * XXX Since we will never span more than 1 mbuf, we can optimise this - */ - -#define ADDCARRY(x) (x > 65535 ? x -= 65535 : x) -#define REDUCE \ - { \ - l_util.l = sum; \ - sum = l_util.s[0] + l_util.s[1]; \ - ADDCARRY(sum); \ - } - -int cksum(struct mbuf *m, int len) -{ - register uint16_t *w; - register int sum = 0; - register int mlen = 0; - int byte_swapped = 0; - - union { - uint8_t c[2]; - uint16_t s; - } s_util; - union { - uint16_t s[2]; - uint32_t l; - } l_util; - - if (m->m_len == 0) - goto cont; - w = mtod(m, uint16_t *); - - mlen = m->m_len; - - if (len < mlen) - mlen = len; - len -= mlen; - /* - * Force to even boundary. - */ - if ((1 & (uintptr_t)w) && (mlen > 0)) { - REDUCE; - sum <<= 8; - s_util.c[0] = *(uint8_t *)w; - w = (uint16_t *)((int8_t *)w + 1); - mlen--; - byte_swapped = 1; - } - /* - * Unroll the loop to make overhead from - * branches &c small. - */ - while ((mlen -= 32) >= 0) { - sum += w[0]; - sum += w[1]; - sum += w[2]; - sum += w[3]; - sum += w[4]; - sum += w[5]; - sum += w[6]; - sum += w[7]; - sum += w[8]; - sum += w[9]; - sum += w[10]; - sum += w[11]; - sum += w[12]; - sum += w[13]; - sum += w[14]; - sum += w[15]; - w += 16; - } - mlen += 32; - while ((mlen -= 8) >= 0) { - sum += w[0]; - sum += w[1]; - sum += w[2]; - sum += w[3]; - w += 4; - } - mlen += 8; - if (mlen == 0 && byte_swapped == 0) - goto cont; - REDUCE; - while ((mlen -= 2) >= 0) { - sum += *w++; - } - - if (byte_swapped) { - REDUCE; - sum <<= 8; - if (mlen == -1) { - s_util.c[1] = *(uint8_t *)w; - sum += s_util.s; - mlen = 0; - } else - - mlen = -1; - } else if (mlen == -1) - s_util.c[0] = *(uint8_t *)w; - -cont: - if (len) { - DEBUG_ERROR("cksum: out of data"); - DEBUG_ERROR(" len = %d", len); - } - if (mlen == -1) { - /* The last mbuf has odd # of bytes. Follow the - standard (the odd byte may be shifted left by 8 bits - or not as determined by endian-ness of the machine) */ - s_util.c[1] = 0; - sum += s_util.s; - } - REDUCE; - return (~sum & 0xffff); -} - -int ip6_cksum(struct mbuf *m) -{ - /* TODO: Optimize this by being able to pass the ip6_pseudohdr to cksum - * separately from the mbuf */ - struct ip6 save_ip, *ip = mtod(m, struct ip6 *); - struct ip6_pseudohdr *ih = mtod(m, struct ip6_pseudohdr *); - int sum; - - save_ip = *ip; - - ih->ih_src = save_ip.ip_src; - ih->ih_dst = save_ip.ip_dst; - ih->ih_pl = htonl((uint32_t)ntohs(save_ip.ip_pl)); - ih->ih_zero_hi = 0; - ih->ih_zero_lo = 0; - ih->ih_nh = save_ip.ip_nh; - - sum = cksum(m, ((int)sizeof(struct ip6_pseudohdr)) + ntohl(ih->ih_pl)); - - *ip = save_ip; - - return sum; -} diff --git a/src/network/slirp/debug.h b/src/network/slirp/debug.h deleted file mode 100644 index 0f9f3eff3..000000000 --- a/src/network/slirp/debug.h +++ /dev/null @@ -1,59 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef DEBUG_H_ -#define DEBUG_H_ - -#define DBG_CALL (1 << 0) -#define DBG_MISC (1 << 1) -#define DBG_ERROR (1 << 2) -#define DBG_TFTP (1 << 3) -#define DBG_VERBOSE_CALL (1 << 4) - -extern int slirp_debug; - -#define DEBUG_CALL(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_CALL)) { \ - g_debug(fmt "...", ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_VERBOSE_CALL(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_VERBOSE_CALL)) { \ - g_debug(fmt "...", ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_ARG(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_CALL)) { \ - g_debug(" " fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_MISC(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_MISC)) { \ - g_debug(fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_ERROR(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_ERROR)) { \ - g_debug(fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#define DEBUG_TFTP(fmt, ...) \ - do { \ - if (G_UNLIKELY(slirp_debug & DBG_TFTP)) { \ - g_debug(fmt, ##__VA_ARGS__); \ - } \ - } while (0) - -#endif /* DEBUG_H_ */ diff --git a/src/network/slirp/dhcpv6.c b/src/network/slirp/dhcpv6.c deleted file mode 100644 index 77b451b91..000000000 --- a/src/network/slirp/dhcpv6.c +++ /dev/null @@ -1,224 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * SLIRP stateless DHCPv6 - * - * We only support stateless DHCPv6, e.g. for network booting. - * See RFC 3315, RFC 3736, RFC 3646 and RFC 5970 for details. - * - * Copyright 2016 Thomas Huth, Red Hat Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "slirp.h" -#include "dhcpv6.h" - -/* DHCPv6 message types */ -#define MSGTYPE_REPLY 7 -#define MSGTYPE_INFO_REQUEST 11 - -/* DHCPv6 option types */ -#define OPTION_CLIENTID 1 -#define OPTION_IAADDR 5 -#define OPTION_ORO 6 -#define OPTION_DNS_SERVERS 23 -#define OPTION_BOOTFILE_URL 59 - -struct requested_infos { - uint8_t *client_id; - int client_id_len; - bool want_dns; - bool want_boot_url; -}; - -/** - * Analyze the info request message sent by the client to see what data it - * provided and what it wants to have. The information is gathered in the - * "requested_infos" struct. Note that client_id (if provided) points into - * the odata region, thus the caller must keep odata valid as long as it - * needs to access the requested_infos struct. - */ -static int dhcpv6_parse_info_request(Slirp *slirp, uint8_t *odata, int olen, - struct requested_infos *ri) -{ - int i, req_opt; - - while (olen > 4) { - /* Parse one option */ - int option = odata[0] << 8 | odata[1]; - int len = odata[2] << 8 | odata[3]; - - if (len + 4 > olen) { - slirp->cb->guest_error("Guest sent bad DHCPv6 packet!", - slirp->opaque); - return -E2BIG; - } - - switch (option) { - case OPTION_IAADDR: - /* According to RFC3315, we must discard requests with IA option */ - return -EINVAL; - case OPTION_CLIENTID: - if (len > 256) { - /* Avoid very long IDs which could cause problems later */ - return -E2BIG; - } - ri->client_id = odata + 4; - ri->client_id_len = len; - break; - case OPTION_ORO: /* Option request option */ - if (len & 1) { - return -EINVAL; - } - /* Check which options the client wants to have */ - for (i = 0; i < len; i += 2) { - req_opt = odata[4 + i] << 8 | odata[4 + i + 1]; - switch (req_opt) { - case OPTION_DNS_SERVERS: - ri->want_dns = true; - break; - case OPTION_BOOTFILE_URL: - ri->want_boot_url = true; - break; - default: - DEBUG_MISC("dhcpv6: Unsupported option request %d", - req_opt); - } - } - break; - default: - DEBUG_MISC("dhcpv6 info req: Unsupported option %d, len=%d", option, - len); - } - - odata += len + 4; - olen -= len + 4; - } - - return 0; -} - - -/** - * Handle information request messages - */ -static void dhcpv6_info_request(Slirp *slirp, struct sockaddr_in6 *srcsas, - uint32_t xid, uint8_t *odata, int olen) -{ - struct requested_infos ri = { NULL }; - struct sockaddr_in6 sa6, da6; - struct mbuf *m; - uint8_t *resp; - - if (dhcpv6_parse_info_request(slirp, odata, olen, &ri) < 0) { - return; - } - - m = m_get(slirp); - if (!m) { - return; - } - memset(m->m_data, 0, m->m_size); - m->m_data += IF_MAXLINKHDR; - resp = (uint8_t *)m->m_data + sizeof(struct ip6) + sizeof(struct udphdr); - - /* Fill in response */ - *resp++ = MSGTYPE_REPLY; - *resp++ = (uint8_t)(xid >> 16); - *resp++ = (uint8_t)(xid >> 8); - *resp++ = (uint8_t)xid; - - if (ri.client_id) { - *resp++ = OPTION_CLIENTID >> 8; /* option-code high byte */ - *resp++ = OPTION_CLIENTID; /* option-code low byte */ - *resp++ = ri.client_id_len >> 8; /* option-len high byte */ - *resp++ = ri.client_id_len; /* option-len low byte */ - memcpy(resp, ri.client_id, ri.client_id_len); - resp += ri.client_id_len; - } - if (ri.want_dns) { - *resp++ = OPTION_DNS_SERVERS >> 8; /* option-code high byte */ - *resp++ = OPTION_DNS_SERVERS; /* option-code low byte */ - *resp++ = 0; /* option-len high byte */ - *resp++ = 16; /* option-len low byte */ - memcpy(resp, &slirp->vnameserver_addr6, 16); - resp += 16; - } - if (ri.want_boot_url) { - uint8_t *sa = slirp->vhost_addr6.s6_addr; - int slen, smaxlen; - - *resp++ = OPTION_BOOTFILE_URL >> 8; /* option-code high byte */ - *resp++ = OPTION_BOOTFILE_URL; /* option-code low byte */ - smaxlen = (uint8_t *)m->m_data + slirp->if_mtu - (resp + 2); - slen = slirp_fmt((char *)resp + 2, smaxlen, - "tftp://[%02x%02x:%02x%02x:%02x%02x:%02x%02x:" - "%02x%02x:%02x%02x:%02x%02x:%02x%02x]/%s", - sa[0], sa[1], sa[2], sa[3], sa[4], sa[5], sa[6], sa[7], - sa[8], sa[9], sa[10], sa[11], sa[12], sa[13], sa[14], - sa[15], slirp->bootp_filename); - *resp++ = slen >> 8; /* option-len high byte */ - *resp++ = slen; /* option-len low byte */ - resp += slen; - } - - sa6.sin6_addr = slirp->vhost_addr6; - sa6.sin6_port = DHCPV6_SERVER_PORT; - da6.sin6_addr = srcsas->sin6_addr; - da6.sin6_port = srcsas->sin6_port; - m->m_data += sizeof(struct ip6) + sizeof(struct udphdr); - m->m_len = resp - (uint8_t *)m->m_data; - udp6_output(NULL, m, &sa6, &da6); -} - -/** - * Handle DHCPv6 messages sent by the client - */ -void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m) -{ - uint8_t *data = (uint8_t *)m->m_data + sizeof(struct udphdr); - int data_len = m->m_len - sizeof(struct udphdr); - uint32_t xid; - - if (data_len < 4) { - return; - } - - xid = ntohl(*(uint32_t *)data) & 0xffffff; - - switch (data[0]) { - case MSGTYPE_INFO_REQUEST: - dhcpv6_info_request(m->slirp, srcsas, xid, &data[4], data_len - 4); - break; - default: - DEBUG_MISC("dhcpv6_input: Unsupported message type 0x%x", data[0]); - } -} diff --git a/src/network/slirp/dhcpv6.h b/src/network/slirp/dhcpv6.h deleted file mode 100644 index d12c49b36..000000000 --- a/src/network/slirp/dhcpv6.h +++ /dev/null @@ -1,68 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Definitions and prototypes for SLIRP stateless DHCPv6 - * - * Copyright 2016 Thomas Huth, Red Hat Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef SLIRP_DHCPV6_H -#define SLIRP_DHCPV6_H - -#define DHCPV6_SERVER_PORT 547 - -#define ALLDHCP_MULTICAST \ - { \ - .s6_addr = { \ - 0xff, \ - 0x02, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x01, \ - 0x00, \ - 0x02 \ - } \ - } - -#define in6_dhcp_multicast(a) in6_equal(a, &(struct in6_addr)ALLDHCP_MULTICAST) - -void dhcpv6_input(struct sockaddr_in6 *srcsas, struct mbuf *m); - -#endif diff --git a/src/network/slirp/dnssearch.c b/src/network/slirp/dnssearch.c deleted file mode 100644 index 55497e860..000000000 --- a/src/network/slirp/dnssearch.c +++ /dev/null @@ -1,306 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * Domain search option for DHCP (RFC 3397) - * - * Copyright (c) 2012 Klaus Stengel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "slirp.h" - -static const uint8_t RFC3397_OPT_DOMAIN_SEARCH = 119; -static const uint8_t MAX_OPT_LEN = 255; -static const uint8_t OPT_HEADER_LEN = 2; -static const uint8_t REFERENCE_LEN = 2; - -struct compact_domain; - -typedef struct compact_domain { - struct compact_domain *self; - struct compact_domain *refdom; - uint8_t *labels; - size_t len; - size_t common_octets; -} CompactDomain; - -static size_t domain_suffix_diffoff(const CompactDomain *a, - const CompactDomain *b) -{ - size_t la = a->len, lb = b->len; - uint8_t *da = a->labels + la, *db = b->labels + lb; - size_t i, lm = (la < lb) ? la : lb; - - for (i = 0; i < lm; i++) { - da--; - db--; - if (*da != *db) { - break; - } - } - return i; -} - -static int domain_suffix_ord(const void *cva, const void *cvb) -{ - const CompactDomain *a = cva, *b = cvb; - size_t la = a->len, lb = b->len; - size_t doff = domain_suffix_diffoff(a, b); - uint8_t ca = a->labels[la - doff]; - uint8_t cb = b->labels[lb - doff]; - - if (ca < cb) { - return -1; - } - if (ca > cb) { - return 1; - } - if (la < lb) { - return -1; - } - if (la > lb) { - return 1; - } - return 0; -} - -static size_t domain_common_label(CompactDomain *a, CompactDomain *b) -{ - size_t res, doff = domain_suffix_diffoff(a, b); - uint8_t *first_eq_pos = a->labels + (a->len - doff); - uint8_t *label = a->labels; - - while (*label && label < first_eq_pos) { - label += *label + 1; - } - res = a->len - (label - a->labels); - /* only report if it can help to reduce the packet size */ - return (res > REFERENCE_LEN) ? res : 0; -} - -static void domain_fixup_order(CompactDomain *cd, size_t n) -{ - size_t i; - - for (i = 0; i < n; i++) { - CompactDomain *cur = cd + i, *next = cd[i].self; - - while (!cur->common_octets) { - CompactDomain *tmp = next->self; /* backup target value */ - - next->self = cur; - cur->common_octets++; - - cur = next; - next = tmp; - } - } -} - -static void domain_mklabels(CompactDomain *cd, const char *input) -{ - uint8_t *len_marker = cd->labels; - uint8_t *output = len_marker; /* pre-incremented */ - const char *in = input; - char cur_chr; - size_t len = 0; - - if (cd->len == 0) { - goto fail; - } - cd->len++; - - do { - cur_chr = *in++; - if (cur_chr == '.' || cur_chr == '\0') { - len = output - len_marker; - if ((len == 0 && cur_chr == '.') || len >= 64) { - goto fail; - } - *len_marker = len; - - output++; - len_marker = output; - } else { - output++; - *output = cur_chr; - } - } while (cur_chr != '\0'); - - /* ensure proper zero-termination */ - if (len != 0) { - *len_marker = 0; - cd->len++; - } - return; - -fail: - g_warning("failed to parse domain name '%s'\n", input); - cd->len = 0; -} - -static void domain_mkxrefs(CompactDomain *doms, CompactDomain *last, - size_t depth) -{ - CompactDomain *i = doms, *target = doms; - - do { - if (i->labels < target->labels) { - target = i; - } - } while (i++ != last); - - for (i = doms; i != last; i++) { - CompactDomain *group_last; - size_t next_depth; - - if (i->common_octets == depth) { - continue; - } - - next_depth = -1; - for (group_last = i; group_last != last; group_last++) { - size_t co = group_last->common_octets; - if (co <= depth) { - break; - } - if (co < next_depth) { - next_depth = co; - } - } - domain_mkxrefs(i, group_last, next_depth); - - i = group_last; - if (i == last) { - break; - } - } - - if (depth == 0) { - return; - } - - i = doms; - do { - if (i != target && i->refdom == NULL) { - i->refdom = target; - i->common_octets = depth; - } - } while (i++ != last); -} - -static size_t domain_compactify(CompactDomain *domains, size_t n) -{ - uint8_t *start = domains->self->labels, *outptr = start; - size_t i; - - for (i = 0; i < n; i++) { - CompactDomain *cd = domains[i].self; - CompactDomain *rd = cd->refdom; - - if (rd != NULL) { - size_t moff = (rd->labels - start) + (rd->len - cd->common_octets); - if (moff < 0x3FFFu) { - cd->len -= cd->common_octets - 2; - cd->labels[cd->len - 1] = moff & 0xFFu; - cd->labels[cd->len - 2] = 0xC0u | (moff >> 8); - } - } - - if (cd->labels != outptr) { - memmove(outptr, cd->labels, cd->len); - cd->labels = outptr; - } - outptr += cd->len; - } - return outptr - start; -} - -int translate_dnssearch(Slirp *s, const char **names) -{ - size_t blocks, bsrc_start, bsrc_end, bdst_start; - size_t i, num_domains, memreq = 0; - uint8_t *result = NULL, *outptr; - CompactDomain *domains = NULL; - - num_domains = g_strv_length((GStrv)(void *)names); - if (num_domains == 0) { - return -2; - } - - domains = g_malloc(num_domains * sizeof(*domains)); - - for (i = 0; i < num_domains; i++) { - size_t nlen = strlen(names[i]); - memreq += nlen + 2; /* 1 zero octet + 1 label length octet */ - domains[i].self = domains + i; - domains[i].len = nlen; - domains[i].common_octets = 0; - domains[i].refdom = NULL; - } - - /* reserve extra 2 header bytes for each 255 bytes of output */ - memreq += DIV_ROUND_UP(memreq, MAX_OPT_LEN) * OPT_HEADER_LEN; - result = g_malloc(memreq * sizeof(*result)); - - outptr = result; - for (i = 0; i < num_domains; i++) { - domains[i].labels = outptr; - domain_mklabels(domains + i, names[i]); - outptr += domains[i].len; - } - - if (outptr == result) { - g_free(domains); - g_free(result); - return -1; - } - - qsort(domains, num_domains, sizeof(*domains), domain_suffix_ord); - domain_fixup_order(domains, num_domains); - - for (i = 1; i < num_domains; i++) { - size_t cl = domain_common_label(domains + i - 1, domains + i); - domains[i - 1].common_octets = cl; - } - - domain_mkxrefs(domains, domains + num_domains - 1, 0); - memreq = domain_compactify(domains, num_domains); - - blocks = DIV_ROUND_UP(memreq, MAX_OPT_LEN); - bsrc_end = memreq; - bsrc_start = (blocks - 1) * MAX_OPT_LEN; - bdst_start = bsrc_start + blocks * OPT_HEADER_LEN; - memreq += blocks * OPT_HEADER_LEN; - - while (blocks--) { - size_t len = bsrc_end - bsrc_start; - memmove(result + bdst_start, result + bsrc_start, len); - result[bdst_start - 2] = RFC3397_OPT_DOMAIN_SEARCH; - result[bdst_start - 1] = len; - bsrc_end = bsrc_start; - bsrc_start -= MAX_OPT_LEN; - bdst_start -= MAX_OPT_LEN + OPT_HEADER_LEN; - } - - g_free(domains); - s->vdnssearch = result; - s->vdnssearch_len = memreq; - return 0; -} diff --git a/src/network/slirp/if.c b/src/network/slirp/if.c deleted file mode 100644 index 741473dc4..000000000 --- a/src/network/slirp/if.c +++ /dev/null @@ -1,216 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -static void ifs_insque(struct mbuf *ifm, struct mbuf *ifmhead) -{ - ifm->ifs_next = ifmhead->ifs_next; - ifmhead->ifs_next = ifm; - ifm->ifs_prev = ifmhead; - ifm->ifs_next->ifs_prev = ifm; -} - -static void ifs_remque(struct mbuf *ifm) -{ - ifm->ifs_prev->ifs_next = ifm->ifs_next; - ifm->ifs_next->ifs_prev = ifm->ifs_prev; -} - -void if_init(Slirp *slirp) -{ - slirp->if_fastq.qh_link = slirp->if_fastq.qh_rlink = &slirp->if_fastq; - slirp->if_batchq.qh_link = slirp->if_batchq.qh_rlink = &slirp->if_batchq; -} - -/* - * if_output: Queue packet into an output queue. - * There are 2 output queue's, if_fastq and if_batchq. - * Each output queue is a doubly linked list of double linked lists - * of mbufs, each list belonging to one "session" (socket). This - * way, we can output packets fairly by sending one packet from each - * session, instead of all the packets from one session, then all packets - * from the next session, etc. Packets on the if_fastq get absolute - * priority, but if one session hogs the link, it gets "downgraded" - * to the batchq until it runs out of packets, then it'll return - * to the fastq (eg. if the user does an ls -alR in a telnet session, - * it'll temporarily get downgraded to the batchq) - */ -void if_output(struct socket *so, struct mbuf *ifm) -{ - Slirp *slirp = ifm->slirp; - M_DUP_DEBUG(slirp, ifm, 0, 0); - - struct mbuf *ifq; - int on_fastq = 1; - - DEBUG_CALL("if_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("ifm = %p", ifm); - - /* - * First remove the mbuf from m_usedlist, - * since we're gonna use m_next and m_prev ourselves - * XXX Shouldn't need this, gotta change dtom() etc. - */ - if (ifm->m_flags & M_USEDLIST) { - slirp_remque(ifm); - ifm->m_flags &= ~M_USEDLIST; - } - - /* - * See if there's already a batchq list for this session. - * This can include an interactive session, which should go on fastq, - * but gets too greedy... hence it'll be downgraded from fastq to batchq. - * We mustn't put this packet back on the fastq (or we'll send it out of - * order) - * XXX add cache here? - */ - if (so) { - for (ifq = (struct mbuf *)slirp->if_batchq.qh_rlink; - (struct slirp_quehead *)ifq != &slirp->if_batchq; - ifq = ifq->ifq_prev) { - if (so == ifq->ifq_so) { - /* A match! */ - ifm->ifq_so = so; - ifs_insque(ifm, ifq->ifs_prev); - goto diddit; - } - } - } - - /* No match, check which queue to put it on */ - if (so && (so->so_iptos & IPTOS_LOWDELAY)) { - ifq = (struct mbuf *)slirp->if_fastq.qh_rlink; - on_fastq = 1; - /* - * Check if this packet is a part of the last - * packet's session - */ - if (ifq->ifq_so == so) { - ifm->ifq_so = so; - ifs_insque(ifm, ifq->ifs_prev); - goto diddit; - } - } else { - ifq = (struct mbuf *)slirp->if_batchq.qh_rlink; - } - - /* Create a new doubly linked list for this session */ - ifm->ifq_so = so; - ifs_init(ifm); - slirp_insque(ifm, ifq); - -diddit: - if (so) { - /* Update *_queued */ - so->so_queued++; - so->so_nqueued++; - /* - * Check if the interactive session should be downgraded to - * the batchq. A session is downgraded if it has queued 6 - * packets without pausing, and at least 3 of those packets - * have been sent over the link - * (XXX These are arbitrary numbers, probably not optimal..) - */ - if (on_fastq && - ((so->so_nqueued >= 6) && (so->so_nqueued - so->so_queued) >= 3)) { - /* Remove from current queue... */ - slirp_remque(ifm->ifs_next); - - /* ...And insert in the new. That'll teach ya! */ - slirp_insque(ifm->ifs_next, &slirp->if_batchq); - } - } - - /* - * This prevents us from malloc()ing too many mbufs - */ - if_start(ifm->slirp); -} - -/* - * Send one packet from each session. - * If there are packets on the fastq, they are sent FIFO, before - * everything else. Then we choose the first packet from each - * batchq session (socket) and send it. - * For example, if there are 3 ftp sessions fighting for bandwidth, - * one packet will be sent from the first session, then one packet - * from the second session, then one packet from the third. - */ -void if_start(Slirp *slirp) -{ - uint64_t now = slirp->cb->clock_get_ns(slirp->opaque); - bool from_batchq = false; - struct mbuf *ifm, *ifm_next, *ifqt; - - DEBUG_VERBOSE_CALL("if_start"); - - if (slirp->if_start_busy) { - return; - } - slirp->if_start_busy = true; - - struct mbuf *batch_head = NULL; - if (slirp->if_batchq.qh_link != &slirp->if_batchq) { - batch_head = (struct mbuf *)slirp->if_batchq.qh_link; - } - - if (slirp->if_fastq.qh_link != &slirp->if_fastq) { - ifm_next = (struct mbuf *)slirp->if_fastq.qh_link; - } else if (batch_head) { - /* Nothing on fastq, pick up from batchq */ - ifm_next = batch_head; - from_batchq = true; - } else { - ifm_next = NULL; - } - - while (ifm_next) { - ifm = ifm_next; - - ifm_next = ifm->ifq_next; - if ((struct slirp_quehead *)ifm_next == &slirp->if_fastq) { - /* No more packets in fastq, switch to batchq */ - ifm_next = batch_head; - from_batchq = true; - } - if ((struct slirp_quehead *)ifm_next == &slirp->if_batchq) { - /* end of batchq */ - ifm_next = NULL; - } - - /* Try to send packet unless it already expired */ - if (ifm->expiration_date >= now && !if_encap(slirp, ifm)) { - /* Packet is delayed due to pending ARP or NDP resolution */ - continue; - } - - /* Remove it from the queue */ - ifqt = ifm->ifq_prev; - slirp_remque(ifm); - - /* If there are more packets for this session, re-queue them */ - if (ifm->ifs_next != ifm) { - struct mbuf *next = ifm->ifs_next; - - slirp_insque(next, ifqt); - ifs_remque(ifm); - if (!from_batchq) { - ifm_next = next; - } - } - - /* Update so_queued */ - if (ifm->ifq_so && --ifm->ifq_so->so_queued == 0) { - /* If there's no more queued, reset nqueued */ - ifm->ifq_so->so_nqueued = 0; - } - - m_free(ifm); - } - - slirp->if_start_busy = false; -} diff --git a/src/network/slirp/if.h b/src/network/slirp/if.h deleted file mode 100644 index 7cf9d2750..000000000 --- a/src/network/slirp/if.h +++ /dev/null @@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef IF_H -#define IF_H - -#define IF_COMPRESS 0x01 /* We want compression */ -#define IF_NOCOMPRESS 0x02 /* Do not do compression */ -#define IF_AUTOCOMP 0x04 /* Autodetect (default) */ -#define IF_NOCIDCOMP 0x08 /* CID compression */ - -#define IF_MTU_DEFAULT 1500 -#define IF_MTU_MIN 68 -#define IF_MTU_MAX 65521 -#define IF_MRU_DEFAULT 1500 -#define IF_MRU_MIN 68 -#define IF_MRU_MAX 65521 -#define IF_COMP IF_AUTOCOMP /* Flags for compression */ - -/* 2 for alignment, 14 for ethernet */ -#define IF_MAXLINKHDR (2 + ETH_HLEN) - -#endif diff --git a/src/network/slirp/ip.h b/src/network/slirp/ip.h deleted file mode 100644 index c4203f635..000000000 --- a/src/network/slirp/ip.h +++ /dev/null @@ -1,272 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip.h 8.1 (Berkeley) 6/10/93 - * ip.h,v 1.3 1994/08/21 05:27:30 paul Exp - */ - -#ifndef IP_H -#define IP_H - -#include - -#if G_BYTE_ORDER == G_BIG_ENDIAN -#undef NTOHL -#undef NTOHS -#undef HTONL -#undef HTONS -#define NTOHL(d) -#define NTOHS(d) -#define HTONL(d) -#define HTONS(d) -#else -#ifndef NTOHL -#define NTOHL(d) ((d) = ntohl((d))) -#endif -#ifndef NTOHS -#define NTOHS(d) ((d) = ntohs((uint16_t)(d))) -#endif -#ifndef HTONL -#define HTONL(d) ((d) = htonl((d))) -#endif -#ifndef HTONS -#define HTONS(d) ((d) = htons((uint16_t)(d))) -#endif -#endif - -typedef uint32_t n_long; /* long as received from the net */ - -/* - * Definitions for internet protocol version 4. - * Per RFC 791, September 1981. - */ -#define IPVERSION 4 - -/* - * Structure of an internet header, naked of options. - */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ip { -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t ip_v : 4, /* version */ - ip_hl : 4; /* header length */ -#else - uint8_t ip_hl : 4, /* header length */ - ip_v : 4; /* version */ -#endif - uint8_t ip_tos; /* type of service */ - uint16_t ip_len; /* total length */ - uint16_t ip_id; /* identification */ - uint16_t ip_off; /* fragment offset field */ -#define IP_DF 0x4000 /* don't fragment flag */ -#define IP_MF 0x2000 /* more fragments flag */ -#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ - uint8_t ip_ttl; /* time to live */ - uint8_t ip_p; /* protocol */ - uint16_t ip_sum; /* checksum */ - struct in_addr ip_src, ip_dst; /* source and dest address */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#define IP_MAXPACKET 65535 /* maximum packet size */ - -/* - * Definitions for IP type of service (ip_tos) - */ -#define IPTOS_LOWDELAY 0x10 -#define IPTOS_THROUGHPUT 0x08 -#define IPTOS_RELIABILITY 0x04 - -/* - * Definitions for options. - */ -#define IPOPT_COPIED(o) ((o)&0x80) -#define IPOPT_CLASS(o) ((o)&0x60) -#define IPOPT_NUMBER(o) ((o)&0x1f) - -#define IPOPT_CONTROL 0x00 -#define IPOPT_RESERVED1 0x20 -#define IPOPT_DEBMEAS 0x40 -#define IPOPT_RESERVED2 0x60 - -#define IPOPT_EOL 0 /* end of option list */ -#define IPOPT_NOP 1 /* no operation */ - -#define IPOPT_RR 7 /* record packet route */ -#define IPOPT_TS 68 /* timestamp */ -#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ -#define IPOPT_LSRR 131 /* loose source route */ -#define IPOPT_SATID 136 /* satnet id */ -#define IPOPT_SSRR 137 /* strict source route */ - -/* - * Offsets to fields in options other than EOL and NOP. - */ -#define IPOPT_OPTVAL 0 /* option ID */ -#define IPOPT_OLEN 1 /* option length */ -#define IPOPT_OFFSET 2 /* offset within option */ -#define IPOPT_MINOFF 4 /* min value of above */ - -/* - * Time stamp option structure. - */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ip_timestamp { - uint8_t ipt_code; /* IPOPT_TS */ - uint8_t ipt_len; /* size of structure (variable) */ - uint8_t ipt_ptr; /* index of current entry */ -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t ipt_oflw : 4, /* overflow counter */ - ipt_flg : 4; /* flags, see below */ -#else - uint8_t ipt_flg : 4, /* flags, see below */ - ipt_oflw : 4; /* overflow counter */ -#endif - union ipt_timestamp { - n_long ipt_time[1]; - struct ipt_ta { - struct in_addr ipt_addr; - n_long ipt_time; - } ipt_ta[1]; - } ipt_timestamp; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* flag bits for ipt_flg */ -#define IPOPT_TS_TSONLY 0 /* timestamps only */ -#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ -#define IPOPT_TS_PRESPEC 3 /* specified modules only */ - -/* bits for security (not byte swapped) */ -#define IPOPT_SECUR_UNCLASS 0x0000 -#define IPOPT_SECUR_CONFID 0xf135 -#define IPOPT_SECUR_EFTO 0x789a -#define IPOPT_SECUR_MMMM 0xbc4d -#define IPOPT_SECUR_RESTR 0xaf13 -#define IPOPT_SECUR_SECRET 0xd788 -#define IPOPT_SECUR_TOPSECRET 0x6bc5 - -/* - * Internet implementation parameters. - */ -#define MAXTTL 255 /* maximum time to live (seconds) */ -#define IPDEFTTL 64 /* default ttl, from RFC 1340 */ -#define IPFRAGTTL 60 /* time to live for frags, slowhz */ -#define IPTTLDEC 1 /* subtracted when forwarding */ - -#define IP_MSS 576 /* default maximum segment size */ - -#if GLIB_SIZEOF_VOID_P == 4 -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct mbuf_ptr { - struct mbuf *mptr; - uint32_t dummy; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif -#else -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct mbuf_ptr { - struct mbuf *mptr; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif -#endif -struct qlink { - void *next, *prev; -}; - -/* - * Overlay for ip header used by other protocols (tcp, udp). - */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ipovly { - struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */ - uint8_t ih_x1; /* (unused) */ - uint8_t ih_pr; /* protocol */ - uint16_t ih_len; /* protocol length */ - struct in_addr ih_src; /* source internet address */ - struct in_addr ih_dst; /* destination internet address */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* - * Ip reassembly queue structure. Each fragment - * being reassembled is attached to one of these structures. - * They are timed out after ipq_ttl drops to 0, and may also - * be reclaimed if memory becomes tight. - * size 28 bytes - */ -struct ipq { - struct qlink frag_link; /* to ip headers of fragments */ - struct qlink ip_link; /* to other reass headers */ - uint8_t ipq_ttl; /* time for reass q to live */ - uint8_t ipq_p; /* protocol of this fragment */ - uint16_t ipq_id; /* sequence id for reassembly */ - struct in_addr ipq_src, ipq_dst; -}; - -/* - * Ip header, when holding a fragment. - * - * Note: ipf_link must be at same offset as frag_link above - */ -struct ipasfrag { - struct qlink ipf_link; - struct ip ipf_ip; -}; - -G_STATIC_ASSERT(offsetof(struct ipq, frag_link) == - offsetof(struct ipasfrag, ipf_link)); - -#define ipf_off ipf_ip.ip_off -#define ipf_tos ipf_ip.ip_tos -#define ipf_len ipf_ip.ip_len -#define ipf_next ipf_link.next -#define ipf_prev ipf_link.prev - -#endif diff --git a/src/network/slirp/ip6.h b/src/network/slirp/ip6.h deleted file mode 100644 index 73a00b114..000000000 --- a/src/network/slirp/ip6.h +++ /dev/null @@ -1,214 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#ifndef SLIRP_IP6_H -#define SLIRP_IP6_H - -#include -#include - -#define ALLNODES_MULTICAST \ - { \ - .s6_addr = { \ - 0xff, \ - 0x02, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x01 \ - } \ - } - -#define SOLICITED_NODE_PREFIX \ - { \ - .s6_addr = { \ - 0xff, \ - 0x02, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x01, \ - 0xff, \ - 0x00, \ - 0x00, \ - 0x00 \ - } \ - } - -#define LINKLOCAL_ADDR \ - { \ - .s6_addr = { \ - 0xfe, \ - 0x80, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x02 \ - } \ - } - -#define ZERO_ADDR \ - { \ - .s6_addr = { \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00, \ - 0x00 \ - } \ - } - -static inline bool in6_equal(const struct in6_addr *a, const struct in6_addr *b) -{ - return memcmp(a, b, sizeof(*a)) == 0; -} - -static inline bool in6_equal_net(const struct in6_addr *a, - const struct in6_addr *b, int prefix_len) -{ - if (memcmp(a, b, prefix_len / 8) != 0) { - return 0; - } - - if (prefix_len % 8 == 0) { - return 1; - } - - return a->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)) == - b->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)); -} - -static inline bool in6_equal_mach(const struct in6_addr *a, - const struct in6_addr *b, int prefix_len) -{ - if (memcmp(&(a->s6_addr[DIV_ROUND_UP(prefix_len, 8)]), - &(b->s6_addr[DIV_ROUND_UP(prefix_len, 8)]), - 16 - DIV_ROUND_UP(prefix_len, 8)) != 0) { - return 0; - } - - if (prefix_len % 8 == 0) { - return 1; - } - - return (a->s6_addr[prefix_len / 8] & - ((1U << (8 - (prefix_len % 8))) - 1)) == - (b->s6_addr[prefix_len / 8] & ((1U << (8 - (prefix_len % 8))) - 1)); -} - - -#define in6_equal_router(a) \ - ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len) && \ - in6_equal_mach(a, &slirp->vhost_addr6, slirp->vprefix_len)) || \ - (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64) && \ - in6_equal_mach(a, &slirp->vhost_addr6, 64))) - -#define in6_equal_dns(a) \ - ((in6_equal_net(a, &slirp->vprefix_addr6, slirp->vprefix_len) && \ - in6_equal_mach(a, &slirp->vnameserver_addr6, slirp->vprefix_len)) || \ - (in6_equal_net(a, &(struct in6_addr)LINKLOCAL_ADDR, 64) && \ - in6_equal_mach(a, &slirp->vnameserver_addr6, 64))) - -#define in6_equal_host(a) (in6_equal_router(a) || in6_equal_dns(a)) - -#define in6_solicitednode_multicast(a) \ - (in6_equal_net(a, &(struct in6_addr)SOLICITED_NODE_PREFIX, 104)) - -#define in6_zero(a) (in6_equal(a, &(struct in6_addr)ZERO_ADDR)) - -/* Compute emulated host MAC address from its ipv6 address */ -static inline void in6_compute_ethaddr(struct in6_addr ip, - uint8_t eth[ETH_ALEN]) -{ - eth[0] = 0x52; - eth[1] = 0x56; - memcpy(ð[2], &ip.s6_addr[16 - (ETH_ALEN - 2)], ETH_ALEN - 2); -} - -/* - * Definitions for internet protocol version 6. - * Per RFC 2460, December 1998. - */ -#define IP6VERSION 6 -#define IP6_HOP_LIMIT 255 - -/* - * Structure of an internet header, naked of options. - */ -struct ip6 { -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint32_t ip_v : 4, /* version */ - ip_tc_hi : 4, /* traffic class */ - ip_tc_lo : 4, ip_fl_hi : 4, /* flow label */ - ip_fl_lo : 16; -#else - uint32_t ip_tc_hi : 4, ip_v : 4, ip_fl_hi : 4, ip_tc_lo : 4, ip_fl_lo : 16; -#endif - uint16_t ip_pl; /* payload length */ - uint8_t ip_nh; /* next header */ - uint8_t ip_hl; /* hop limit */ - struct in6_addr ip_src, ip_dst; /* source and dest address */ -}; - -/* - * IPv6 pseudo-header used by upper-layer protocols - */ -struct ip6_pseudohdr { - struct in6_addr ih_src; /* source internet address */ - struct in6_addr ih_dst; /* destination internet address */ - uint32_t ih_pl; /* upper-layer packet length */ - uint16_t ih_zero_hi; /* zero */ - uint8_t ih_zero_lo; /* zero */ - uint8_t ih_nh; /* next header */ -}; - -/* - * We don't want to mark these ip6 structs as packed as they are naturally - * correctly aligned; instead assert that there is no stray padding. - * If we marked the struct as packed then we would be unable to take - * the address of any of the fields in it. - */ -G_STATIC_ASSERT(sizeof(struct ip6) == 40); -G_STATIC_ASSERT(sizeof(struct ip6_pseudohdr) == 40); - -#endif diff --git a/src/network/slirp/ip6_icmp.c b/src/network/slirp/ip6_icmp.c deleted file mode 100644 index 0d7ee69ca..000000000 --- a/src/network/slirp/ip6_icmp.c +++ /dev/null @@ -1,442 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#include "slirp.h" -#include "ip6_icmp.h" - -#define NDP_Interval \ - g_rand_int_range(slirp->grand, NDP_MinRtrAdvInterval, NDP_MaxRtrAdvInterval) - -void icmp6_post_init(Slirp *slirp) -{ - if (!slirp->in6_enabled) { - return; - } - - slirp->ra_timer = - slirp_timer_new(slirp, SLIRP_TIMER_RA, NULL); - slirp->cb->timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS + - NDP_Interval, - slirp->opaque); -} - -void icmp6_cleanup(Slirp *slirp) -{ - if (!slirp->in6_enabled) { - return; - } - - slirp->cb->timer_free(slirp->ra_timer, slirp->opaque); -} - -static void icmp6_send_echoreply(struct mbuf *m, Slirp *slirp, struct ip6 *ip, - struct icmp6 *icmp) -{ - struct mbuf *t = m_get(slirp); - t->m_len = sizeof(struct ip6) + ntohs(ip->ip_pl); - memcpy(t->m_data, m->m_data, t->m_len); - - /* IPv6 Packet */ - struct ip6 *rip = mtod(t, struct ip6 *); - rip->ip_dst = ip->ip_src; - rip->ip_src = ip->ip_dst; - - /* ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = ICMP6_ECHO_REPLY; - ricmp->icmp6_cksum = 0; - - /* Checksum */ - t->m_data -= sizeof(struct ip6); - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 0); -} - -void icmp6_forward_error(struct mbuf *m, uint8_t type, uint8_t code, struct in6_addr *src) -{ - Slirp *slirp = m->slirp; - struct mbuf *t; - struct ip6 *ip = mtod(m, struct ip6 *); - char addrstr[INET6_ADDRSTRLEN]; - - DEBUG_CALL("icmp6_send_error"); - DEBUG_ARG("type = %d, code = %d", type, code); - - if (IN6_IS_ADDR_MULTICAST(&ip->ip_src) || in6_zero(&ip->ip_src)) { - /* TODO icmp error? */ - return; - } - - t = m_get(slirp); - - /* IPv6 packet */ - struct ip6 *rip = mtod(t, struct ip6 *); - rip->ip_src = *src; - rip->ip_dst = ip->ip_src; - inet_ntop(AF_INET6, &rip->ip_dst, addrstr, INET6_ADDRSTRLEN); - DEBUG_ARG("target = %s", addrstr); - - rip->ip_nh = IPPROTO_ICMPV6; - const int error_data_len = MIN( - m->m_len, slirp->if_mtu - (sizeof(struct ip6) + ICMP6_ERROR_MINLEN)); - rip->ip_pl = htons(ICMP6_ERROR_MINLEN + error_data_len); - t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl); - - /* ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = type; - ricmp->icmp6_code = code; - ricmp->icmp6_cksum = 0; - - switch (type) { - case ICMP6_UNREACH: - case ICMP6_TIMXCEED: - ricmp->icmp6_err.unused = 0; - break; - case ICMP6_TOOBIG: - ricmp->icmp6_err.mtu = htonl(slirp->if_mtu); - break; - case ICMP6_PARAMPROB: - /* TODO: Handle this case */ - break; - default: - g_assert_not_reached(); - } - t->m_data += ICMP6_ERROR_MINLEN; - memcpy(t->m_data, m->m_data, error_data_len); - - /* Checksum */ - t->m_data -= ICMP6_ERROR_MINLEN; - t->m_data -= sizeof(struct ip6); - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 0); -} - -void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code) -{ - struct in6_addr src = LINKLOCAL_ADDR; - icmp6_forward_error(m, type, code, &src); -} - -/* - * Send NDP Router Advertisement - */ -static void ndp_send_ra(Slirp *slirp) -{ - DEBUG_CALL("ndp_send_ra"); - - /* Build IPv6 packet */ - struct mbuf *t = m_get(slirp); - struct ip6 *rip = mtod(t, struct ip6 *); - size_t pl_size = 0; - struct in6_addr addr; - uint32_t scope_id; - - rip->ip_src = (struct in6_addr)LINKLOCAL_ADDR; - rip->ip_dst = (struct in6_addr)ALLNODES_MULTICAST; - rip->ip_nh = IPPROTO_ICMPV6; - - /* Build ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = ICMP6_NDP_RA; - ricmp->icmp6_code = 0; - ricmp->icmp6_cksum = 0; - - /* NDP */ - ricmp->icmp6_nra.chl = NDP_AdvCurHopLimit; - ricmp->icmp6_nra.M = NDP_AdvManagedFlag; - ricmp->icmp6_nra.O = NDP_AdvOtherConfigFlag; - ricmp->icmp6_nra.reserved = 0; - ricmp->icmp6_nra.lifetime = htons(NDP_AdvDefaultLifetime); - ricmp->icmp6_nra.reach_time = htonl(NDP_AdvReachableTime); - ricmp->icmp6_nra.retrans_time = htonl(NDP_AdvRetransTime); - t->m_data += ICMP6_NDP_RA_MINLEN; - pl_size += ICMP6_NDP_RA_MINLEN; - - /* Source link-layer address (NDP option) */ - struct ndpopt *opt = mtod(t, struct ndpopt *); - opt->ndpopt_type = NDPOPT_LINKLAYER_SOURCE; - opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8; - in6_compute_ethaddr(rip->ip_src, opt->ndpopt_linklayer); - t->m_data += NDPOPT_LINKLAYER_LEN; - pl_size += NDPOPT_LINKLAYER_LEN; - - /* Prefix information (NDP option) */ - struct ndpopt *opt2 = mtod(t, struct ndpopt *); - opt2->ndpopt_type = NDPOPT_PREFIX_INFO; - opt2->ndpopt_len = NDPOPT_PREFIXINFO_LEN / 8; - opt2->ndpopt_prefixinfo.prefix_length = slirp->vprefix_len; - opt2->ndpopt_prefixinfo.L = 1; - opt2->ndpopt_prefixinfo.A = 1; - opt2->ndpopt_prefixinfo.reserved1 = 0; - opt2->ndpopt_prefixinfo.valid_lt = htonl(NDP_AdvValidLifetime); - opt2->ndpopt_prefixinfo.pref_lt = htonl(NDP_AdvPrefLifetime); - opt2->ndpopt_prefixinfo.reserved2 = 0; - opt2->ndpopt_prefixinfo.prefix = slirp->vprefix_addr6; - t->m_data += NDPOPT_PREFIXINFO_LEN; - pl_size += NDPOPT_PREFIXINFO_LEN; - - /* Prefix information (NDP option) */ - if (get_dns6_addr(&addr, &scope_id) >= 0) { - /* Host system does have an IPv6 DNS server, announce our proxy. */ - struct ndpopt *opt3 = mtod(t, struct ndpopt *); - opt3->ndpopt_type = NDPOPT_RDNSS; - opt3->ndpopt_len = NDPOPT_RDNSS_LEN / 8; - opt3->ndpopt_rdnss.reserved = 0; - opt3->ndpopt_rdnss.lifetime = htonl(2 * NDP_MaxRtrAdvInterval); - opt3->ndpopt_rdnss.addr = slirp->vnameserver_addr6; - t->m_data += NDPOPT_RDNSS_LEN; - pl_size += NDPOPT_RDNSS_LEN; - } - - rip->ip_pl = htons(pl_size); - t->m_data -= sizeof(struct ip6) + pl_size; - t->m_len = sizeof(struct ip6) + pl_size; - - /* ICMPv6 Checksum */ - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 0); -} - -void ra_timer_handler(Slirp *slirp, void *unused) -{ - slirp->cb->timer_mod(slirp->ra_timer, - slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS + - NDP_Interval, - slirp->opaque); - ndp_send_ra(slirp); -} - -/* - * Send NDP Neighbor Solitication - */ -void ndp_send_ns(Slirp *slirp, struct in6_addr addr) -{ - char addrstr[INET6_ADDRSTRLEN]; - - inet_ntop(AF_INET6, &addr, addrstr, INET6_ADDRSTRLEN); - - DEBUG_CALL("ndp_send_ns"); - DEBUG_ARG("target = %s", addrstr); - - /* Build IPv6 packet */ - struct mbuf *t = m_get(slirp); - struct ip6 *rip = mtod(t, struct ip6 *); - rip->ip_src = slirp->vhost_addr6; - rip->ip_dst = (struct in6_addr)SOLICITED_NODE_PREFIX; - memcpy(&rip->ip_dst.s6_addr[13], &addr.s6_addr[13], 3); - rip->ip_nh = IPPROTO_ICMPV6; - rip->ip_pl = htons(ICMP6_NDP_NS_MINLEN + NDPOPT_LINKLAYER_LEN); - t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl); - - /* Build ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = ICMP6_NDP_NS; - ricmp->icmp6_code = 0; - ricmp->icmp6_cksum = 0; - - /* NDP */ - ricmp->icmp6_nns.reserved = 0; - ricmp->icmp6_nns.target = addr; - - /* Build NDP option */ - t->m_data += ICMP6_NDP_NS_MINLEN; - struct ndpopt *opt = mtod(t, struct ndpopt *); - opt->ndpopt_type = NDPOPT_LINKLAYER_SOURCE; - opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8; - in6_compute_ethaddr(slirp->vhost_addr6, opt->ndpopt_linklayer); - - /* ICMPv6 Checksum */ - t->m_data -= ICMP6_NDP_NA_MINLEN; - t->m_data -= sizeof(struct ip6); - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 1); -} - -/* - * Send NDP Neighbor Advertisement - */ -static void ndp_send_na(Slirp *slirp, struct ip6 *ip, struct icmp6 *icmp) -{ - /* Build IPv6 packet */ - struct mbuf *t = m_get(slirp); - struct ip6 *rip = mtod(t, struct ip6 *); - rip->ip_src = icmp->icmp6_nns.target; - if (in6_zero(&ip->ip_src)) { - rip->ip_dst = (struct in6_addr)ALLNODES_MULTICAST; - } else { - rip->ip_dst = ip->ip_src; - } - rip->ip_nh = IPPROTO_ICMPV6; - rip->ip_pl = htons(ICMP6_NDP_NA_MINLEN + NDPOPT_LINKLAYER_LEN); - t->m_len = sizeof(struct ip6) + ntohs(rip->ip_pl); - - /* Build ICMPv6 packet */ - t->m_data += sizeof(struct ip6); - struct icmp6 *ricmp = mtod(t, struct icmp6 *); - ricmp->icmp6_type = ICMP6_NDP_NA; - ricmp->icmp6_code = 0; - ricmp->icmp6_cksum = 0; - - /* NDP */ - ricmp->icmp6_nna.R = NDP_IsRouter; - ricmp->icmp6_nna.S = !IN6_IS_ADDR_MULTICAST(&rip->ip_dst); - ricmp->icmp6_nna.O = 1; - ricmp->icmp6_nna.reserved_hi = 0; - ricmp->icmp6_nna.reserved_lo = 0; - ricmp->icmp6_nna.target = icmp->icmp6_nns.target; - - /* Build NDP option */ - t->m_data += ICMP6_NDP_NA_MINLEN; - struct ndpopt *opt = mtod(t, struct ndpopt *); - opt->ndpopt_type = NDPOPT_LINKLAYER_TARGET; - opt->ndpopt_len = NDPOPT_LINKLAYER_LEN / 8; - in6_compute_ethaddr(ricmp->icmp6_nna.target, opt->ndpopt_linklayer); - - /* ICMPv6 Checksum */ - t->m_data -= ICMP6_NDP_NA_MINLEN; - t->m_data -= sizeof(struct ip6); - ricmp->icmp6_cksum = ip6_cksum(t); - - ip6_output(NULL, t, 0); -} - -/* - * Process a NDP message - */ -static void ndp_input(struct mbuf *m, Slirp *slirp, struct ip6 *ip, - struct icmp6 *icmp) -{ - g_assert(M_ROOMBEFORE(m) >= ETH_HLEN); - - m->m_len += ETH_HLEN; - m->m_data -= ETH_HLEN; - struct ethhdr *eth = mtod(m, struct ethhdr *); - m->m_len -= ETH_HLEN; - m->m_data += ETH_HLEN; - - switch (icmp->icmp6_type) { - case ICMP6_NDP_RS: - DEBUG_CALL(" type = Router Solicitation"); - if (ip->ip_hl == 255 && icmp->icmp6_code == 0 && - ntohs(ip->ip_pl) >= ICMP6_NDP_RS_MINLEN) { - /* Gratuitous NDP */ - ndp_table_add(slirp, ip->ip_src, eth->h_source); - - ndp_send_ra(slirp); - } - break; - - case ICMP6_NDP_RA: - DEBUG_CALL(" type = Router Advertisement"); - slirp->cb->guest_error("Warning: guest sent NDP RA, but shouldn't", - slirp->opaque); - break; - - case ICMP6_NDP_NS: - DEBUG_CALL(" type = Neighbor Solicitation"); - if (ip->ip_hl == 255 && icmp->icmp6_code == 0 && - !IN6_IS_ADDR_MULTICAST(&icmp->icmp6_nns.target) && - ntohs(ip->ip_pl) >= ICMP6_NDP_NS_MINLEN && - (!in6_zero(&ip->ip_src) || - in6_solicitednode_multicast(&ip->ip_dst))) { - if (in6_equal_host(&icmp->icmp6_nns.target)) { - /* Gratuitous NDP */ - ndp_table_add(slirp, ip->ip_src, eth->h_source); - ndp_send_na(slirp, ip, icmp); - } - } - break; - - case ICMP6_NDP_NA: - DEBUG_CALL(" type = Neighbor Advertisement"); - if (ip->ip_hl == 255 && icmp->icmp6_code == 0 && - ntohs(ip->ip_pl) >= ICMP6_NDP_NA_MINLEN && - !IN6_IS_ADDR_MULTICAST(&icmp->icmp6_nna.target) && - (!IN6_IS_ADDR_MULTICAST(&ip->ip_dst) || icmp->icmp6_nna.S == 0)) { - ndp_table_add(slirp, ip->ip_src, eth->h_source); - } - break; - - case ICMP6_NDP_REDIRECT: - DEBUG_CALL(" type = Redirect"); - slirp->cb->guest_error( - "Warning: guest sent NDP REDIRECT, but shouldn't", slirp->opaque); - break; - } -} - -/* - * Process a received ICMPv6 message. - */ -void icmp6_input(struct mbuf *m) -{ - Slirp *slirp = m->slirp; - /* NDP reads the ethernet header for gratuitous NDP */ - M_DUP_DEBUG(slirp, m, 1, ETH_HLEN); - - struct icmp6 *icmp; - struct ip6 *ip = mtod(m, struct ip6 *); - int hlen = sizeof(struct ip6); - - DEBUG_CALL("icmp6_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m_len = %d", m->m_len); - - if (ntohs(ip->ip_pl) < ICMP6_MINLEN) { - goto end; - } - - if (ip6_cksum(m)) { - goto end; - } - - m->m_len -= hlen; - m->m_data += hlen; - icmp = mtod(m, struct icmp6 *); - m->m_len += hlen; - m->m_data -= hlen; - - DEBUG_ARG("icmp6_type = %d", icmp->icmp6_type); - switch (icmp->icmp6_type) { - case ICMP6_ECHO_REQUEST: - if (in6_equal_host(&ip->ip_dst)) { - icmp6_send_echoreply(m, slirp, ip, icmp); - } else { - /* TODO */ - g_critical("external icmpv6 not supported yet"); - } - break; - - case ICMP6_NDP_RS: - case ICMP6_NDP_RA: - case ICMP6_NDP_NS: - case ICMP6_NDP_NA: - case ICMP6_NDP_REDIRECT: - ndp_input(m, slirp, ip, icmp); - break; - - case ICMP6_UNREACH: - case ICMP6_TOOBIG: - case ICMP6_TIMXCEED: - case ICMP6_PARAMPROB: - /* XXX? report error? close socket? */ - default: - break; - } - -end: - m_free(m); -} diff --git a/src/network/slirp/ip6_icmp.h b/src/network/slirp/ip6_icmp.h deleted file mode 100644 index 02761b726..000000000 --- a/src/network/slirp/ip6_icmp.h +++ /dev/null @@ -1,238 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#ifndef SLIRP_IP6_ICMP_H -#define SLIRP_IP6_ICMP_H - -/* - * Interface Control Message Protocol version 6 Definitions. - * Per RFC 4443, March 2006. - * - * Network Discover Protocol Definitions. - * Per RFC 4861, September 2007. - */ - -struct icmp6_echo { /* Echo Messages */ - uint16_t id; - uint16_t seq_num; -}; - -union icmp6_error_body { - uint32_t unused; - uint32_t pointer; - uint32_t mtu; -}; - -/* - * NDP Messages - */ -struct ndp_rs { /* Router Solicitation Message */ - uint32_t reserved; -}; - -struct ndp_ra { /* Router Advertisement Message */ - uint8_t chl; /* Cur Hop Limit */ -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t M : 1, O : 1, reserved : 6; -#else - uint8_t reserved : 6, O : 1, M : 1; -#endif - uint16_t lifetime; /* Router Lifetime */ - uint32_t reach_time; /* Reachable Time */ - uint32_t retrans_time; /* Retrans Timer */ -}; - -G_STATIC_ASSERT(sizeof(struct ndp_ra) == 12); - -struct ndp_ns { /* Neighbor Solicitation Message */ - uint32_t reserved; - struct in6_addr target; /* Target Address */ -}; - -G_STATIC_ASSERT(sizeof(struct ndp_ns) == 20); - -struct ndp_na { /* Neighbor Advertisement Message */ -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint32_t R : 1, /* Router Flag */ - S : 1, /* Solicited Flag */ - O : 1, /* Override Flag */ - reserved_hi : 5, reserved_lo : 24; -#else - uint32_t reserved_hi : 5, O : 1, S : 1, R : 1, reserved_lo : 24; -#endif - struct in6_addr target; /* Target Address */ -}; - -G_STATIC_ASSERT(sizeof(struct ndp_na) == 20); - -struct ndp_redirect { - uint32_t reserved; - struct in6_addr target; /* Target Address */ - struct in6_addr dest; /* Destination Address */ -}; - -G_STATIC_ASSERT(sizeof(struct ndp_redirect) == 36); - -/* - * Structure of an icmpv6 header. - */ -struct icmp6 { - uint8_t icmp6_type; /* type of message, see below */ - uint8_t icmp6_code; /* type sub code */ - uint16_t icmp6_cksum; /* ones complement cksum of struct */ - union { - union icmp6_error_body error_body; - struct icmp6_echo echo; - struct ndp_rs ndp_rs; - struct ndp_ra ndp_ra; - struct ndp_ns ndp_ns; - struct ndp_na ndp_na; - struct ndp_redirect ndp_redirect; - } icmp6_body; -#define icmp6_err icmp6_body.error_body -#define icmp6_echo icmp6_body.echo -#define icmp6_nrs icmp6_body.ndp_rs -#define icmp6_nra icmp6_body.ndp_ra -#define icmp6_nns icmp6_body.ndp_ns -#define icmp6_nna icmp6_body.ndp_na -#define icmp6_redirect icmp6_body.ndp_redirect -}; - -G_STATIC_ASSERT(sizeof(struct icmp6) == 40); - -#define ICMP6_MINLEN 4 -#define ICMP6_ERROR_MINLEN 8 -#define ICMP6_ECHO_MINLEN 8 -#define ICMP6_NDP_RS_MINLEN 8 -#define ICMP6_NDP_RA_MINLEN 16 -#define ICMP6_NDP_NS_MINLEN 24 -#define ICMP6_NDP_NA_MINLEN 24 -#define ICMP6_NDP_REDIRECT_MINLEN 40 - -/* - * NDP Options - */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ndpopt { - uint8_t ndpopt_type; /* Option type */ - uint8_t ndpopt_len; /* /!\ In units of 8 octets */ - union { - unsigned char linklayer_addr[6]; /* Source/Target Link-layer */ -#define ndpopt_linklayer ndpopt_body.linklayer_addr -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif - struct prefixinfo { /* Prefix Information */ - uint8_t prefix_length; -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t L : 1, A : 1, reserved1 : 6; -#else - uint8_t reserved1 : 6, A : 1, L : 1; -#endif - uint32_t valid_lt; /* Valid Lifetime */ - uint32_t pref_lt; /* Preferred Lifetime */ - uint32_t reserved2; - struct in6_addr prefix; - } SLIRP_PACKED prefixinfo; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif -#define ndpopt_prefixinfo ndpopt_body.prefixinfo -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif - struct rdnss { - uint16_t reserved; - uint32_t lifetime; - struct in6_addr addr; - } SLIRP_PACKED rdnss; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif -#define ndpopt_rdnss ndpopt_body.rdnss - } ndpopt_body; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* NDP options type */ -#define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */ -#define NDPOPT_LINKLAYER_TARGET 2 /* Target Link-Layer Address */ -#define NDPOPT_PREFIX_INFO 3 /* Prefix Information */ -#define NDPOPT_RDNSS 25 /* Recursive DNS Server Address */ - -/* NDP options size, in octets. */ -#define NDPOPT_LINKLAYER_LEN 8 -#define NDPOPT_PREFIXINFO_LEN 32 -#define NDPOPT_RDNSS_LEN 24 - -/* - * Definition of type and code field values. - * Per https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xml - * Last Updated 2012-11-12 - */ - -/* Errors */ -#define ICMP6_UNREACH 1 /* Destination Unreachable */ -#define ICMP6_UNREACH_NO_ROUTE 0 /* no route to dest */ -#define ICMP6_UNREACH_DEST_PROHIB 1 /* com with dest prohibited */ -#define ICMP6_UNREACH_SCOPE 2 /* beyond scope of src addr */ -#define ICMP6_UNREACH_ADDRESS 3 /* address unreachable */ -#define ICMP6_UNREACH_PORT 4 /* port unreachable */ -#define ICMP6_UNREACH_SRC_FAIL 5 /* src addr failed */ -#define ICMP6_UNREACH_REJECT_ROUTE 6 /* reject route to dest */ -#define ICMP6_UNREACH_SRC_HDR_ERROR 7 /* error in src routing header */ -#define ICMP6_TOOBIG 2 /* Packet Too Big */ -#define ICMP6_TIMXCEED 3 /* Time Exceeded */ -#define ICMP6_TIMXCEED_INTRANS 0 /* hop limit exceeded in transit */ -#define ICMP6_TIMXCEED_REASS 1 /* ttl=0 in reass */ -#define ICMP6_PARAMPROB 4 /* Parameter Problem */ -#define ICMP6_PARAMPROB_HDR_FIELD 0 /* err header field */ -#define ICMP6_PARAMPROB_NXTHDR_TYPE 1 /* unrecognized Next Header type */ -#define ICMP6_PARAMPROB_IPV6_OPT 2 /* unrecognized IPv6 option */ - -/* Informational Messages */ -#define ICMP6_ECHO_REQUEST 128 /* Echo Request */ -#define ICMP6_ECHO_REPLY 129 /* Echo Reply */ -#define ICMP6_NDP_RS 133 /* Router Solicitation (NDP) */ -#define ICMP6_NDP_RA 134 /* Router Advertisement (NDP) */ -#define ICMP6_NDP_NS 135 /* Neighbor Solicitation (NDP) */ -#define ICMP6_NDP_NA 136 /* Neighbor Advertisement (NDP) */ -#define ICMP6_NDP_REDIRECT 137 /* Redirect Message (NDP) */ - -/* - * Router Configuration Variables (rfc4861#section-6) - */ -#define NDP_IsRouter 1 -#define NDP_AdvSendAdvertisements 1 -#define NDP_MaxRtrAdvInterval 600000 -#define NDP_MinRtrAdvInterval \ - ((NDP_MaxRtrAdvInterval >= 9) ? NDP_MaxRtrAdvInterval / 3 : \ - NDP_MaxRtrAdvInterval) -#define NDP_AdvManagedFlag 0 -#define NDP_AdvOtherConfigFlag 0 -#define NDP_AdvLinkMTU 0 -#define NDP_AdvReachableTime 0 -#define NDP_AdvRetransTime 0 -#define NDP_AdvCurHopLimit 64 -#define NDP_AdvDefaultLifetime ((3 * NDP_MaxRtrAdvInterval) / 1000) -#define NDP_AdvValidLifetime 86400 -#define NDP_AdvOnLinkFlag 1 -#define NDP_AdvPrefLifetime 14400 -#define NDP_AdvAutonomousFlag 1 - -void icmp6_post_init(Slirp *slirp); -void icmp6_cleanup(Slirp *slirp); -void icmp6_input(struct mbuf *); -void icmp6_forward_error(struct mbuf *m, uint8_t type, uint8_t code, struct in6_addr *src); -void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code); -void ndp_send_ns(Slirp *slirp, struct in6_addr addr); -void ra_timer_handler(Slirp *slirp, void *unused); - -#endif diff --git a/src/network/slirp/ip6_input.c b/src/network/slirp/ip6_input.c deleted file mode 100644 index 4aca08285..000000000 --- a/src/network/slirp/ip6_input.c +++ /dev/null @@ -1,88 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#include "slirp.h" -#include "ip6_icmp.h" - -/* - * IP initialization: fill in IP protocol switch table. - * All protocols not implemented in kernel go to raw IP protocol handler. - */ -void ip6_post_init(Slirp *slirp) -{ - icmp6_post_init(slirp); -} - -void ip6_cleanup(Slirp *slirp) -{ - icmp6_cleanup(slirp); -} - -void ip6_input(struct mbuf *m) -{ - Slirp *slirp = m->slirp; - /* NDP reads the ethernet header for gratuitous NDP */ - M_DUP_DEBUG(slirp, m, 1, TCPIPHDR_DELTA + 2 + ETH_HLEN); - - struct ip6 *ip6; - - if (!slirp->in6_enabled) { - goto bad; - } - - DEBUG_CALL("ip6_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m_len = %d", m->m_len); - - if (m->m_len < sizeof(struct ip6)) { - goto bad; - } - - ip6 = mtod(m, struct ip6 *); - - if (ip6->ip_v != IP6VERSION) { - goto bad; - } - - if (ntohs(ip6->ip_pl) + sizeof(struct ip6) > slirp->if_mtu) { - icmp6_send_error(m, ICMP6_TOOBIG, 0); - goto bad; - } - - // Check if the message size is big enough to hold what's - // set in the payload length header. If not this is an invalid - // packet - if (m->m_len < ntohs(ip6->ip_pl) + sizeof(struct ip6)) { - goto bad; - } - - /* check ip_ttl for a correct ICMP reply */ - if (ip6->ip_hl == 0) { - icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS); - goto bad; - } - - /* - * Switch out to protocol's input routine. - */ - switch (ip6->ip_nh) { - case IPPROTO_TCP: - NTOHS(ip6->ip_pl); - tcp_input(m, sizeof(struct ip6), (struct socket *)NULL, AF_INET6); - break; - case IPPROTO_UDP: - udp6_input(m); - break; - case IPPROTO_ICMPV6: - icmp6_input(m); - break; - default: - m_free(m); - } - return; -bad: - m_free(m); -} diff --git a/src/network/slirp/ip6_output.c b/src/network/slirp/ip6_output.c deleted file mode 100644 index 834f1c0a3..000000000 --- a/src/network/slirp/ip6_output.c +++ /dev/null @@ -1,45 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#include "slirp.h" - -/* Number of packets queued before we start sending - * (to prevent allocing too many mbufs) */ -#define IF6_THRESH 10 - -/* - * IPv6 output. The packet in mbuf chain m contains a IP header - */ -int ip6_output(struct socket *so, struct mbuf *m, int fast) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - struct ip6 *ip = mtod(m, struct ip6 *); - - DEBUG_CALL("ip6_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - - /* Fill IPv6 header */ - ip->ip_v = IP6VERSION; - ip->ip_hl = IP6_HOP_LIMIT; - ip->ip_tc_hi = 0; - ip->ip_tc_lo = 0; - ip->ip_fl_hi = 0; - ip->ip_fl_lo = 0; - - if (fast) { - /* We cannot fast-send non-multicast, we'd need a NDP NS */ - assert(IN6_IS_ADDR_MULTICAST(&ip->ip_dst)); - if_encap(m->slirp, m); - m_free(m); - } else { - if_output(so, m); - } - - return 0; -} diff --git a/src/network/slirp/ip_icmp.c b/src/network/slirp/ip_icmp.c deleted file mode 100644 index 6ae523c69..000000000 --- a/src/network/slirp/ip_icmp.c +++ /dev/null @@ -1,541 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94 - * ip_icmp.c,v 1.7 1995/05/30 08:09:42 rgrimes Exp - */ - -#include "slirp.h" -#include "ip_icmp.h" - -#ifndef WITH_ICMP_ERROR_MSG -#define WITH_ICMP_ERROR_MSG 0 -#endif - -/* The message sent when emulating PING */ -/* Be nice and tell them it's just a pseudo-ping packet */ -static const char icmp_ping_msg[] = - "This is a pseudo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST " - "packets.\n"; - -/* list of actions for icmp_send_error() on RX of an icmp message */ -static const int icmp_flush[19] = { - /* ECHO REPLY (0) */ 0, - 1, - 1, - /* DEST UNREACH (3) */ 1, - /* SOURCE QUENCH (4)*/ 1, - /* REDIRECT (5) */ 1, - 1, - 1, - /* ECHO (8) */ 0, - /* ROUTERADVERT (9) */ 1, - /* ROUTERSOLICIT (10) */ 1, - /* TIME EXCEEDED (11) */ 1, - /* PARAMETER PROBLEM (12) */ 1, - /* TIMESTAMP (13) */ 0, - /* TIMESTAMP REPLY (14) */ 0, - /* INFO (15) */ 0, - /* INFO REPLY (16) */ 0, - /* ADDR MASK (17) */ 0, - /* ADDR MASK REPLY (18) */ 0 -}; - -void icmp_init(Slirp *slirp) -{ - slirp->icmp.so_next = slirp->icmp.so_prev = &slirp->icmp; - slirp->icmp_last_so = &slirp->icmp; -} - -void icmp_cleanup(Slirp *slirp) -{ - struct socket *so, *so_next; - - for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so_next) { - so_next = so->so_next; - icmp_detach(so); - } -} - -static int icmp_send(struct socket *so, struct mbuf *m, int hlen) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - struct ip *ip = mtod(m, struct ip *); - struct sockaddr_in addr; - - /* - * The behavior of reading SOCK_DGRAM+IPPROTO_ICMP sockets is inconsistent - * between host OSes. On Linux, only the ICMP header and payload is - * included. On macOS/Darwin, the socket acts like a raw socket and - * includes the IP header as well. On other BSDs, SOCK_DGRAM+IPPROTO_ICMP - * sockets aren't supported at all, so we treat them like raw sockets. It - * isn't possible to detect this difference at runtime, so we must use an - * #ifdef to determine if we need to remove the IP header. - */ -#ifdef CONFIG_BSD - so->so_type = IPPROTO_IP; -#else - so->so_type = IPPROTO_ICMP; -#endif - - so->s = slirp_socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP); - if (so->s == -1) { - if (errno == EAFNOSUPPORT - || errno == EPROTONOSUPPORT - || errno == EACCES) { - /* Kernel doesn't support or allow ping sockets. */ - so->so_type = IPPROTO_IP; - so->s = slirp_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); - } - } - if (so->s == -1) { - return -1; - } - so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); - - if (slirp_bind_outbound(so, AF_INET) != 0) { - // bind failed - close socket - closesocket(so->s); - so->s = -1; - return -1; - } - - so->so_m = m; - so->so_faddr = ip->ip_dst; - so->so_laddr = ip->ip_src; - so->so_iptos = ip->ip_tos; - so->so_state = SS_ISFCONNECTED; - so->so_expire = curtime + SO_EXPIRE; - - addr.sin_family = AF_INET; - addr.sin_addr = so->so_faddr; - - slirp_insque(so, &so->slirp->icmp); - - if (sendto(so->s, m->m_data + hlen, m->m_len - hlen, 0, - (struct sockaddr *)&addr, sizeof(addr)) == -1) { - DEBUG_MISC("icmp_input icmp sendto tx errno = %d-%s", errno, - strerror(errno)); - icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); - icmp_detach(so); - } - - return 0; -} - -void icmp_detach(struct socket *so) -{ - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sofree(so); -} - -/* - * Process a received ICMP message. - */ -void icmp_input(struct mbuf *m, int hlen) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - register struct icmp *icp; - register struct ip *ip = mtod(m, struct ip *); - int icmplen = ip->ip_len; - - DEBUG_CALL("icmp_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m_len = %d", m->m_len); - - /* - * Locate icmp structure in mbuf, and check - * that its not corrupted and of at least minimum length. - */ - if (icmplen < ICMP_MINLEN) { /* min 8 bytes payload */ - freeit: - m_free(m); - goto end_error; - } - - m->m_len -= hlen; - m->m_data += hlen; - icp = mtod(m, struct icmp *); - if (cksum(m, icmplen)) { - goto freeit; - } - m->m_len += hlen; - m->m_data -= hlen; - - DEBUG_ARG("icmp_type = %d", icp->icmp_type); - switch (icp->icmp_type) { - case ICMP_ECHO: - ip->ip_len += hlen; /* since ip_input subtracts this */ - if (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr || - ip->ip_dst.s_addr == slirp->vnameserver_addr.s_addr) { - icmp_reflect(m); - } else if (slirp->restricted) { - goto freeit; - } else { - struct socket *so; - struct sockaddr_storage addr; - int ttl; - - so = socreate(slirp, IPPROTO_ICMP); - if (icmp_send(so, m, hlen) == 0) { - /* We could send this as ICMP, good! */ - return; - } - - /* We could not send this as ICMP, try to send it on UDP echo - * service (7), wishfully hoping that it is open there. */ - - if (udp_attach(so, AF_INET) == -1) { - DEBUG_MISC("icmp_input udp_attach errno = %d-%s", errno, - strerror(errno)); - sofree(so); - m_free(m); - goto end_error; - } - so->so_m = m; - so->so_ffamily = AF_INET; - so->so_faddr = ip->ip_dst; - so->so_fport = htons(7); - so->so_lfamily = AF_INET; - so->so_laddr = ip->ip_src; - so->so_lport = htons(9); - so->so_iptos = ip->ip_tos; - so->so_state = SS_ISFCONNECTED; - - /* Send the packet */ - addr = so->fhost.ss; - if (sotranslate_out(so, &addr) < 0) { - icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, - strerror(errno)); - udp_detach(so); - return; - } - - /* - * Check for TTL - */ - ttl = ip->ip_ttl-1; - if (ttl <= 0) { - DEBUG_MISC("udp ttl exceeded"); - icmp_send_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, - NULL); - udp_detach(so); - break; - } - setsockopt(so->s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); - - if (sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0, - (struct sockaddr *)&addr, sockaddr_size(&addr)) == -1) { - DEBUG_MISC("icmp_input udp sendto tx errno = %d-%s", errno, - strerror(errno)); - icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, - strerror(errno)); - udp_detach(so); - } - } /* if ip->ip_dst.s_addr == alias_addr.s_addr */ - break; - case ICMP_UNREACH: - /* XXX? report error? close socket? */ - case ICMP_TIMXCEED: - case ICMP_PARAMPROB: - case ICMP_SOURCEQUENCH: - case ICMP_TSTAMP: - case ICMP_MASKREQ: - case ICMP_REDIRECT: - m_free(m); - break; - - default: - m_free(m); - } /* switch */ - -end_error: - /* m is m_free()'d xor put in a socket xor or given to ip_send */ - return; -} - - -/* - * Send an ICMP message in response to a situation - * - * RFC 1122: 3.2.2 MUST send at least the IP header and 8 bytes of header. - *MAY send more (we do). MUST NOT change this header information. MUST NOT reply - *to a multicast/broadcast IP address. MUST NOT reply to a multicast/broadcast - *MAC address. MUST reply to only the first fragment. - */ -/* - * Send ICMP_UNREACH back to the source regarding msrc. - * mbuf *msrc is used as a template, but is NOT m_free()'d. - * It is reported as the bad ip packet. The header should - * be fully correct and in host byte order. - * ICMP fragmentation is illegal. All machines must accept 576 bytes in one - * packet. The maximum payload is 576-20(ip hdr)-8(icmp hdr)=548 - */ - -#define ICMP_MAXDATALEN (IP_MSS - 28) -void icmp_forward_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, - const char *message, struct in_addr *src) -{ - unsigned hlen, shlen, s_ip_len; - register struct ip *ip; - register struct icmp *icp; - register struct mbuf *m; - - DEBUG_CALL("icmp_send_error"); - DEBUG_ARG("msrc = %p", msrc); - DEBUG_ARG("msrc_len = %d", msrc->m_len); - - if (type != ICMP_UNREACH && type != ICMP_TIMXCEED) - goto end_error; - - /* check msrc */ - if (!msrc) - goto end_error; - ip = mtod(msrc, struct ip *); - if (slirp_debug & DBG_MISC) { - char addr_src[INET_ADDRSTRLEN]; - char addr_dst[INET_ADDRSTRLEN]; - - inet_ntop(AF_INET, &ip->ip_src, addr_src, sizeof(addr_src)); - inet_ntop(AF_INET, &ip->ip_dst, addr_dst, sizeof(addr_dst)); - DEBUG_MISC(" %.16s to %.16s", addr_src, addr_dst); - } - if (ip->ip_off & IP_OFFMASK) - goto end_error; /* Only reply to fragment 0 */ - - /* Do not reply to source-only IPs */ - if ((ip->ip_src.s_addr & htonl(~(0xf << 28))) == 0) { - goto end_error; - } - - shlen = ip->ip_hl << 2; - s_ip_len = ip->ip_len; - if (ip->ip_p == IPPROTO_ICMP) { - icp = (struct icmp *)((char *)ip + shlen); - /* - * Assume any unknown ICMP type is an error. This isn't - * specified by the RFC, but think about it.. - */ - if (icp->icmp_type > 18 || icmp_flush[icp->icmp_type]) - goto end_error; - } - - /* make a copy */ - m = m_get(msrc->slirp); - if (!m) { - goto end_error; - } - - { - int new_m_size; - new_m_size = - sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN; - if (new_m_size > m->m_size) - m_inc(m, new_m_size); - } - memcpy(m->m_data, msrc->m_data, msrc->m_len); - m->m_len = msrc->m_len; /* copy msrc to m */ - - /* make the header of the reply packet */ - ip = mtod(m, struct ip *); - hlen = sizeof(struct ip); /* no options in reply */ - - /* fill in icmp */ - m->m_data += hlen; - m->m_len -= hlen; - - icp = mtod(m, struct icmp *); - - if (minsize) - s_ip_len = shlen + ICMP_MINLEN; /* return header+8b only */ - else if (s_ip_len > ICMP_MAXDATALEN) /* maximum size */ - s_ip_len = ICMP_MAXDATALEN; - - m->m_len = ICMP_MINLEN + s_ip_len; /* 8 bytes ICMP header */ - - /* min. size = 8+sizeof(struct ip)+8 */ - - icp->icmp_type = type; - icp->icmp_code = code; - icp->icmp_id = 0; - icp->icmp_seq = 0; - - memcpy(&icp->icmp_ip, msrc->m_data, s_ip_len); /* report the ip packet */ - HTONS(icp->icmp_ip.ip_len); - HTONS(icp->icmp_ip.ip_id); - HTONS(icp->icmp_ip.ip_off); - - if (message && WITH_ICMP_ERROR_MSG) { /* append message to ICMP packet */ - int message_len; - char *cpnt; - message_len = strlen(message); - if (message_len > ICMP_MAXDATALEN) - message_len = ICMP_MAXDATALEN; - cpnt = (char *)m->m_data + m->m_len; - memcpy(cpnt, message, message_len); - m->m_len += message_len; - } - - icp->icmp_cksum = 0; - icp->icmp_cksum = cksum(m, m->m_len); - - m->m_data -= hlen; - m->m_len += hlen; - - /* fill in ip */ - ip->ip_hl = hlen >> 2; - ip->ip_len = m->m_len; - - ip->ip_tos = ((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */ - - ip->ip_ttl = MAXTTL; - ip->ip_p = IPPROTO_ICMP; - ip->ip_dst = ip->ip_src; /* ip addresses */ - ip->ip_src = *src; - - ip_output((struct socket *)NULL, m); - -end_error: - return; -} -#undef ICMP_MAXDATALEN - -void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, - const char *message) -{ - icmp_forward_error(msrc, type, code, minsize, message, &msrc->slirp->vhost_addr); -} - -/* - * Reflect the ip packet back to the source - */ -void icmp_reflect(struct mbuf *m) -{ - register struct ip *ip = mtod(m, struct ip *); - int hlen = ip->ip_hl << 2; - int optlen = hlen - sizeof(struct ip); - register struct icmp *icp; - - /* - * Send an icmp packet back to the ip level, - * after supplying a checksum. - */ - m->m_data += hlen; - m->m_len -= hlen; - icp = mtod(m, struct icmp *); - - icp->icmp_type = ICMP_ECHOREPLY; - icp->icmp_cksum = 0; - icp->icmp_cksum = cksum(m, ip->ip_len - hlen); - - m->m_data -= hlen; - m->m_len += hlen; - - /* fill in ip */ - if (optlen > 0) { - /* - * Strip out original options by copying rest of first - * mbuf's data back, and adjust the IP length. - */ - memmove((char *)(ip + 1), (char *)ip + hlen, - (unsigned)(m->m_len - hlen)); - hlen -= optlen; - ip->ip_hl = hlen >> 2; - ip->ip_len -= optlen; - m->m_len -= optlen; - } - - ip->ip_ttl = MAXTTL; - { /* swap */ - struct in_addr icmp_dst; - icmp_dst = ip->ip_dst; - ip->ip_dst = ip->ip_src; - ip->ip_src = icmp_dst; - } - - ip_output((struct socket *)NULL, m); -} - -void icmp_receive(struct socket *so) -{ - struct mbuf *m = so->so_m; - struct ip *ip = mtod(m, struct ip *); - int hlen = ip->ip_hl << 2; - uint8_t error_code; - struct icmp *icp; - int id, len; - - m->m_data += hlen; - m->m_len -= hlen; - icp = mtod(m, struct icmp *); - - id = icp->icmp_id; - len = recv(so->s, icp, M_ROOM(m), 0); - - if (so->so_type == IPPROTO_IP) { - if (len >= sizeof(struct ip)) { - struct ip *inner_ip = mtod(m, struct ip *); - int inner_hlen = inner_ip->ip_hl << 2; - if (inner_hlen > len) { - len = -1; - errno = -EINVAL; - } else { - len -= inner_hlen; - memmove(icp, (unsigned char *)icp + inner_hlen, len); - } - } else { - len = -1; - errno = -EINVAL; - } - } - - icp->icmp_id = id; - - m->m_data -= hlen; - m->m_len += hlen; - - if (len == -1 || len == 0) { - if (errno == ENETUNREACH) { - error_code = ICMP_UNREACH_NET; - } else { - error_code = ICMP_UNREACH_HOST; - } - DEBUG_MISC(" udp icmp rx errno = %d-%s", errno, strerror(errno)); - icmp_send_error(so->so_m, ICMP_UNREACH, error_code, 0, strerror(errno)); - } else { - icmp_reflect(so->so_m); - so->so_m = NULL; /* Don't m_free() it again! */ - } - icmp_detach(so); -} diff --git a/src/network/slirp/ip_icmp.h b/src/network/slirp/ip_icmp.h deleted file mode 100644 index 569a08306..000000000 --- a/src/network/slirp/ip_icmp.h +++ /dev/null @@ -1,168 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93 - * ip_icmp.h,v 1.4 1995/05/30 08:09:43 rgrimes Exp - */ - -#ifndef NETINET_IP_ICMP_H -#define NETINET_IP_ICMP_H - -/* - * Interface Control Message Protocol Definitions. - * Per RFC 792, September 1981. - */ - -typedef uint32_t n_time; - -/* - * Structure of an icmp header. - */ -struct icmp { - uint8_t icmp_type; /* type of message, see below */ - uint8_t icmp_code; /* type sub code */ - uint16_t icmp_cksum; /* ones complement cksum of struct */ - union { - uint8_t ih_pptr; /* ICMP_PARAMPROB */ - struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ - struct ih_idseq { - uint16_t icd_id; - uint16_t icd_seq; - } ih_idseq; - int ih_void; - - /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */ - struct ih_pmtu { - uint16_t ipm_void; - uint16_t ipm_nextmtu; - } ih_pmtu; - } icmp_hun; -#define icmp_pptr icmp_hun.ih_pptr -#define icmp_gwaddr icmp_hun.ih_gwaddr -#define icmp_id icmp_hun.ih_idseq.icd_id -#define icmp_seq icmp_hun.ih_idseq.icd_seq -#define icmp_void icmp_hun.ih_void -#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void -#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu - union { - struct id_ts { - n_time its_otime; - n_time its_rtime; - n_time its_ttime; - } id_ts; - struct id_ip { - struct ip idi_ip; - /* options and then 64 bits of data */ - } id_ip; - uint32_t id_mask; - char id_data[1]; - } icmp_dun; -#define icmp_otime icmp_dun.id_ts.its_otime -#define icmp_rtime icmp_dun.id_ts.its_rtime -#define icmp_ttime icmp_dun.id_ts.its_ttime -#define icmp_ip icmp_dun.id_ip.idi_ip -#define icmp_mask icmp_dun.id_mask -#define icmp_data icmp_dun.id_data -}; - -/* - * Lower bounds on packet lengths for various types. - * For the error advice packets must first ensure that the - * packet is large enough to contain the returned ip header. - * Only then can we do the check to see if 64 bits of packet - * data have been returned, since we need to check the returned - * ip header length. - */ -#define ICMP_MINLEN 8 /* abs minimum */ -#define ICMP_TSLEN (8 + 3 * sizeof(n_time)) /* timestamp */ -#define ICMP_MASKLEN 12 /* address mask */ -#define ICMP_ADVLENMIN (8 + sizeof(struct ip) + 8) /* min */ -#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) -/* N.B.: must separately check that ip_hl >= 5 */ - -/* - * Definition of type and code field values. - */ -#define ICMP_ECHOREPLY 0 /* echo reply */ -#define ICMP_UNREACH 3 /* dest unreachable, codes: */ -#define ICMP_UNREACH_NET 0 /* bad net */ -#define ICMP_UNREACH_HOST 1 /* bad host */ -#define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ -#define ICMP_UNREACH_PORT 3 /* bad port */ -#define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ -#define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ -#define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ -#define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ -#define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ -#define ICMP_UNREACH_NET_PROHIB 9 /* prohibited access */ -#define ICMP_UNREACH_HOST_PROHIB 10 /* ditto */ -#define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ -#define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ -#define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ -#define ICMP_REDIRECT 5 /* shorter route, codes: */ -#define ICMP_REDIRECT_NET 0 /* for network */ -#define ICMP_REDIRECT_HOST 1 /* for host */ -#define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ -#define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ -#define ICMP_ECHO 8 /* echo service */ -#define ICMP_ROUTERADVERT 9 /* router advertisement */ -#define ICMP_ROUTERSOLICIT 10 /* router solicitation */ -#define ICMP_TIMXCEED 11 /* time exceeded, code: */ -#define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ -#define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ -#define ICMP_PARAMPROB 12 /* ip header bad */ -#define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ -#define ICMP_TSTAMP 13 /* timestamp request */ -#define ICMP_TSTAMPREPLY 14 /* timestamp reply */ -#define ICMP_IREQ 15 /* information request */ -#define ICMP_IREQREPLY 16 /* information reply */ -#define ICMP_MASKREQ 17 /* address mask request */ -#define ICMP_MASKREPLY 18 /* address mask reply */ - -#define ICMP_MAXTYPE 18 - -#define ICMP_INFOTYPE(type) \ - ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ - (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ - (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ - (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ - (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) - -void icmp_init(Slirp *slirp); -void icmp_cleanup(Slirp *slirp); -void icmp_input(struct mbuf *, int); -void icmp_forward_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, - const char *message, struct in_addr *src); -void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize, - const char *message); -void icmp_reflect(struct mbuf *); -void icmp_receive(struct socket *so); -void icmp_detach(struct socket *so); - -#endif diff --git a/src/network/slirp/ip_input.c b/src/network/slirp/ip_input.c deleted file mode 100644 index b0a64da19..000000000 --- a/src/network/slirp/ip_input.c +++ /dev/null @@ -1,464 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 - * ip_input.c,v 1.11 1994/11/16 10:17:08 jkh Exp - */ - -/* - * Changes and additions relating to SLiRP are - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" -#include "ip_icmp.h" -#include - -static struct ip *ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp); -static void ip_freef(Slirp *slirp, struct ipq *fp); -static void ip_enq(register struct ipasfrag *p, register struct ipasfrag *prev); -static void ip_deq(register struct ipasfrag *p); - -/* - * IP initialization: fill in IP protocol switch table. - * All protocols not implemented in kernel go to raw IP protocol handler. - */ -void ip_init(Slirp *slirp) -{ - slirp->ipq.ip_link.next = slirp->ipq.ip_link.prev = &slirp->ipq.ip_link; - udp_init(slirp); - tcp_init(slirp); - icmp_init(slirp); -} - -void ip_cleanup(Slirp *slirp) -{ - udp_cleanup(slirp); - tcp_cleanup(slirp); - icmp_cleanup(slirp); -} - -/* - * Ip input routine. Checksum and byte swap header. If fragmented - * try to reassemble. Process options. Pass to next level. - */ -void ip_input(struct mbuf *m) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, TCPIPHDR_DELTA); - - register struct ip *ip; - int hlen; - - if (!slirp->in_enabled) { - goto bad; - } - - DEBUG_CALL("ip_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m_len = %d", m->m_len); - - if (m->m_len < sizeof(struct ip)) { - goto bad; - } - - ip = mtod(m, struct ip *); - - if (ip->ip_v != IPVERSION) { - goto bad; - } - - hlen = ip->ip_hl << 2; - if (hlen < sizeof(struct ip) || hlen > m->m_len) { /* min header length */ - goto bad; /* or packet too short */ - } - - /* keep ip header intact for ICMP reply - * ip->ip_sum = cksum(m, hlen); - * if (ip->ip_sum) { - */ - if (cksum(m, hlen)) { - goto bad; - } - - /* - * Convert fields to host representation. - */ - NTOHS(ip->ip_len); - if (ip->ip_len < hlen) { - goto bad; - } - NTOHS(ip->ip_id); - NTOHS(ip->ip_off); - - /* - * Check that the amount of data in the buffers - * is as at least much as the IP header would have us expect. - * Trim mbufs if longer than we expect. - * Drop packet if shorter than we expect. - */ - if (m->m_len < ip->ip_len) { - goto bad; - } - - /* Should drop packet if mbuf too long? hmmm... */ - if (m->m_len > ip->ip_len) - m_adj(m, ip->ip_len - m->m_len); - - /* check ip_ttl for a correct ICMP reply */ - if (ip->ip_ttl == 0) { - icmp_send_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, "ttl"); - goto bad; - } - - /* - * If offset or IP_MF are set, must reassemble. - * Otherwise, nothing need be done. - * (We could look in the reassembly queue to see - * if the packet was previously fragmented, - * but it's not worth the time; just let them time out.) - * - * XXX This should fail, don't fragment yet - */ - if (ip->ip_off & ~IP_DF) { - register struct ipq *fp; - struct qlink *l; - /* - * Look for queue of fragments - * of this datagram. - */ - for (l = slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link; - l = l->next) { - fp = container_of(l, struct ipq, ip_link); - if (ip->ip_id == fp->ipq_id && - ip->ip_src.s_addr == fp->ipq_src.s_addr && - ip->ip_dst.s_addr == fp->ipq_dst.s_addr && - ip->ip_p == fp->ipq_p) - goto found; - } - fp = NULL; - found: - - /* - * Adjust ip_len to not reflect header, - * set ip_mff if more fragments are expected, - * convert offset of this to bytes. - */ - ip->ip_len -= hlen; - if (ip->ip_off & IP_MF) - ip->ip_tos |= 1; - else - ip->ip_tos &= ~1; - - ip->ip_off <<= 3; - - /* - * If datagram marked as having more fragments - * or if this is not the first fragment, - * attempt reassembly; if it succeeds, proceed. - */ - if (ip->ip_tos & 1 || ip->ip_off) { - ip = ip_reass(slirp, ip, fp); - if (ip == NULL) - return; - m = dtom(slirp, ip); - } else if (fp) - ip_freef(slirp, fp); - - } else - ip->ip_len -= hlen; - - /* - * Switch out to protocol's input routine. - */ - switch (ip->ip_p) { - case IPPROTO_TCP: - tcp_input(m, hlen, (struct socket *)NULL, AF_INET); - break; - case IPPROTO_UDP: - udp_input(m, hlen); - break; - case IPPROTO_ICMP: - icmp_input(m, hlen); - break; - default: - m_free(m); - } - return; -bad: - m_free(m); -} - -#define iptofrag(P) ((struct ipasfrag *)(((char *)(P)) - sizeof(struct qlink))) -#define fragtoip(P) ((struct ip *)(((char *)(P)) + sizeof(struct qlink))) -/* - * Take incoming datagram fragment and try to - * reassemble it into whole datagram. If a chain for - * reassembly of this datagram already exists, then it - * is given as fp; otherwise have to make a chain. - */ -static struct ip *ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp) -{ - register struct mbuf *m = dtom(slirp, ip); - register struct ipasfrag *q; - int hlen = ip->ip_hl << 2; - int i, next; - - DEBUG_CALL("ip_reass"); - DEBUG_ARG("ip = %p", ip); - DEBUG_ARG("fp = %p", fp); - DEBUG_ARG("m = %p", m); - - /* - * Presence of header sizes in mbufs - * would confuse code below. - * Fragment m_data is concatenated. - */ - m->m_data += hlen; - m->m_len -= hlen; - - /* - * If first fragment to arrive, create a reassembly queue. - */ - if (fp == NULL) { - struct mbuf *t = m_get(slirp); - - if (t == NULL) { - goto dropfrag; - } - fp = mtod(t, struct ipq *); - slirp_insque(&fp->ip_link, &slirp->ipq.ip_link); - fp->ipq_ttl = IPFRAGTTL; - fp->ipq_p = ip->ip_p; - fp->ipq_id = ip->ip_id; - fp->frag_link.next = fp->frag_link.prev = &fp->frag_link; - fp->ipq_src = ip->ip_src; - fp->ipq_dst = ip->ip_dst; - q = (struct ipasfrag *)fp; - goto insert; - } - - /* - * Find a segment which begins after this one does. - */ - for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link; - q = q->ipf_next) - if (q->ipf_off > ip->ip_off) - break; - - /* - * If there is a preceding segment, it may provide some of - * our data already. If so, drop the data from the incoming - * segment. If it provides all of our data, drop us. - */ - if (q->ipf_prev != &fp->frag_link) { - struct ipasfrag *pq = q->ipf_prev; - i = pq->ipf_off + pq->ipf_len - ip->ip_off; - if (i > 0) { - if (i >= ip->ip_len) - goto dropfrag; - m_adj(dtom(slirp, ip), i); - ip->ip_off += i; - ip->ip_len -= i; - } - } - - /* - * While we overlap succeeding segments trim them or, - * if they are completely covered, dequeue them. - */ - while (q != (struct ipasfrag *)&fp->frag_link && - ip->ip_off + ip->ip_len > q->ipf_off) { - struct ipasfrag *prev; - i = (ip->ip_off + ip->ip_len) - q->ipf_off; - if (i < q->ipf_len) { - q->ipf_len -= i; - q->ipf_off += i; - m_adj(dtom(slirp, q), i); - break; - } - prev = q; - q = q->ipf_next; - ip_deq(prev); - m_free(dtom(slirp, prev)); - } - -insert: - /* - * Stick new segment in its place; - * check for complete reassembly. - */ - ip_enq(iptofrag(ip), q->ipf_prev); - next = 0; - for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link; - q = q->ipf_next) { - if (q->ipf_off != next) - return NULL; - next += q->ipf_len; - } - if (((struct ipasfrag *)(q->ipf_prev))->ipf_tos & 1) - return NULL; - - /* - * Reassembly is complete; concatenate fragments. - */ - q = fp->frag_link.next; - m = dtom(slirp, q); - int delta = (char *)q - (m->m_flags & M_EXT ? m->m_ext : m->m_dat); - - q = (struct ipasfrag *)q->ipf_next; - while (q != (struct ipasfrag *)&fp->frag_link) { - struct mbuf *t = dtom(slirp, q); - q = (struct ipasfrag *)q->ipf_next; - m_cat(m, t); - } - - /* - * Create header for new ip packet by - * modifying header of first packet; - * dequeue and discard fragment reassembly header. - * Make header visible. - */ - q = fp->frag_link.next; - - /* - * If the fragments concatenated to an mbuf that's bigger than the total - * size of the fragment and the mbuf was not already using an m_ext buffer, - * then an m_ext buffer was allocated. But fp->ipq_next points to the old - * buffer (in the mbuf), so we must point ip into the new buffer. - */ - if (m->m_flags & M_EXT) { - q = (struct ipasfrag *)(m->m_ext + delta); - } - - ip = fragtoip(q); - ip->ip_len = next; - ip->ip_tos &= ~1; - ip->ip_src = fp->ipq_src; - ip->ip_dst = fp->ipq_dst; - slirp_remque(&fp->ip_link); - m_free(dtom(slirp, fp)); - m->m_len += (ip->ip_hl << 2); - m->m_data -= (ip->ip_hl << 2); - - return ip; - -dropfrag: - m_free(m); - return NULL; -} - -/* - * Free a fragment reassembly header and all - * associated datagrams. - */ -static void ip_freef(Slirp *slirp, struct ipq *fp) -{ - register struct ipasfrag *q, *p; - - for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link; - q = p) { - p = q->ipf_next; - ip_deq(q); - m_free(dtom(slirp, q)); - } - slirp_remque(&fp->ip_link); - m_free(dtom(slirp, fp)); -} - -/* - * Put an ip fragment on a reassembly chain. - * Like slirp_insque, but pointers in middle of structure. - */ -static void ip_enq(register struct ipasfrag *p, register struct ipasfrag *prev) -{ - DEBUG_CALL("ip_enq"); - DEBUG_ARG("prev = %p", prev); - p->ipf_prev = prev; - p->ipf_next = prev->ipf_next; - ((struct ipasfrag *)(prev->ipf_next))->ipf_prev = p; - prev->ipf_next = p; -} - -/* - * To ip_enq as slirp_remque is to slirp_insque. - */ -static void ip_deq(register struct ipasfrag *p) -{ - ((struct ipasfrag *)(p->ipf_prev))->ipf_next = p->ipf_next; - ((struct ipasfrag *)(p->ipf_next))->ipf_prev = p->ipf_prev; -} - -/* - * IP timer processing; - * if a timer expires on a reassembly - * queue, discard it. - */ -void ip_slowtimo(Slirp *slirp) -{ - struct qlink *l; - - DEBUG_CALL("ip_slowtimo"); - - l = slirp->ipq.ip_link.next; - - if (l == NULL) - return; - - while (l != &slirp->ipq.ip_link) { - struct ipq *fp = container_of(l, struct ipq, ip_link); - l = l->next; - if (--fp->ipq_ttl == 0) { - ip_freef(slirp, fp); - } - } -} - -/* - * Strip out IP options, at higher - * level protocol in the kernel. - * Second argument is buffer to which options - * will be moved, and return value is their length. - * (XXX) should be deleted; last arg currently ignored. - */ -void ip_stripoptions(register struct mbuf *m, struct mbuf *mopt) -{ - register int i; - struct ip *ip = mtod(m, struct ip *); - register char *opts; - int olen; - - olen = (ip->ip_hl << 2) - sizeof(struct ip); - opts = (char *)(ip + 1); - i = m->m_len - (sizeof(struct ip) + olen); - memmove(opts, opts + olen, (unsigned)i); - m->m_len -= olen; - - ip->ip_hl = sizeof(struct ip) >> 2; -} diff --git a/src/network/slirp/ip_output.c b/src/network/slirp/ip_output.c deleted file mode 100644 index 4f6260591..000000000 --- a/src/network/slirp/ip_output.c +++ /dev/null @@ -1,171 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 - * ip_output.c,v 1.9 1994/11/16 10:17:10 jkh Exp - */ - -/* - * Changes and additions relating to SLiRP are - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -/* Number of packets queued before we start sending - * (to prevent allocing too many mbufs) */ -#define IF_THRESH 10 - -/* - * IP output. The packet in mbuf chain m contains a skeletal IP - * header (with len, off, ttl, proto, tos, src, dst). - * The mbuf chain containing the packet will be freed. - * The mbuf opt, if present, will not be freed. - */ -int ip_output(struct socket *so, struct mbuf *m0) -{ - Slirp *slirp = m0->slirp; - M_DUP_DEBUG(slirp, m0, 0, 0); - - register struct ip *ip; - register struct mbuf *m = m0; - register int hlen = sizeof(struct ip); - int len, off, error = 0; - - DEBUG_CALL("ip_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m0 = %p", m0); - - ip = mtod(m, struct ip *); - /* - * Fill in IP header. - */ - ip->ip_v = IPVERSION; - ip->ip_off &= IP_DF; - ip->ip_id = htons(slirp->ip_id++); - ip->ip_hl = hlen >> 2; - - /* - * If small enough for interface, can just send directly. - */ - if ((uint16_t)ip->ip_len <= slirp->if_mtu) { - ip->ip_len = htons((uint16_t)ip->ip_len); - ip->ip_off = htons((uint16_t)ip->ip_off); - ip->ip_sum = 0; - ip->ip_sum = cksum(m, hlen); - - if_output(so, m); - goto done; - } - - /* - * Too large for interface; fragment if possible. - * Must be able to put at least 8 bytes per fragment. - */ - if (ip->ip_off & IP_DF) { - error = -1; - goto bad; - } - - len = (slirp->if_mtu - hlen) & ~7; /* ip databytes per packet */ - if (len < 8) { - error = -1; - goto bad; - } - - { - int mhlen, firstlen = len; - struct mbuf **mnext = &m->m_nextpkt; - - /* - * Loop through length of segment after first fragment, - * make new header and copy data of each part and link onto chain. - */ - m0 = m; - mhlen = sizeof(struct ip); - for (off = hlen + len; off < (uint16_t)ip->ip_len; off += len) { - register struct ip *mhip; - m = m_get(slirp); - if (m == NULL) { - error = -1; - goto sendorfree; - } - m->m_data += IF_MAXLINKHDR; - mhip = mtod(m, struct ip *); - *mhip = *ip; - - m->m_len = mhlen; - mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF); - if (ip->ip_off & IP_MF) - mhip->ip_off |= IP_MF; - if (off + len >= (uint16_t)ip->ip_len) - len = (uint16_t)ip->ip_len - off; - else - mhip->ip_off |= IP_MF; - mhip->ip_len = htons((uint16_t)(len + mhlen)); - - if (m_copy(m, m0, off, len) < 0) { - error = -1; - goto sendorfree; - } - - mhip->ip_off = htons((uint16_t)mhip->ip_off); - mhip->ip_sum = 0; - mhip->ip_sum = cksum(m, mhlen); - *mnext = m; - mnext = &m->m_nextpkt; - } - /* - * Update first fragment by trimming what's been copied out - * and updating header, then send each fragment (in order). - */ - m = m0; - m_adj(m, hlen + firstlen - (uint16_t)ip->ip_len); - ip->ip_len = htons((uint16_t)m->m_len); - ip->ip_off = htons((uint16_t)(ip->ip_off | IP_MF)); - ip->ip_sum = 0; - ip->ip_sum = cksum(m, hlen); - sendorfree: - for (m = m0; m; m = m0) { - m0 = m->m_nextpkt; - m->m_nextpkt = NULL; - if (error == 0) - if_output(so, m); - else - m_free(m); - } - } - -done: - return (error); - -bad: - m_free(m0); - goto done; -} diff --git a/src/network/slirp/libslirp-version.h b/src/network/slirp/libslirp-version.h deleted file mode 100644 index b68906957..000000000 --- a/src/network/slirp/libslirp-version.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#ifndef LIBSLIRP_VERSION_H_ -#define LIBSLIRP_VERSION_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#define SLIRP_MAJOR_VERSION 4 -#define SLIRP_MINOR_VERSION 7 -#define SLIRP_MICRO_VERSION 0 -#define SLIRP_VERSION_STRING "4.7.0-86Box" - -#define SLIRP_CHECK_VERSION(major,minor,micro) \ - (SLIRP_MAJOR_VERSION > (major) || \ - (SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION > (minor)) || \ - (SLIRP_MAJOR_VERSION == (major) && SLIRP_MINOR_VERSION == (minor) && \ - SLIRP_MICRO_VERSION >= (micro))) - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* LIBSLIRP_VERSION_H_ */ diff --git a/src/network/slirp/libslirp.h b/src/network/slirp/libslirp.h deleted file mode 100644 index 7a6c9a4da..000000000 --- a/src/network/slirp/libslirp.h +++ /dev/null @@ -1,273 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#ifndef LIBSLIRP_H -#define LIBSLIRP_H - -#include -#include -#include - -#ifdef _WIN32 -#include -#include -#include -#else -#include -#include -#endif - -#include "libslirp-version.h" - -/* Windows does not define ssize_t, so we need to define it here. */ -#ifndef _SSIZE_T_DEFINED -# define _SSIZE_T_DEFINED -# undef ssize_t -# ifdef _WIN64 -# define ssize_t int64_t -# else -# define ssize_t int32_t -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Opaque structure containing the slirp state */ -typedef struct Slirp Slirp; - -/* Flags passed to SlirpAddPollCb and to be returned by SlirpGetREventsCb. */ -enum { - SLIRP_POLL_IN = 1 << 0, - SLIRP_POLL_OUT = 1 << 1, - SLIRP_POLL_PRI = 1 << 2, - SLIRP_POLL_ERR = 1 << 3, - SLIRP_POLL_HUP = 1 << 4, -}; - -typedef ssize_t (*SlirpReadCb)(void *buf, size_t len, void *opaque); -typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); -typedef void (*SlirpTimerCb)(void *opaque); -typedef int (*SlirpAddPollCb)(int fd, int events, void *opaque); -typedef int (*SlirpGetREventsCb)(int idx, void *opaque); - -typedef enum SlirpTimerId { - SLIRP_TIMER_RA, - SLIRP_TIMER_NUM, -} SlirpTimerId; - -/* - * Callbacks from slirp, to be set by the application. - * - * The opaque parameter is set to the opaque pointer given in the slirp_new / - * slirp_init call. - */ -typedef struct SlirpCb { - /* - * Send an ethernet frame to the guest network. The opaque parameter is the - * one given to slirp_init(). If the guest is not ready to receive a frame, - * the function can just drop the data. TCP will then handle retransmissions - * at a lower pace. - * <0 reports an IO error. - */ - SlirpWriteCb send_packet; - /* Print a message for an error due to guest misbehavior. */ - void (*guest_error)(const char *msg, void *opaque); - /* Return the virtual clock value in nanoseconds */ - int64_t (*clock_get_ns)(void *opaque); - /* Create a new timer with the given callback and opaque data. Not - * needed if timer_new_opaque is provided. */ - void *(*timer_new)(SlirpTimerCb cb, void *cb_opaque, void *opaque); - /* Remove and free a timer */ - void (*timer_free)(void *timer, void *opaque); - /* Modify a timer to expire at @expire_time (ms) */ - void (*timer_mod)(void *timer, int64_t expire_time, void *opaque); - /* Register a fd for future polling */ - void (*register_poll_fd)(int fd, void *opaque); - /* Unregister a fd */ - void (*unregister_poll_fd)(int fd, void *opaque); - /* Kick the io-thread, to signal that new events may be processed because some TCP buffer - * can now receive more data, i.e. slirp_socket_can_recv will return 1. */ - void (*notify)(void *opaque); - - /* - * Fields introduced in SlirpConfig version 4 begin - */ - - /* Initialization has completed and a Slirp* has been created. */ - void (*init_completed)(Slirp *slirp, void *opaque); - /* Create a new timer. When the timer fires, the application passes - * the SlirpTimerId and cb_opaque to slirp_handle_timer. */ - void *(*timer_new_opaque)(SlirpTimerId id, void *cb_opaque, void *opaque); -} SlirpCb; - -#define SLIRP_CONFIG_VERSION_MIN 1 -#define SLIRP_CONFIG_VERSION_MAX 4 - -typedef struct SlirpConfig { - /* Version must be provided */ - uint32_t version; - /* - * Fields introduced in SlirpConfig version 1 begin - */ - int restricted; - bool in_enabled; - struct in_addr vnetwork; - struct in_addr vnetmask; - struct in_addr vhost; - bool in6_enabled; - struct in6_addr vprefix_addr6; - uint8_t vprefix_len; - struct in6_addr vhost6; - const char *vhostname; - const char *tftp_server_name; - const char *tftp_path; - const char *bootfile; - struct in_addr vdhcp_start; - struct in_addr vnameserver; - struct in6_addr vnameserver6; - const char **vdnssearch; - const char *vdomainname; - /* Default: IF_MTU_DEFAULT */ - size_t if_mtu; - /* Default: IF_MRU_DEFAULT */ - size_t if_mru; - /* Prohibit connecting to 127.0.0.1:* */ - bool disable_host_loopback; - /* - * Enable emulation code (*warning*: this code isn't safe, it is not - * recommended to enable it) - */ - bool enable_emu; - /* - * Fields introduced in SlirpConfig version 2 begin - */ - struct sockaddr_in *outbound_addr; - struct sockaddr_in6 *outbound_addr6; - /* - * Fields introduced in SlirpConfig version 3 begin - */ - bool disable_dns; /* slirp will not redirect/serve any DNS packet */ - /* - * Fields introduced in SlirpConfig version 4 begin - */ - bool disable_dhcp; /* slirp will not reply to any DHCP requests */ -} SlirpConfig; - -/* Create a new instance of a slirp stack */ -Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks, - void *opaque); -/* slirp_init is deprecated in favor of slirp_new */ -Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, - struct in_addr vnetmask, struct in_addr vhost, - bool in6_enabled, struct in6_addr vprefix_addr6, - uint8_t vprefix_len, struct in6_addr vhost6, - const char *vhostname, const char *tftp_server_name, - const char *tftp_path, const char *bootfile, - struct in_addr vdhcp_start, struct in_addr vnameserver, - struct in6_addr vnameserver6, const char **vdnssearch, - const char *vdomainname, const SlirpCb *callbacks, - void *opaque); -/* Shut down an instance of a slirp stack */ -void slirp_cleanup(Slirp *slirp); - -/* This is called by the application when it is about to sleep through poll(). - * *timeout is set to the amount of virtual time (in ms) that the application intends to - * wait (UINT32_MAX if infinite). slirp_pollfds_fill updates it according to - * e.g. TCP timers, so the application knows it should sleep a smaller amount of - * time. slirp_pollfds_fill calls add_poll for each file descriptor - * that should be monitored along the sleep. The opaque pointer is passed as - * such to add_poll, and add_poll returns an index. */ -void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout, - SlirpAddPollCb add_poll, void *opaque); - -/* This is called by the application after sleeping, to report which file - * descriptors are available. slirp_pollfds_poll calls get_revents on each file - * descriptor, giving it the index that add_poll returned during the - * slirp_pollfds_fill call, to know whether the descriptor is available for - * read/write/etc. (SLIRP_POLL_*) - * select_error should be passed 1 if poll() returned an error. */ -void slirp_pollfds_poll(Slirp *slirp, int select_error, - SlirpGetREventsCb get_revents, void *opaque); - -/* This is called by the application when the guest emits a packet on the - * guest network, to be interpreted by slirp. */ -void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); - -/* This is called by the application when a timer expires, if it provides - * the timer_new_opaque callback. It is not needed if the application only - * uses timer_new. */ -void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque); - -/* These set up / remove port forwarding between a host port in the real world - * and the guest network. */ -int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, - int host_port, struct in_addr guest_addr, int guest_port); -int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, - int host_port); - -#define SLIRP_HOSTFWD_UDP 1 -#define SLIRP_HOSTFWD_V6ONLY 2 -int slirp_add_hostxfwd(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *gaddr, socklen_t gaddrlen, - int flags); -int slirp_remove_hostxfwd(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - int flags); - -/* Set up port forwarding between a port in the guest network and a - * command running on the host */ -int slirp_add_exec(Slirp *slirp, const char *cmdline, - struct in_addr *guest_addr, int guest_port); -/* Set up port forwarding between a port in the guest network and a - * Unix port on the host */ -int slirp_add_unix(Slirp *slirp, const char *unixsock, - struct in_addr *guest_addr, int guest_port); -/* Set up port forwarding between a port in the guest network and a - * callback that will receive the data coming from the port */ -int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque, - struct in_addr *guest_addr, int guest_port); - -/* TODO: rather identify a guestfwd through an opaque pointer instead of through - * the guest_addr */ - -/* This is called by the application for a guestfwd, to determine how much data - * can be received by the forwarded port through a call to slirp_socket_recv. */ -size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr, - int guest_port); -/* This is called by the application for a guestfwd, to provide the data to be - * sent on the forwarded port */ -void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port, - const uint8_t *buf, int size); - -/* Remove entries added by slirp_add_exec, slirp_add_unix or slirp_add_guestfwd */ -int slirp_remove_guestfwd(Slirp *slirp, struct in_addr guest_addr, - int guest_port); - -/* Return a human-readable state of the slirp stack */ -char *slirp_connection_info(Slirp *slirp); - -/* Return a human-readable state of the NDP/ARP tables */ -char *slirp_neighbor_info(Slirp *slirp); - -/* Save the slirp state through the write_cb. The opaque pointer is passed as - * such to the write_cb. */ -void slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque); - -/* Returns the version of the slirp state, to be saved along the state */ -int slirp_state_version(void); - -/* Load the slirp state through the read_cb. The opaque pointer is passed as - * such to the read_cb. The version should be given as it was obtained from - * slirp_state_version when slirp_state_save was called. */ -int slirp_state_load(Slirp *s, int version_id, SlirpReadCb read_cb, - void *opaque); - -/* Return the version of the slirp implementation */ -const char *slirp_version_string(void); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* LIBSLIRP_H */ diff --git a/src/network/slirp/main.h b/src/network/slirp/main.h deleted file mode 100644 index 3b3f88370..000000000 --- a/src/network/slirp/main.h +++ /dev/null @@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef SLIRP_MAIN_H -#define SLIRP_MAIN_H - -extern unsigned curtime; -extern struct in_addr loopback_addr; -extern unsigned long loopback_mask; - -int if_encap(Slirp *slirp, struct mbuf *ifm); -ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags); - -#endif diff --git a/src/network/slirp/mbuf.c b/src/network/slirp/mbuf.c deleted file mode 100644 index 153b36c03..000000000 --- a/src/network/slirp/mbuf.c +++ /dev/null @@ -1,282 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski - */ - -/* - * mbuf's in SLiRP are much simpler than the real mbufs in - * FreeBSD. They are fixed size, determined by the MTU, - * so that one whole packet can fit. Mbuf's cannot be - * chained together. If there's more data than the mbuf - * could hold, an external g_malloced buffer is pointed to - * by m_ext (and the data pointers) and M_EXT is set in - * the flags - */ - -#include "slirp.h" -#include - -#define MBUF_THRESH 30 - -/* - * Find a nice value for msize - */ -#define SLIRP_MSIZE(mtu) \ - (offsetof(struct mbuf, m_dat) + IF_MAXLINKHDR + TCPIPHDR_DELTA + (mtu)) - -void m_init(Slirp *slirp) -{ - slirp->m_freelist.qh_link = slirp->m_freelist.qh_rlink = &slirp->m_freelist; - slirp->m_usedlist.qh_link = slirp->m_usedlist.qh_rlink = &slirp->m_usedlist; -} - -static void m_cleanup_list(struct slirp_quehead *list_head) -{ - struct mbuf *m, *next; - - m = (struct mbuf *)list_head->qh_link; - while ((struct slirp_quehead *)m != list_head) { - next = m->m_next; - if (m->m_flags & M_EXT) { - g_free(m->m_ext); - } - g_free(m); - m = next; - } - list_head->qh_link = list_head; - list_head->qh_rlink = list_head; -} - -void m_cleanup(Slirp *slirp) -{ - m_cleanup_list(&slirp->m_usedlist); - m_cleanup_list(&slirp->m_freelist); - m_cleanup_list(&slirp->if_batchq); - m_cleanup_list(&slirp->if_fastq); -} - -/* - * Get an mbuf from the free list, if there are none - * allocate one - * - * Because fragmentation can occur if we alloc new mbufs and - * free old mbufs, we mark all mbufs above mbuf_thresh as M_DOFREE, - * which tells m_free to actually g_free() it - */ -struct mbuf *m_get(Slirp *slirp) -{ - register struct mbuf *m; - int flags = 0; - - DEBUG_CALL("m_get"); - - if (MBUF_DEBUG || slirp->m_freelist.qh_link == &slirp->m_freelist) { - m = g_malloc(SLIRP_MSIZE(slirp->if_mtu)); - slirp->mbuf_alloced++; - if (MBUF_DEBUG || slirp->mbuf_alloced > MBUF_THRESH) - flags = M_DOFREE; - m->slirp = slirp; - } else { - m = (struct mbuf *)slirp->m_freelist.qh_link; - slirp_remque(m); - } - - /* Insert it in the used list */ - slirp_insque(m, &slirp->m_usedlist); - m->m_flags = (flags | M_USEDLIST); - - /* Initialise it */ - m->m_size = SLIRP_MSIZE(slirp->if_mtu) - offsetof(struct mbuf, m_dat); - m->m_data = m->m_dat; - m->m_len = 0; - m->m_nextpkt = NULL; - m->m_prevpkt = NULL; - m->resolution_requested = false; - m->expiration_date = (uint64_t)-1; - DEBUG_ARG("m = %p", m); - return m; -} - -void m_free(struct mbuf *m) -{ - DEBUG_CALL("m_free"); - DEBUG_ARG("m = %p", m); - - if (m) { - /* Remove from m_usedlist */ - if (m->m_flags & M_USEDLIST) - slirp_remque(m); - - /* If it's M_EXT, free() it */ - if (m->m_flags & M_EXT) { - g_free(m->m_ext); - m->m_flags &= ~M_EXT; - } - /* - * Either free() it or put it on the free list - */ - if (m->m_flags & M_DOFREE) { - m->slirp->mbuf_alloced--; - g_free(m); - } else if ((m->m_flags & M_FREELIST) == 0) { - slirp_insque(m, &m->slirp->m_freelist); - m->m_flags = M_FREELIST; /* Clobber other flags */ - } - } /* if(m) */ -} - -/* - * Copy data from one mbuf to the end of - * the other.. if result is too big for one mbuf, allocate - * an M_EXT data segment - */ -void m_cat(struct mbuf *m, struct mbuf *n) -{ - /* - * If there's no room, realloc - */ - if (M_FREEROOM(m) < n->m_len) - m_inc(m, m->m_len + n->m_len); - - memcpy(m->m_data + m->m_len, n->m_data, n->m_len); - m->m_len += n->m_len; - - m_free(n); -} - - -/* make m 'size' bytes large from m_data */ -void m_inc(struct mbuf *m, int size) -{ - int gapsize; - - /* some compilers throw up on gotos. This one we can fake. */ - if (M_ROOM(m) > size) { - return; - } - - if (m->m_flags & M_EXT) { - gapsize = m->m_data - m->m_ext; - m->m_ext = g_realloc(m->m_ext, size + gapsize); - } else { - gapsize = m->m_data - m->m_dat; - m->m_ext = g_malloc(size + gapsize); - memcpy(m->m_ext, m->m_dat, m->m_size); - m->m_flags |= M_EXT; - } - - m->m_data = m->m_ext + gapsize; - m->m_size = size + gapsize; -} - - -void m_adj(struct mbuf *m, int len) -{ - if (m == NULL) - return; - if (len >= 0) { - /* Trim from head */ - m->m_data += len; - m->m_len -= len; - } else { - /* Trim from tail */ - len = -len; - m->m_len -= len; - } -} - - -/* - * Copy len bytes from m, starting off bytes into n - */ -int m_copy(struct mbuf *n, struct mbuf *m, int off, int len) -{ - if (len > M_FREEROOM(n)) - return -1; - - memcpy((n->m_data + n->m_len), (m->m_data + off), len); - n->m_len += len; - return 0; -} - - -/* - * Given a pointer into an mbuf, return the mbuf - * XXX This is a kludge, I should eliminate the need for it - * Fortunately, it's not used often - */ -struct mbuf *dtom(Slirp *slirp, void *dat) -{ - struct mbuf *m; - - DEBUG_CALL("dtom"); - DEBUG_ARG("dat = %p", dat); - - /* bug corrected for M_EXT buffers */ - for (m = (struct mbuf *)slirp->m_usedlist.qh_link; - (struct slirp_quehead *)m != &slirp->m_usedlist; m = m->m_next) { - if (m->m_flags & M_EXT) { - if ((char *)dat >= m->m_ext && (char *)dat < (m->m_ext + m->m_size)) - return m; - } else { - if ((char *)dat >= m->m_dat && (char *)dat < (m->m_dat + m->m_size)) - return m; - } - } - - DEBUG_ERROR("dtom failed"); - - return (struct mbuf *)0; -} - -/* - * Duplicate the mbuf - * - * copy_header specifies whether the bytes before m_data should also be copied. - * header_size specifies how many bytes are to be reserved before m_data. - */ -struct mbuf *m_dup(Slirp *slirp, struct mbuf *m, - bool copy_header, - size_t header_size) -{ - struct mbuf *n; - int mcopy_result; - - /* The previous mbuf was supposed to have it already, we can check it along - * the way */ - assert(M_ROOMBEFORE(m) >= header_size); - - n = m_get(slirp); - m_inc(n, m->m_len + header_size); - - if (copy_header) { - m->m_len += header_size; - m->m_data -= header_size; - mcopy_result = m_copy(n, m, 0, m->m_len + header_size); - n->m_data += header_size; - m->m_len -= header_size; - m->m_data += header_size; - } else { - n->m_data += header_size; - mcopy_result = m_copy(n, m, 0, m->m_len); - } - g_assert(mcopy_result == 0); - - return n; -} - -void *mtod_check(struct mbuf *m, size_t len) -{ - if (m->m_len >= len) { - return m->m_data; - } - - DEBUG_ERROR("mtod failed"); - - return NULL; -} - -void *m_end(struct mbuf *m) -{ - return m->m_data + m->m_len; -} diff --git a/src/network/slirp/mbuf.h b/src/network/slirp/mbuf.h deleted file mode 100644 index aedfc712e..000000000 --- a/src/network/slirp/mbuf.h +++ /dev/null @@ -1,192 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)mbuf.h 8.3 (Berkeley) 1/21/94 - * mbuf.h,v 1.9 1994/11/14 13:54:20 bde Exp - */ - -#ifndef MBUF_H -#define MBUF_H - -/* - * Macros for type conversion - * mtod(m,t) - convert mbuf pointer to data pointer of correct type - */ -#define mtod(m, t) ((t)(m)->m_data) - -/* XXX About mbufs for slirp: - * Only one mbuf is ever used in a chain, for each "cell" of data. - * m_nextpkt points to the next packet, if fragmented. - * If the data is too large, the M_EXT is used, and a larger block - * is alloced. Therefore, m_free[m] must check for M_EXT and if set - * free the m_ext. This is inefficient memory-wise, but who cares. - */ - -/* - * mbufs allow to have a gap between the start of the allocated buffer (m_ext if - * M_EXT is set, m_dat otherwise) and the in-use data: - * - * |--gapsize----->|---m_len-------> - * |----------m_size------------------------------> - * |----M_ROOM--------------------> - * |-M_FREEROOM--> - * - * ^ ^ ^ - * m_dat/m_ext m_data end of buffer - */ - -/* - * How much room is in the mbuf, from m_data to the end of the mbuf - */ -#define M_ROOM(m) \ - ((m->m_flags & M_EXT) ? (((m)->m_ext + (m)->m_size) - (m)->m_data) : \ - (((m)->m_dat + (m)->m_size) - (m)->m_data)) - -/* - * How much free room there is - */ -#define M_FREEROOM(m) (M_ROOM(m) - (m)->m_len) - -/* - * How much free room there is before m_data - */ -#define M_ROOMBEFORE(m) \ - (((m)->m_flags & M_EXT) ? (m)->m_data - (m)->m_ext \ - : (m)->m_data - (m)->m_dat) - -struct mbuf { - /* XXX should union some of these! */ - /* header at beginning of each mbuf: */ - struct mbuf *m_next; /* Linked list of mbufs */ - struct mbuf *m_prev; - struct mbuf *m_nextpkt; /* Next packet in queue/record */ - struct mbuf *m_prevpkt; /* Flags aren't used in the output queue */ - int m_flags; /* Misc flags */ - - int m_size; /* Size of mbuf, from m_dat or m_ext */ - struct socket *m_so; - - char *m_data; /* Current location of data */ - int m_len; /* Amount of data in this mbuf, from m_data */ - - Slirp *slirp; - bool resolution_requested; - uint64_t expiration_date; - char *m_ext; - /* start of dynamic buffer area, must be last element */ - char m_dat[]; -}; - -#define ifq_prev m_prev -#define ifq_next m_next -#define ifs_prev m_prevpkt -#define ifs_next m_nextpkt -#define ifq_so m_so - -#define M_EXT 0x01 /* m_ext points to more (malloced) data */ -#define M_FREELIST 0x02 /* mbuf is on free list */ -#define M_USEDLIST 0x04 /* XXX mbuf is on used list (for dtom()) */ -#define M_DOFREE \ - 0x08 /* when m_free is called on the mbuf, free() \ - * it rather than putting it on the free list */ - -void m_init(Slirp *); -void m_cleanup(Slirp *slirp); -struct mbuf *m_get(Slirp *); -void m_free(struct mbuf *); -void m_cat(register struct mbuf *, register struct mbuf *); -void m_inc(struct mbuf *, int); -void m_adj(struct mbuf *, int); -int m_copy(struct mbuf *, struct mbuf *, int, int); -struct mbuf *m_dup(Slirp *slirp, struct mbuf *m, bool copy_header, size_t header_size); -struct mbuf *dtom(Slirp *, void *); -void *mtod_check(struct mbuf *, size_t len); -void *m_end(struct mbuf *); - -static inline void ifs_init(struct mbuf *ifm) -{ - ifm->ifs_next = ifm->ifs_prev = ifm; -} - -#ifdef SLIRP_DEBUG -# define MBUF_DEBUG 1 -#else -# ifdef HAVE_VALGRIND -# include -# define MBUF_DEBUG RUNNING_ON_VALGRIND -# else -# define MBUF_DEBUG 0 -# endif -#endif - -/* - * When a function is given an mbuf as well as the responsibility to free it, we - * want valgrind etc. to properly identify the new responsible for the - * free. Achieve this by making a new copy. For instance: - * - * f0(void) { - * struct mbuf *m = m_get(slirp); - * [...] - * switch (something) { - * case 1: - * f1(m); - * break; - * case 2: - * f2(m); - * break; - * [...] - * } - * } - * - * f1(struct mbuf *m) { - * M_DUP_DEBUG(m->slirp, m); - * [...] - * m_free(m); // but author of f1 might be forgetting this - * } - * - * f0 transfers the freeing responsibility to f1, f2, etc. Without the - * M_DUP_DEBUG call in f1, valgrind would tell us that it is f0 where the buffer - * was allocated, but it's difficult to know whether a leak is actually in f0, - * or in f1, or in f2, etc. Duplicating the mbuf in M_DUP_DEBUG each time the - * responsibility is transferred allows to immediately know where the leak - * actually is. - */ -#define M_DUP_DEBUG(slirp, m, copy_header, header_size) do { \ - if (MBUF_DEBUG) { \ - struct mbuf *__n; \ - __n = m_dup((slirp), (m), (copy_header), (header_size)); \ - m_free(m); \ - (m) = __n; \ - } else { \ - (void) (slirp); (void) (copy_header); \ - g_assert(M_ROOMBEFORE(m) >= (header_size)); \ - } \ -} while(0) - -#endif diff --git a/src/network/slirp/misc.c b/src/network/slirp/misc.c deleted file mode 100644 index 220506328..000000000 --- a/src/network/slirp/misc.c +++ /dev/null @@ -1,459 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" -#include -#ifdef G_OS_UNIX -#include -#include -#ifdef BSD -#define g_strlcpy strlcpy -#else -extern gsize g_strlcpy(gchar* dest, const gchar* src, gsize dest_size); -#endif -#endif - -#ifdef __APPLE__ -#include -#endif - -extern inline void slirp_insque(void *a, void *b) -{ - register struct slirp_quehead *element = (struct slirp_quehead *)a; - register struct slirp_quehead *head = (struct slirp_quehead *)b; - element->qh_link = head->qh_link; - head->qh_link = (struct slirp_quehead *)element; - element->qh_rlink = (struct slirp_quehead *)head; - ((struct slirp_quehead *)(element->qh_link))->qh_rlink = - (struct slirp_quehead *)element; -} - -extern inline void slirp_remque(void *a) -{ - register struct slirp_quehead *element = (struct slirp_quehead *)a; - ((struct slirp_quehead *)(element->qh_link))->qh_rlink = element->qh_rlink; - ((struct slirp_quehead *)(element->qh_rlink))->qh_link = element->qh_link; - element->qh_rlink = NULL; -} - -/* TODO: IPv6 */ -struct gfwd_list *add_guestfwd(struct gfwd_list **ex_ptr, SlirpWriteCb write_cb, - void *opaque, struct in_addr addr, int port) -{ - struct gfwd_list *f = g_new0(struct gfwd_list, 1); - - f->write_cb = write_cb; - f->opaque = opaque; - f->ex_fport = port; - f->ex_addr = addr; - f->ex_next = *ex_ptr; - *ex_ptr = f; - - return f; -} - -struct gfwd_list *add_exec(struct gfwd_list **ex_ptr, const char *cmdline, - struct in_addr addr, int port) -{ - struct gfwd_list *f = add_guestfwd(ex_ptr, NULL, NULL, addr, port); - - f->ex_exec = g_strdup(cmdline); - - return f; -} - -struct gfwd_list *add_unix(struct gfwd_list **ex_ptr, const char *unixsock, - struct in_addr addr, int port) -{ - struct gfwd_list *f = add_guestfwd(ex_ptr, NULL, NULL, addr, port); - - f->ex_unix = g_strdup(unixsock); - - return f; -} - -int remove_guestfwd(struct gfwd_list **ex_ptr, struct in_addr addr, int port) -{ - for (; *ex_ptr != NULL; ex_ptr = &((*ex_ptr)->ex_next)) { - struct gfwd_list *f = *ex_ptr; - if (f->ex_addr.s_addr == addr.s_addr && f->ex_fport == port) { - *ex_ptr = f->ex_next; - g_free(f->ex_exec); - g_free(f); - return 0; - } - } - return -1; -} - -static int slirp_socketpair_with_oob(int sv[2]) -{ - struct sockaddr_in addr = { - .sin_family = AF_INET, - .sin_port = 0, - .sin_addr.s_addr = htonl(INADDR_LOOPBACK), - }; - socklen_t addrlen = sizeof(addr); - int ret, s; - - sv[1] = -1; - s = slirp_socket(AF_INET, SOCK_STREAM, 0); - if (s < 0 || bind(s, (struct sockaddr *)&addr, addrlen) < 0 || - listen(s, 1) < 0 || - getsockname(s, (struct sockaddr *)&addr, &addrlen) < 0) { - goto err; - } - - sv[1] = slirp_socket(AF_INET, SOCK_STREAM, 0); - if (sv[1] < 0) { - goto err; - } - /* - * This connect won't block because we've already listen()ed on - * the server end (even though we won't accept() the connection - * until later on). - */ - do { - ret = connect(sv[1], (struct sockaddr *)&addr, addrlen); - } while (ret < 0 && errno == EINTR); - if (ret < 0) { - goto err; - } - - do { - sv[0] = accept(s, (struct sockaddr *)&addr, &addrlen); - } while (sv[0] < 0 && errno == EINTR); - if (sv[0] < 0) { - goto err; - } - - closesocket(s); - return 0; - -err: - g_critical("slirp_socketpair(): %s", strerror(errno)); - if (s >= 0) { - closesocket(s); - } - if (sv[1] >= 0) { - closesocket(sv[1]); - } - return -1; -} - -static void fork_exec_child_setup(gpointer data) -{ -#ifndef _WIN32 - setsid(); - - /* Unblock all signals and leave our exec()-ee to block what it wants */ - sigset_t ss; - sigemptyset(&ss); - sigprocmask(SIG_SETMASK, &ss, NULL); - - /* POSIX is obnoxious about SIGCHLD specifically across exec() */ - signal(SIGCHLD, SIG_DFL); -#endif -} - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - -#if !GLIB_CHECK_VERSION(2, 58, 0) -typedef struct SlirpGSpawnFds { - GSpawnChildSetupFunc child_setup; - gpointer user_data; - gint stdin_fd; - gint stdout_fd; - gint stderr_fd; -} SlirpGSpawnFds; - -static inline void slirp_gspawn_fds_setup(gpointer user_data) -{ - SlirpGSpawnFds *q = (SlirpGSpawnFds *)user_data; - - dup2(q->stdin_fd, 0); - dup2(q->stdout_fd, 1); - dup2(q->stderr_fd, 2); - q->child_setup(q->user_data); -} -#endif - -static inline gboolean -g_spawn_async_with_fds_slirp(const gchar *working_directory, gchar **argv, - gchar **envp, GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, GPid *child_pid, gint stdin_fd, - gint stdout_fd, gint stderr_fd, GError **error) -{ -#if GLIB_CHECK_VERSION(2, 58, 0) - return g_spawn_async_with_fds(working_directory, argv, envp, flags, - child_setup, user_data, child_pid, stdin_fd, - stdout_fd, stderr_fd, error); -#else - SlirpGSpawnFds setup = { - .child_setup = child_setup, - .user_data = user_data, - .stdin_fd = stdin_fd, - .stdout_fd = stdout_fd, - .stderr_fd = stderr_fd, - }; - - return g_spawn_async(working_directory, argv, envp, flags, - slirp_gspawn_fds_setup, &setup, child_pid, error); -#endif -} - -#define g_spawn_async_with_fds(wd, argv, env, f, c, d, p, ifd, ofd, efd, err) \ - g_spawn_async_with_fds_slirp(wd, argv, env, f, c, d, p, ifd, ofd, efd, err) - -#ifdef __GNUC__ -#pragma GCC diagnostic pop -#endif - -int fork_exec(struct socket *so, const char *ex) -{ - GError *err = NULL; - gint argc = 0; - gchar **argv = NULL; - int opt, sp[2]; - - DEBUG_CALL("fork_exec"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("ex = %p", ex); - - if (slirp_socketpair_with_oob(sp) < 0) { - return 0; - } - - if (!g_shell_parse_argv(ex, &argc, &argv, &err)) { - g_critical("fork_exec invalid command: %s\nerror: %s", ex, err->message); - g_error_free(err); - return 0; - } - - g_spawn_async_with_fds(NULL /* cwd */, argv, NULL /* env */, - G_SPAWN_SEARCH_PATH, fork_exec_child_setup, - NULL /* data */, NULL /* child_pid */, sp[1], sp[1], - sp[1], &err); - g_strfreev(argv); - - if (err) { - g_critical("fork_exec: %s", err->message); - g_error_free(err); - closesocket(sp[0]); - closesocket(sp[1]); - return 0; - } - - so->s = sp[0]; - closesocket(sp[1]); - slirp_socket_set_fast_reuse(so->s); - opt = 1; - setsockopt(so->s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - slirp_set_nonblock(so->s); - so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); - return 1; -} - -int open_unix(struct socket *so, const char *unixpath) -{ -#ifdef G_OS_UNIX - struct sockaddr_un sa; - int s; - - DEBUG_CALL("open_unix"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("unixpath = %s", unixpath); - - memset(&sa, 0, sizeof(sa)); - sa.sun_family = AF_UNIX; - if (g_strlcpy(sa.sun_path, unixpath, sizeof(sa.sun_path)) >= sizeof(sa.sun_path)) { - g_critical("Bad unix path: %s", unixpath); - return 0; - } - - s = slirp_socket(PF_UNIX, SOCK_STREAM, 0); - if (s < 0) { - g_critical("open_unix(): %s", strerror(errno)); - return 0; - } - - if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) { - g_critical("open_unix(): %s", strerror(errno)); - closesocket(s); - return 0; - } - - so->s = s; - slirp_set_nonblock(so->s); - so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); - - return 1; -#else - g_assert_not_reached(); -#endif -} - -char *slirp_connection_info(Slirp *slirp) -{ - GString *str = g_string_new(NULL); - const char *const tcpstates[] = { - [TCPS_CLOSED] = "CLOSED", [TCPS_LISTEN] = "LISTEN", - [TCPS_SYN_SENT] = "SYN_SENT", [TCPS_SYN_RECEIVED] = "SYN_RCVD", - [TCPS_ESTABLISHED] = "ESTABLISHED", [TCPS_CLOSE_WAIT] = "CLOSE_WAIT", - [TCPS_FIN_WAIT_1] = "FIN_WAIT_1", [TCPS_CLOSING] = "CLOSING", - [TCPS_LAST_ACK] = "LAST_ACK", [TCPS_FIN_WAIT_2] = "FIN_WAIT_2", - [TCPS_TIME_WAIT] = "TIME_WAIT", - }; - struct in_addr dst_addr; - struct sockaddr_in src; - socklen_t src_len; - uint16_t dst_port; - struct socket *so; - const char *state; - char addr[INET_ADDRSTRLEN]; - char buf[20]; - - g_string_append_printf(str, - " Protocol[State] FD Source Address Port " - "Dest. Address Port RecvQ SendQ\n"); - - /* TODO: IPv6 */ - - for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so->so_next) { - if (so->so_state & SS_HOSTFWD) { - state = "HOST_FORWARD"; - } else if (so->so_tcpcb) { - state = tcpstates[so->so_tcpcb->t_state]; - } else { - state = "NONE"; - } - if (so->so_state & (SS_HOSTFWD | SS_INCOMING)) { - src_len = sizeof(src); - getsockname(so->s, (struct sockaddr *)&src, &src_len); - dst_addr = so->so_laddr; - dst_port = so->so_lport; - } else { - src.sin_addr = so->so_laddr; - src.sin_port = so->so_lport; - dst_addr = so->so_faddr; - dst_port = so->so_fport; - } - slirp_fmt0(buf, sizeof(buf), " TCP[%s]", state); - g_string_append_printf(str, "%-19s %3d %15s %5d ", buf, so->s, - src.sin_addr.s_addr ? - inet_ntop(AF_INET, &src.sin_addr, addr, sizeof(addr)) : "*", - ntohs(src.sin_port)); - g_string_append_printf(str, "%15s %5d %5d %5d\n", - inet_ntop(AF_INET, &dst_addr, addr, sizeof(addr)), - ntohs(dst_port), so->so_rcv.sb_cc, - so->so_snd.sb_cc); - } - - for (so = slirp->udb.so_next; so != &slirp->udb; so = so->so_next) { - if (so->so_state & SS_HOSTFWD) { - slirp_fmt0(buf, sizeof(buf), " UDP[HOST_FORWARD]"); - src_len = sizeof(src); - getsockname(so->s, (struct sockaddr *)&src, &src_len); - dst_addr = so->so_laddr; - dst_port = so->so_lport; - } else { - slirp_fmt0(buf, sizeof(buf), " UDP[%d sec]", - (so->so_expire - curtime) / 1000); - src.sin_addr = so->so_laddr; - src.sin_port = so->so_lport; - dst_addr = so->so_faddr; - dst_port = so->so_fport; - } - g_string_append_printf(str, "%-19s %3d %15s %5d ", buf, so->s, - src.sin_addr.s_addr ? - inet_ntop(AF_INET, &src.sin_addr, addr, sizeof(addr)) : "*", - ntohs(src.sin_port)); - g_string_append_printf(str, "%15s %5d %5d %5d\n", - inet_ntop(AF_INET, &dst_addr, addr, sizeof(addr)), - ntohs(dst_port), so->so_rcv.sb_cc, - so->so_snd.sb_cc); - } - - for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so->so_next) { - slirp_fmt0(buf, sizeof(buf), " ICMP[%d sec]", - (so->so_expire - curtime) / 1000); - src.sin_addr = so->so_laddr; - dst_addr = so->so_faddr; - g_string_append_printf(str, "%-19s %3d %15s - ", buf, so->s, - src.sin_addr.s_addr ? - inet_ntop(AF_INET, &src.sin_addr, addr, sizeof(addr)) : "*"); - g_string_append_printf(str, "%15s - %5d %5d\n", - inet_ntop(AF_INET, &dst_addr, addr, sizeof(addr)), - so->so_rcv.sb_cc, so->so_snd.sb_cc); - } - - return g_string_free(str, false); -} - -char *slirp_neighbor_info(Slirp *slirp) -{ - GString *str = g_string_new(NULL); - ArpTable *arp_table = &slirp->arp_table; - NdpTable *ndp_table = &slirp->ndp_table; - char ip_addr[INET6_ADDRSTRLEN]; - char eth_addr[ETH_ADDRSTRLEN]; - const char *ip; - - g_string_append_printf(str, " %5s %-17s %s\n", - "Table", "MacAddr", "IP Address"); - - for (int i = 0; i < ARP_TABLE_SIZE; ++i) { - struct in_addr addr; - addr.s_addr = arp_table->table[i].ar_sip; - if (!addr.s_addr) { - continue; - } - ip = inet_ntop(AF_INET, &addr, ip_addr, sizeof(ip_addr)); - g_assert(ip != NULL); - g_string_append_printf(str, " %5s %-17s %s\n", "ARP", - slirp_ether_ntoa(arp_table->table[i].ar_sha, - eth_addr, sizeof(eth_addr)), - ip); - } - - for (int i = 0; i < NDP_TABLE_SIZE; ++i) { - if (in6_zero(&ndp_table->table[i].ip_addr)) { - continue; - } - ip = inet_ntop(AF_INET6, &ndp_table->table[i].ip_addr, ip_addr, - sizeof(ip_addr)); - g_assert(ip != NULL); - g_string_append_printf(str, " %5s %-17s %s\n", "NDP", - slirp_ether_ntoa(ndp_table->table[i].eth_addr, - eth_addr, sizeof(eth_addr)), - ip); - } - - return g_string_free(str, false); -} - -int slirp_bind_outbound(struct socket *so, unsigned short af) -{ - int ret = 0; - struct sockaddr *addr = NULL; - int addr_size = 0; - - if (af == AF_INET && so->slirp->outbound_addr != NULL) { - addr = (struct sockaddr *)so->slirp->outbound_addr; - addr_size = sizeof(struct sockaddr_in); - } else if (af == AF_INET6 && so->slirp->outbound_addr6 != NULL) { - addr = (struct sockaddr *)so->slirp->outbound_addr6; - addr_size = sizeof(struct sockaddr_in6); - } - - if (addr != NULL) { - ret = bind(so->s, addr, addr_size); - } - return ret; -} diff --git a/src/network/slirp/misc.h b/src/network/slirp/misc.h deleted file mode 100644 index 81b370cfb..000000000 --- a/src/network/slirp/misc.h +++ /dev/null @@ -1,72 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef MISC_H -#define MISC_H - -#include "libslirp.h" - -struct gfwd_list { - SlirpWriteCb write_cb; - void *opaque; - struct in_addr ex_addr; /* Server address */ - int ex_fport; /* Port to telnet to */ - char *ex_exec; /* Command line of what to exec */ - char *ex_unix; /* unix socket */ - struct gfwd_list *ex_next; -}; - -#define EMU_NONE 0x0 - -/* TCP emulations */ -#define EMU_CTL 0x1 -#define EMU_FTP 0x2 -#define EMU_KSH 0x3 -#define EMU_IRC 0x4 -#define EMU_REALAUDIO 0x5 -#define EMU_RLOGIN 0x6 -#define EMU_IDENT 0x7 - -#define EMU_NOCONNECT 0x10 /* Don't connect */ - -struct tos_t { - uint16_t lport; - uint16_t fport; - uint8_t tos; - uint8_t emu; -}; - -struct emu_t { - uint16_t lport; - uint16_t fport; - uint8_t tos; - uint8_t emu; - struct emu_t *next; -}; - -struct slirp_quehead { - struct slirp_quehead *qh_link; - struct slirp_quehead *qh_rlink; -}; - -void slirp_insque(void *, void *); -void slirp_remque(void *); -int fork_exec(struct socket *so, const char *ex); -int open_unix(struct socket *so, const char *unixsock); - -struct gfwd_list *add_guestfwd(struct gfwd_list **ex_ptr, SlirpWriteCb write_cb, - void *opaque, struct in_addr addr, int port); - -struct gfwd_list *add_exec(struct gfwd_list **ex_ptr, const char *cmdline, - struct in_addr addr, int port); - -struct gfwd_list *add_unix(struct gfwd_list **ex_ptr, const char *unixsock, - struct in_addr addr, int port); - -int remove_guestfwd(struct gfwd_list **ex_ptr, struct in_addr addr, int port); - -int slirp_bind_outbound(struct socket *so, unsigned short af); - -#endif diff --git a/src/network/slirp/ncsi-pkt.h b/src/network/slirp/ncsi-pkt.h deleted file mode 100644 index 7694e68ff..000000000 --- a/src/network/slirp/ncsi-pkt.h +++ /dev/null @@ -1,616 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright Gavin Shan, IBM Corporation 2016. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef NCSI_PKT_H -#define NCSI_PKT_H - -/* from linux/net/ncsi/ncsi-pkt.h */ -#define __be32 uint32_t -#define __be16 uint16_t - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_pkt_hdr { - unsigned char mc_id; /* Management controller ID */ - unsigned char revision; /* NCSI version - 0x01 */ - unsigned char reserved; /* Reserved */ - unsigned char id; /* Packet sequence number */ - unsigned char type; /* Packet type */ - unsigned char channel; /* Network controller ID */ - __be16 length; /* Payload length */ - __be32 reserved1[2]; /* Reserved */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_pkt_hdr { - struct ncsi_pkt_hdr common; /* Common NCSI packet header */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_pkt_hdr { - struct ncsi_pkt_hdr common; /* Common NCSI packet header */ - __be16 code; /* Response code */ - __be16 reason; /* Response reason */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_aen_pkt_hdr { - struct ncsi_pkt_hdr common; /* Common NCSI packet header */ - unsigned char reserved2[3]; /* Reserved */ - unsigned char type; /* AEN packet type */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* NCSI common command packet */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 checksum; /* Checksum */ - unsigned char pad[26]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Select Package */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_sp_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char hw_arbitration; /* HW arbitration */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Disable Channel */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_dc_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char ald; /* Allow link down */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Reset Channel */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_rc_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 reserved; /* Reserved */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* AEN Enable */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_ae_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char mc_id; /* MC ID */ - __be32 mode; /* AEN working mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[18]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Set Link */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_sl_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 mode; /* Link working mode */ - __be32 oem_mode; /* OEM link mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[18]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Set VLAN Filter */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_svf_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be16 reserved; /* Reserved */ - __be16 vlan; /* VLAN ID */ - __be16 reserved1; /* Reserved */ - unsigned char index; /* VLAN table index */ - unsigned char enable; /* Enable or disable */ - __be32 checksum; /* Checksum */ - unsigned char pad[14]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Enable VLAN */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_ev_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char mode; /* VLAN filter mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Set MAC Address */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_sma_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char mac[6]; /* MAC address */ - unsigned char index; /* MAC table index */ - unsigned char at_e; /* Addr type and operation */ - __be32 checksum; /* Checksum */ - unsigned char pad[18]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Enable Broadcast Filter */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_ebf_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 mode; /* Filter mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Enable Global Multicast Filter */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_cmd_egmf_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - __be32 mode; /* Global MC mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Set NCSI Flow Control */ -struct ncsi_cmd_snfc_pkt { - struct ncsi_cmd_pkt_hdr cmd; /* Command header */ - unsigned char reserved[3]; /* Reserved */ - unsigned char mode; /* Flow control mode */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Link Status */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gls_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 status; /* Link status */ - __be32 other; /* Other indications */ - __be32 oem_status; /* OEM link status */ - __be32 checksum; - unsigned char pad[10]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Version ID */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gvi_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 ncsi_version; /* NCSI version */ - unsigned char reserved[3]; /* Reserved */ - unsigned char alpha2; /* NCSI version */ - unsigned char fw_name[12]; /* f/w name string */ - __be32 fw_version; /* f/w version */ - __be16 pci_ids[4]; /* PCI IDs */ - __be32 mf_id; /* Manufacture ID */ - __be32 checksum; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Capabilities */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gc_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 cap; /* Capabilities */ - __be32 bc_cap; /* Broadcast cap */ - __be32 mc_cap; /* Multicast cap */ - __be32 buf_cap; /* Buffering cap */ - __be32 aen_cap; /* AEN cap */ - unsigned char vlan_cnt; /* VLAN filter count */ - unsigned char mixed_cnt; /* Mix filter count */ - unsigned char mc_cnt; /* MC filter count */ - unsigned char uc_cnt; /* UC filter count */ - unsigned char reserved[2]; /* Reserved */ - unsigned char vlan_mode; /* VLAN mode */ - unsigned char channel_cnt; /* Channel count */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Parameters */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gp_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - unsigned char mac_cnt; /* Number of MAC addr */ - unsigned char reserved[2]; /* Reserved */ - unsigned char mac_enable; /* MAC addr enable flags */ - unsigned char vlan_cnt; /* VLAN tag count */ - unsigned char reserved1; /* Reserved */ - __be16 vlan_enable; /* VLAN tag enable flags */ - __be32 link_mode; /* Link setting */ - __be32 bc_mode; /* BC filter mode */ - __be32 valid_modes; /* Valid mode parameters */ - unsigned char vlan_mode; /* VLAN mode */ - unsigned char fc_mode; /* Flow control mode */ - unsigned char reserved2[2]; /* Reserved */ - __be32 aen_mode; /* AEN mode */ - unsigned char mac[6]; /* Supported MAC addr */ - __be16 vlan; /* Supported VLAN tags */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get Controller Packet Statistics */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gcps_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 cnt_hi; /* Counter cleared */ - __be32 cnt_lo; /* Counter cleared */ - __be32 rx_bytes; /* Rx bytes */ - __be32 tx_bytes; /* Tx bytes */ - __be32 rx_uc_pkts; /* Rx UC packets */ - __be32 rx_mc_pkts; /* Rx MC packets */ - __be32 rx_bc_pkts; /* Rx BC packets */ - __be32 tx_uc_pkts; /* Tx UC packets */ - __be32 tx_mc_pkts; /* Tx MC packets */ - __be32 tx_bc_pkts; /* Tx BC packets */ - __be32 fcs_err; /* FCS errors */ - __be32 align_err; /* Alignment errors */ - __be32 false_carrier; /* False carrier detection */ - __be32 runt_pkts; /* Rx runt packets */ - __be32 jabber_pkts; /* Rx jabber packets */ - __be32 rx_pause_xon; /* Rx pause XON frames */ - __be32 rx_pause_xoff; /* Rx XOFF frames */ - __be32 tx_pause_xon; /* Tx XON frames */ - __be32 tx_pause_xoff; /* Tx XOFF frames */ - __be32 tx_s_collision; /* Single collision frames */ - __be32 tx_m_collision; /* Multiple collision frames */ - __be32 l_collision; /* Late collision frames */ - __be32 e_collision; /* Excessive collision frames */ - __be32 rx_ctl_frames; /* Rx control frames */ - __be32 rx_64_frames; /* Rx 64-bytes frames */ - __be32 rx_127_frames; /* Rx 65-127 bytes frames */ - __be32 rx_255_frames; /* Rx 128-255 bytes frames */ - __be32 rx_511_frames; /* Rx 256-511 bytes frames */ - __be32 rx_1023_frames; /* Rx 512-1023 bytes frames */ - __be32 rx_1522_frames; /* Rx 1024-1522 bytes frames */ - __be32 rx_9022_frames; /* Rx 1523-9022 bytes frames */ - __be32 tx_64_frames; /* Tx 64-bytes frames */ - __be32 tx_127_frames; /* Tx 65-127 bytes frames */ - __be32 tx_255_frames; /* Tx 128-255 bytes frames */ - __be32 tx_511_frames; /* Tx 256-511 bytes frames */ - __be32 tx_1023_frames; /* Tx 512-1023 bytes frames */ - __be32 tx_1522_frames; /* Tx 1024-1522 bytes frames */ - __be32 tx_9022_frames; /* Tx 1523-9022 bytes frames */ - __be32 rx_valid_bytes; /* Rx valid bytes */ - __be32 rx_runt_pkts; /* Rx error runt packets */ - __be32 rx_jabber_pkts; /* Rx error jabber packets */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get NCSI Statistics */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gns_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 rx_cmds; /* Rx NCSI commands */ - __be32 dropped_cmds; /* Dropped commands */ - __be32 cmd_type_errs; /* Command type errors */ - __be32 cmd_csum_errs; /* Command checksum errors */ - __be32 rx_pkts; /* Rx NCSI packets */ - __be32 tx_pkts; /* Tx NCSI packets */ - __be32 tx_aen_pkts; /* Tx AEN packets */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get NCSI Pass-through Statistics */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gnpts_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 tx_pkts; /* Tx packets */ - __be32 tx_dropped; /* Tx dropped packets */ - __be32 tx_channel_err; /* Tx channel errors */ - __be32 tx_us_err; /* Tx undersize errors */ - __be32 rx_pkts; /* Rx packets */ - __be32 rx_dropped; /* Rx dropped packets */ - __be32 rx_channel_err; /* Rx channel errors */ - __be32 rx_us_err; /* Rx undersize errors */ - __be32 rx_os_err; /* Rx oversize errors */ - __be32 checksum; /* Checksum */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get package status */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gps_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 status; /* Hardware arbitration status */ - __be32 checksum; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* Get package UUID */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_rsp_gpuuid_pkt { - struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - unsigned char uuid[16]; /* UUID */ - __be32 checksum; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* AEN: Link State Change */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_aen_lsc_pkt { - struct ncsi_aen_pkt_hdr aen; /* AEN header */ - __be32 status; /* Link status */ - __be32 oem_status; /* OEM link status */ - __be32 checksum; /* Checksum */ - unsigned char pad[14]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* AEN: Configuration Required */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_aen_cr_pkt { - struct ncsi_aen_pkt_hdr aen; /* AEN header */ - __be32 checksum; /* Checksum */ - unsigned char pad[22]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* AEN: Host Network Controller Driver Status Change */ -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct ncsi_aen_hncdsc_pkt { - struct ncsi_aen_pkt_hdr aen; /* AEN header */ - __be32 status; /* Status */ - __be32 checksum; /* Checksum */ - unsigned char pad[18]; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -/* NCSI packet revision */ -#define NCSI_PKT_REVISION 0x01 - -/* NCSI packet commands */ -#define NCSI_PKT_CMD_CIS 0x00 /* Clear Initial State */ -#define NCSI_PKT_CMD_SP 0x01 /* Select Package */ -#define NCSI_PKT_CMD_DP 0x02 /* Deselect Package */ -#define NCSI_PKT_CMD_EC 0x03 /* Enable Channel */ -#define NCSI_PKT_CMD_DC 0x04 /* Disable Channel */ -#define NCSI_PKT_CMD_RC 0x05 /* Reset Channel */ -#define NCSI_PKT_CMD_ECNT 0x06 /* Enable Channel Network Tx */ -#define NCSI_PKT_CMD_DCNT 0x07 /* Disable Channel Network Tx */ -#define NCSI_PKT_CMD_AE 0x08 /* AEN Enable */ -#define NCSI_PKT_CMD_SL 0x09 /* Set Link */ -#define NCSI_PKT_CMD_GLS 0x0a /* Get Link */ -#define NCSI_PKT_CMD_SVF 0x0b /* Set VLAN Filter */ -#define NCSI_PKT_CMD_EV 0x0c /* Enable VLAN */ -#define NCSI_PKT_CMD_DV 0x0d /* Disable VLAN */ -#define NCSI_PKT_CMD_SMA 0x0e /* Set MAC address */ -#define NCSI_PKT_CMD_EBF 0x10 /* Enable Broadcast Filter */ -#define NCSI_PKT_CMD_DBF 0x11 /* Disable Broadcast Filter */ -#define NCSI_PKT_CMD_EGMF 0x12 /* Enable Global Multicast Filter */ -#define NCSI_PKT_CMD_DGMF 0x13 /* Disable Global Multicast Filter */ -#define NCSI_PKT_CMD_SNFC 0x14 /* Set NCSI Flow Control */ -#define NCSI_PKT_CMD_GVI 0x15 /* Get Version ID */ -#define NCSI_PKT_CMD_GC 0x16 /* Get Capabilities */ -#define NCSI_PKT_CMD_GP 0x17 /* Get Parameters */ -#define NCSI_PKT_CMD_GCPS 0x18 /* Get Controller Packet Statistics */ -#define NCSI_PKT_CMD_GNS 0x19 /* Get NCSI Statistics */ -#define NCSI_PKT_CMD_GNPTS 0x1a /* Get NCSI Pass-throu Statistics */ -#define NCSI_PKT_CMD_GPS 0x1b /* Get package status */ -#define NCSI_PKT_CMD_OEM 0x50 /* OEM */ -#define NCSI_PKT_CMD_PLDM 0x51 /* PLDM request over NCSI over RBT */ -#define NCSI_PKT_CMD_GPUUID 0x52 /* Get package UUID */ - -/* NCSI packet responses */ -#define NCSI_PKT_RSP_CIS (NCSI_PKT_CMD_CIS + 0x80) -#define NCSI_PKT_RSP_SP (NCSI_PKT_CMD_SP + 0x80) -#define NCSI_PKT_RSP_DP (NCSI_PKT_CMD_DP + 0x80) -#define NCSI_PKT_RSP_EC (NCSI_PKT_CMD_EC + 0x80) -#define NCSI_PKT_RSP_DC (NCSI_PKT_CMD_DC + 0x80) -#define NCSI_PKT_RSP_RC (NCSI_PKT_CMD_RC + 0x80) -#define NCSI_PKT_RSP_ECNT (NCSI_PKT_CMD_ECNT + 0x80) -#define NCSI_PKT_RSP_DCNT (NCSI_PKT_CMD_DCNT + 0x80) -#define NCSI_PKT_RSP_AE (NCSI_PKT_CMD_AE + 0x80) -#define NCSI_PKT_RSP_SL (NCSI_PKT_CMD_SL + 0x80) -#define NCSI_PKT_RSP_GLS (NCSI_PKT_CMD_GLS + 0x80) -#define NCSI_PKT_RSP_SVF (NCSI_PKT_CMD_SVF + 0x80) -#define NCSI_PKT_RSP_EV (NCSI_PKT_CMD_EV + 0x80) -#define NCSI_PKT_RSP_DV (NCSI_PKT_CMD_DV + 0x80) -#define NCSI_PKT_RSP_SMA (NCSI_PKT_CMD_SMA + 0x80) -#define NCSI_PKT_RSP_EBF (NCSI_PKT_CMD_EBF + 0x80) -#define NCSI_PKT_RSP_DBF (NCSI_PKT_CMD_DBF + 0x80) -#define NCSI_PKT_RSP_EGMF (NCSI_PKT_CMD_EGMF + 0x80) -#define NCSI_PKT_RSP_DGMF (NCSI_PKT_CMD_DGMF + 0x80) -#define NCSI_PKT_RSP_SNFC (NCSI_PKT_CMD_SNFC + 0x80) -#define NCSI_PKT_RSP_GVI (NCSI_PKT_CMD_GVI + 0x80) -#define NCSI_PKT_RSP_GC (NCSI_PKT_CMD_GC + 0x80) -#define NCSI_PKT_RSP_GP (NCSI_PKT_CMD_GP + 0x80) -#define NCSI_PKT_RSP_GCPS (NCSI_PKT_CMD_GCPS + 0x80) -#define NCSI_PKT_RSP_GNS (NCSI_PKT_CMD_GNS + 0x80) -#define NCSI_PKT_RSP_GNPTS (NCSI_PKT_CMD_GNPTS + 0x80) -#define NCSI_PKT_RSP_GPS (NCSI_PKT_CMD_GPS + 0x80) -#define NCSI_PKT_RSP_OEM (NCSI_PKT_CMD_OEM + 0x80) -#define NCSI_PKT_RSP_PLDM (NCSI_PKT_CMD_PLDM + 0x80) -#define NCSI_PKT_RSP_GPUUID (NCSI_PKT_CMD_GPUUID + 0x80) - -/* NCSI response code/reason */ -#define NCSI_PKT_RSP_C_COMPLETED 0x0000 /* Command Completed */ -#define NCSI_PKT_RSP_C_FAILED 0x0001 /* Command Failed */ -#define NCSI_PKT_RSP_C_UNAVAILABLE 0x0002 /* Command Unavailable */ -#define NCSI_PKT_RSP_C_UNSUPPORTED 0x0003 /* Command Unsupported */ -#define NCSI_PKT_RSP_R_NO_ERROR 0x0000 /* No Error */ -#define NCSI_PKT_RSP_R_INTERFACE 0x0001 /* Interface not ready */ -#define NCSI_PKT_RSP_R_PARAM 0x0002 /* Invalid Parameter */ -#define NCSI_PKT_RSP_R_CHANNEL 0x0003 /* Channel not Ready */ -#define NCSI_PKT_RSP_R_PACKAGE 0x0004 /* Package not Ready */ -#define NCSI_PKT_RSP_R_LENGTH 0x0005 /* Invalid payload length */ -#define NCSI_PKT_RSP_R_UNKNOWN 0x7fff /* Command type unsupported */ - -/* NCSI AEN packet type */ -#define NCSI_PKT_AEN 0xFF /* AEN Packet */ -#define NCSI_PKT_AEN_LSC 0x00 /* Link status change */ -#define NCSI_PKT_AEN_CR 0x01 /* Configuration required */ -#define NCSI_PKT_AEN_HNCDSC 0x02 /* HNC driver status change */ - -#endif /* NCSI_PKT_H */ diff --git a/src/network/slirp/ncsi.c b/src/network/slirp/ncsi.c deleted file mode 100644 index f3427bd66..000000000 --- a/src/network/slirp/ncsi.c +++ /dev/null @@ -1,197 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * NC-SI (Network Controller Sideband Interface) "echo" model - * - * Copyright (C) 2016-2018 IBM Corp. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "slirp.h" - -#include "ncsi-pkt.h" - -static uint32_t ncsi_calculate_checksum(uint8_t *data, int len) -{ - uint32_t checksum = 0; - int i; - - /* - * 32-bit unsigned sum of the NC-SI packet header and NC-SI packet - * payload interpreted as a series of 16-bit unsigned integer values. - */ - for (i = 0; i < len; i += 2) { - checksum += (((uint16_t) data[i]) << 8) + data[i+1]; - } - - checksum = (~checksum + 1); - return checksum; -} - -/* Get Capabilities */ -static int ncsi_rsp_handler_gc(struct ncsi_rsp_pkt_hdr *rnh) -{ - struct ncsi_rsp_gc_pkt *rsp = (struct ncsi_rsp_gc_pkt *)rnh; - - rsp->cap = htonl(~0); - rsp->bc_cap = htonl(~0); - rsp->mc_cap = htonl(~0); - rsp->buf_cap = htonl(~0); - rsp->aen_cap = htonl(~0); - rsp->vlan_mode = 0xff; - rsp->uc_cnt = 2; - return 0; -} - -/* Get Link status */ -static int ncsi_rsp_handler_gls(struct ncsi_rsp_pkt_hdr *rnh) -{ - struct ncsi_rsp_gls_pkt *rsp = (struct ncsi_rsp_gls_pkt *)rnh; - - rsp->status = htonl(0x1); - return 0; -} - -/* Get Parameters */ -static int ncsi_rsp_handler_gp(struct ncsi_rsp_pkt_hdr *rnh) -{ - struct ncsi_rsp_gp_pkt *rsp = (struct ncsi_rsp_gp_pkt *)rnh; - - /* no MAC address filters or VLAN filters on the channel */ - rsp->mac_cnt = 0; - rsp->mac_enable = 0; - rsp->vlan_cnt = 0; - rsp->vlan_enable = 0; - - return 0; -} - -static const struct ncsi_rsp_handler { - unsigned char type; - int payload; - int (*handler)(struct ncsi_rsp_pkt_hdr *rnh); -} ncsi_rsp_handlers[] = { { NCSI_PKT_RSP_CIS, 4, NULL }, - { NCSI_PKT_RSP_SP, 4, NULL }, - { NCSI_PKT_RSP_DP, 4, NULL }, - { NCSI_PKT_RSP_EC, 4, NULL }, - { NCSI_PKT_RSP_DC, 4, NULL }, - { NCSI_PKT_RSP_RC, 4, NULL }, - { NCSI_PKT_RSP_ECNT, 4, NULL }, - { NCSI_PKT_RSP_DCNT, 4, NULL }, - { NCSI_PKT_RSP_AE, 4, NULL }, - { NCSI_PKT_RSP_SL, 4, NULL }, - { NCSI_PKT_RSP_GLS, 16, ncsi_rsp_handler_gls }, - { NCSI_PKT_RSP_SVF, 4, NULL }, - { NCSI_PKT_RSP_EV, 4, NULL }, - { NCSI_PKT_RSP_DV, 4, NULL }, - { NCSI_PKT_RSP_SMA, 4, NULL }, - { NCSI_PKT_RSP_EBF, 4, NULL }, - { NCSI_PKT_RSP_DBF, 4, NULL }, - { NCSI_PKT_RSP_EGMF, 4, NULL }, - { NCSI_PKT_RSP_DGMF, 4, NULL }, - { NCSI_PKT_RSP_SNFC, 4, NULL }, - { NCSI_PKT_RSP_GVI, 40, NULL }, - { NCSI_PKT_RSP_GC, 32, ncsi_rsp_handler_gc }, - { NCSI_PKT_RSP_GP, 40, ncsi_rsp_handler_gp }, - { NCSI_PKT_RSP_GCPS, 172, NULL }, - { NCSI_PKT_RSP_GNS, 172, NULL }, - { NCSI_PKT_RSP_GNPTS, 172, NULL }, - { NCSI_PKT_RSP_GPS, 8, NULL }, - { NCSI_PKT_RSP_OEM, 0, NULL }, - { NCSI_PKT_RSP_PLDM, 0, NULL }, - { NCSI_PKT_RSP_GPUUID, 20, NULL } }; - -/* - * packet format : ncsi header + payload + checksum - */ -#define NCSI_MAX_PAYLOAD 172 -#define NCSI_MAX_LEN (sizeof(struct ncsi_pkt_hdr) + NCSI_MAX_PAYLOAD + 4) - -void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) -{ - const struct ncsi_pkt_hdr *nh = - (const struct ncsi_pkt_hdr *)(pkt + ETH_HLEN); - uint8_t ncsi_reply[ETH_HLEN + NCSI_MAX_LEN]; - struct ethhdr *reh = (struct ethhdr *)ncsi_reply; - struct ncsi_rsp_pkt_hdr *rnh = - (struct ncsi_rsp_pkt_hdr *)(ncsi_reply + ETH_HLEN); - const struct ncsi_rsp_handler *handler = NULL; - int i; - int ncsi_rsp_len = sizeof(*nh); - uint32_t checksum; - uint32_t *pchecksum; - - if (pkt_len < ETH_HLEN + sizeof(struct ncsi_pkt_hdr)) { - return; /* packet too short */ - } - - memset(ncsi_reply, 0, sizeof(ncsi_reply)); - - memset(reh->h_dest, 0xff, ETH_ALEN); - memset(reh->h_source, 0xff, ETH_ALEN); - reh->h_proto = htons(ETH_P_NCSI); - - for (i = 0; i < G_N_ELEMENTS(ncsi_rsp_handlers); i++) { - if (ncsi_rsp_handlers[i].type == nh->type + 0x80) { - handler = &ncsi_rsp_handlers[i]; - break; - } - } - - rnh->common.mc_id = nh->mc_id; - rnh->common.revision = NCSI_PKT_REVISION; - rnh->common.id = nh->id; - rnh->common.type = nh->type + 0x80; - rnh->common.channel = nh->channel; - - if (handler) { - rnh->common.length = htons(handler->payload); - rnh->code = htons(NCSI_PKT_RSP_C_COMPLETED); - rnh->reason = htons(NCSI_PKT_RSP_R_NO_ERROR); - - if (handler->handler) { - /* TODO: handle errors */ - handler->handler(rnh); - } - ncsi_rsp_len += handler->payload; - } else { - rnh->common.length = 0; - rnh->code = htons(NCSI_PKT_RSP_C_UNAVAILABLE); - rnh->reason = htons(NCSI_PKT_RSP_R_UNKNOWN); - } - - /* Add the optional checksum at the end of the frame. */ - checksum = ncsi_calculate_checksum((uint8_t *)rnh, ncsi_rsp_len); - pchecksum = (uint32_t *)((void *)rnh + ncsi_rsp_len); - *pchecksum = htonl(checksum); - ncsi_rsp_len += 4; - - slirp_send_packet_all(slirp, ncsi_reply, ETH_HLEN + ncsi_rsp_len); -} diff --git a/src/network/slirp/ndp_table.c b/src/network/slirp/ndp_table.c deleted file mode 100644 index fdb189d59..000000000 --- a/src/network/slirp/ndp_table.c +++ /dev/null @@ -1,98 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne. - */ - -#include "slirp.h" - -void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, - uint8_t ethaddr[ETH_ALEN]) -{ - char addrstr[INET6_ADDRSTRLEN]; - NdpTable *ndp_table = &slirp->ndp_table; - int i; - char ethaddr_str[ETH_ADDRSTRLEN]; - - inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN); - - DEBUG_CALL("ndp_table_add"); - DEBUG_ARG("ip = %s", addrstr); - DEBUG_ARG("hw addr = %s", slirp_ether_ntoa(ethaddr, ethaddr_str, - sizeof(ethaddr_str))); - - if (IN6_IS_ADDR_MULTICAST(&ip_addr) || in6_zero(&ip_addr)) { - /* Do not register multicast or unspecified addresses */ - DEBUG_CALL(" abort: do not register multicast or unspecified address"); - return; - } - - /* Search for an entry */ - for (i = 0; i < NDP_TABLE_SIZE; i++) { - if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) { - DEBUG_CALL(" already in table: update the entry"); - /* Update the entry */ - memcpy(ndp_table->table[i].eth_addr, ethaddr, ETH_ALEN); - return; - } - } - - /* No entry found, create a new one */ - DEBUG_CALL(" create new entry"); - /* Save the first entry, it is the guest. */ - if (in6_zero(&ndp_table->guest_in6_addr)) { - ndp_table->guest_in6_addr = ip_addr; - } - ndp_table->table[ndp_table->next_victim].ip_addr = ip_addr; - memcpy(ndp_table->table[ndp_table->next_victim].eth_addr, ethaddr, - ETH_ALEN); - ndp_table->next_victim = (ndp_table->next_victim + 1) % NDP_TABLE_SIZE; -} - -bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr, - uint8_t out_ethaddr[ETH_ALEN]) -{ - char addrstr[INET6_ADDRSTRLEN]; - NdpTable *ndp_table = &slirp->ndp_table; - int i; - char ethaddr_str[ETH_ADDRSTRLEN]; - - inet_ntop(AF_INET6, &(ip_addr), addrstr, INET6_ADDRSTRLEN); - - DEBUG_CALL("ndp_table_search"); - DEBUG_ARG("ip = %s", addrstr); - - /* If unspecified address */ - if (in6_zero(&ip_addr)) { - /* return Ethernet broadcast address */ - memset(out_ethaddr, 0xff, ETH_ALEN); - return 1; - } - - /* Multicast address: fec0::abcd:efgh/8 -> 33:33:ab:cd:ef:gh */ - if (IN6_IS_ADDR_MULTICAST(&ip_addr)) { - out_ethaddr[0] = 0x33; - out_ethaddr[1] = 0x33; - out_ethaddr[2] = ip_addr.s6_addr[12]; - out_ethaddr[3] = ip_addr.s6_addr[13]; - out_ethaddr[4] = ip_addr.s6_addr[14]; - out_ethaddr[5] = ip_addr.s6_addr[15]; - DEBUG_ARG("multicast addr = %s", - slirp_ether_ntoa(out_ethaddr, ethaddr_str, - sizeof(ethaddr_str))); - return 1; - } - - for (i = 0; i < NDP_TABLE_SIZE; i++) { - if (in6_equal(&ndp_table->table[i].ip_addr, &ip_addr)) { - memcpy(out_ethaddr, ndp_table->table[i].eth_addr, ETH_ALEN); - DEBUG_ARG("found hw addr = %s", - slirp_ether_ntoa(out_ethaddr, ethaddr_str, - sizeof(ethaddr_str))); - return 1; - } - } - - DEBUG_CALL(" ip not found in table"); - return 0; -} diff --git a/src/network/slirp/sbuf.c b/src/network/slirp/sbuf.c deleted file mode 100644 index b35709170..000000000 --- a/src/network/slirp/sbuf.c +++ /dev/null @@ -1,168 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -static void sbappendsb(struct sbuf *sb, struct mbuf *m); - -void sbfree(struct sbuf *sb) -{ - g_free(sb->sb_data); -} - -bool sbdrop(struct sbuf *sb, size_t num) -{ - int limit = sb->sb_datalen / 2; - - g_warn_if_fail(num <= sb->sb_cc); - if (num > sb->sb_cc) - num = sb->sb_cc; - - sb->sb_cc -= num; - sb->sb_rptr += num; - if (sb->sb_rptr >= sb->sb_data + sb->sb_datalen) - sb->sb_rptr -= sb->sb_datalen; - - if (sb->sb_cc < limit && sb->sb_cc + num >= limit) { - return true; - } - - return false; -} - -void sbreserve(struct sbuf *sb, size_t size) -{ - sb->sb_wptr = sb->sb_rptr = sb->sb_data = g_realloc(sb->sb_data, size); - sb->sb_cc = 0; - sb->sb_datalen = size; -} - -/* - * Try and write() to the socket, whatever doesn't get written - * append to the buffer... for a host with a fast net connection, - * this prevents an unnecessary copy of the data - * (the socket is non-blocking, so we won't hang) - */ -void sbappend(struct socket *so, struct mbuf *m) -{ - int ret = 0; - - DEBUG_CALL("sbappend"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("m->m_len = %d", m->m_len); - - /* Shouldn't happen, but... e.g. foreign host closes connection */ - if (m->m_len <= 0) { - m_free(m); - return; - } - - /* - * If there is urgent data, call sosendoob - * if not all was sent, sowrite will take care of the rest - * (The rest of this function is just an optimisation) - */ - if (so->so_urgc) { - sbappendsb(&so->so_rcv, m); - m_free(m); - sosendoob(so); - return; - } - - /* - * We only write if there's nothing in the buffer, - * ottherwise it'll arrive out of order, and hence corrupt - */ - if (!so->so_rcv.sb_cc) - ret = slirp_send(so, m->m_data, m->m_len, 0); - - if (ret <= 0) { - /* - * Nothing was written - * It's possible that the socket has closed, but - * we don't need to check because if it has closed, - * it will be detected in the normal way by soread() - */ - sbappendsb(&so->so_rcv, m); - } else if (ret != m->m_len) { - /* - * Something was written, but not everything.. - * sbappendsb the rest - */ - m->m_len -= ret; - m->m_data += ret; - sbappendsb(&so->so_rcv, m); - } /* else */ - /* Whatever happened, we free the mbuf */ - m_free(m); -} - -/* - * Copy the data from m into sb - * The caller is responsible to make sure there's enough room - */ -static void sbappendsb(struct sbuf *sb, struct mbuf *m) -{ - int len, n, nn; - - len = m->m_len; - - if (sb->sb_wptr < sb->sb_rptr) { - n = sb->sb_rptr - sb->sb_wptr; - if (n > len) - n = len; - memcpy(sb->sb_wptr, m->m_data, n); - } else { - /* Do the right edge first */ - n = sb->sb_data + sb->sb_datalen - sb->sb_wptr; - if (n > len) - n = len; - memcpy(sb->sb_wptr, m->m_data, n); - len -= n; - if (len) { - /* Now the left edge */ - nn = sb->sb_rptr - sb->sb_data; - if (nn > len) - nn = len; - memcpy(sb->sb_data, m->m_data + n, nn); - n += nn; - } - } - - sb->sb_cc += n; - sb->sb_wptr += n; - if (sb->sb_wptr >= sb->sb_data + sb->sb_datalen) - sb->sb_wptr -= sb->sb_datalen; -} - -/* - * Copy data from sbuf to a normal, straight buffer - * Don't update the sbuf rptr, this will be - * done in sbdrop when the data is acked - */ -void sbcopy(struct sbuf *sb, size_t off, size_t len, char *to) -{ - char *from; - - g_assert(len + off <= sb->sb_cc); - - from = sb->sb_rptr + off; - if (from >= sb->sb_data + sb->sb_datalen) - from -= sb->sb_datalen; - - if (from < sb->sb_wptr) { - memcpy(to, from, len); - } else { - /* re-use off */ - off = (sb->sb_data + sb->sb_datalen) - from; - if (off > len) - off = len; - memcpy(to, from, off); - len -= off; - if (len) - memcpy(to + off, sb->sb_data, len); - } -} diff --git a/src/network/slirp/sbuf.h b/src/network/slirp/sbuf.h deleted file mode 100644 index 01886fbd0..000000000 --- a/src/network/slirp/sbuf.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef SBUF_H -#define SBUF_H - -#define sbspace(sb) ((sb)->sb_datalen - (sb)->sb_cc) - -struct sbuf { - uint32_t sb_cc; /* actual chars in buffer */ - uint32_t sb_datalen; /* Length of data */ - char *sb_wptr; /* write pointer. points to where the next - * bytes should be written in the sbuf */ - char *sb_rptr; /* read pointer. points to where the next - * byte should be read from the sbuf */ - char *sb_data; /* Actual data */ -}; - -void sbfree(struct sbuf *sb); -bool sbdrop(struct sbuf *sb, size_t len); -void sbreserve(struct sbuf *sb, size_t size); -void sbappend(struct socket *sb, struct mbuf *mb); -void sbcopy(struct sbuf *sb, size_t off, size_t len, char *p); - -#endif diff --git a/src/network/slirp/slirp.c b/src/network/slirp/slirp.c deleted file mode 100644 index 0c2a20a9b..000000000 --- a/src/network/slirp/slirp.c +++ /dev/null @@ -1,1592 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * libslirp glue - * - * Copyright (c) 2004-2008 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "slirp.h" - - -#ifndef _WIN32 -#include -#endif - -/* https://gitlab.freedesktop.org/slirp/libslirp/issues/18 */ -#if defined(__NetBSD__) && defined(if_mtu) -#undef if_mtu -#endif - -#if defined(_WIN32) - -#define INITIAL_DNS_ADDR_BUF_SIZE 32 * 1024 -#define REALLOC_RETRIES 5 - -// Broadcast site local DNS resolvers. We do not use these because they are -// highly unlikely to be valid. -// https://www.ietf.org/proceedings/52/I-D/draft-ietf-ipngwg-dns-discovery-03.txt -static const struct in6_addr SITE_LOCAL_DNS_BROADCAST_ADDRS[] = { - { - {{ - 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 - }} - }, - { - {{ - 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 - }} - }, - { - {{ - 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - }} - }, -}; - -#endif - -int slirp_debug; - -/* Define to 1 if you want KEEPALIVE timers */ -bool slirp_do_keepalive; - -/* host loopback address */ -struct in_addr loopback_addr; -/* host loopback network mask */ -unsigned long loopback_mask; - -/* emulated hosts use the MAC addr 52:55:IP:IP:IP:IP */ -static const uint8_t special_ethaddr[ETH_ALEN] = { 0x52, 0x55, 0x00, - 0x00, 0x00, 0x00 }; - -unsigned curtime; - -static struct in_addr dns_addr; -static struct in6_addr dns6_addr; -static uint32_t dns6_scope_id; -static unsigned dns_addr_time; -static unsigned dns6_addr_time; - -#define TIMEOUT_FAST 2 /* milliseconds */ -#define TIMEOUT_SLOW 499 /* milliseconds */ -/* for the aging of certain requests like DNS */ -#define TIMEOUT_DEFAULT 1000 /* milliseconds */ - -#if defined(_WIN32) - -int get_dns_addr(struct in_addr *pdns_addr) -{ - FIXED_INFO *FixedInfo = NULL; - ULONG BufLen; - DWORD ret; - IP_ADDR_STRING *pIPAddr; - struct in_addr tmp_addr; - - if (dns_addr.s_addr != 0 && (curtime - dns_addr_time) < TIMEOUT_DEFAULT) { - *pdns_addr = dns_addr; - return 0; - } - - FixedInfo = (FIXED_INFO *)GlobalAlloc(GPTR, sizeof(FIXED_INFO)); - BufLen = sizeof(FIXED_INFO); - - if (ERROR_BUFFER_OVERFLOW == GetNetworkParams(FixedInfo, &BufLen)) { - if (FixedInfo) { - GlobalFree(FixedInfo); - FixedInfo = NULL; - } - FixedInfo = GlobalAlloc(GPTR, BufLen); - } - - if ((ret = GetNetworkParams(FixedInfo, &BufLen)) != ERROR_SUCCESS) { - printf("GetNetworkParams failed. ret = %08x\n", (unsigned)ret); - if (FixedInfo) { - GlobalFree(FixedInfo); - FixedInfo = NULL; - } - return -1; - } - - pIPAddr = &(FixedInfo->DnsServerList); - inet_aton(pIPAddr->IpAddress.String, &tmp_addr); - *pdns_addr = tmp_addr; - dns_addr = tmp_addr; - dns_addr_time = curtime; - if (FixedInfo) { - GlobalFree(FixedInfo); - FixedInfo = NULL; - } - return 0; -} - -int is_site_local_dns_broadcast(struct in6_addr *address) -{ - int i; - for (i = 0; i < G_N_ELEMENTS(SITE_LOCAL_DNS_BROADCAST_ADDRS); i++) { - if (in6_equal(address, &SITE_LOCAL_DNS_BROADCAST_ADDRS[i])) { - return 1; - } - } - return 0; -} - -void print_dns_v6_address(struct in6_addr address) -{ - char address_str[INET6_ADDRSTRLEN] = ""; - if (inet_ntop(AF_INET6, &address, address_str, INET6_ADDRSTRLEN) - == NULL) { - DEBUG_ERROR("Failed to stringify IPv6 address for logging."); - return; - } - DEBUG_CALL("IPv6 DNS server found: %s", address_str); -} - -// Gets the first valid DNS resolver with an IPv6 address. -// Ignores any site local broadcast DNS servers, as these -// are on deprecated addresses and not generally expected -// to work. Further details at: -// https://www.ietf.org/proceedings/52/I-D/draft-ietf-ipngwg-dns-discovery-03.txt -int get_ipv6_dns_server(struct in6_addr *dns_server_address, uint32_t *scope_id) -{ - PIP_ADAPTER_ADDRESSES addresses = NULL; - PIP_ADAPTER_ADDRESSES address = NULL; - IP_ADAPTER_DNS_SERVER_ADDRESS *dns_server = NULL; - struct sockaddr_in6 *dns_v6_addr = NULL; - - ULONG buf_size = INITIAL_DNS_ADDR_BUF_SIZE; - DWORD res = ERROR_BUFFER_OVERFLOW; - int i; - - for (i = 0; i < REALLOC_RETRIES; i++) { - // If non null, we hit buffer overflow, free it so we can try again. - if (addresses != NULL) { - g_free(addresses); - } - - addresses = g_malloc(buf_size); - res = GetAdaptersAddresses(AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, NULL, - addresses, &buf_size); - - if (res != ERROR_BUFFER_OVERFLOW) { - break; - } - } - - if (res != NO_ERROR) { - DEBUG_ERROR("Failed to get IPv6 DNS addresses due to error %lX", res); - goto failure; - } - - address = addresses; - for (address = addresses; address != NULL; address = address->Next) { - for (dns_server = address->FirstDnsServerAddress; - dns_server != NULL; - dns_server = dns_server->Next) { - - if (dns_server->Address.lpSockaddr->sa_family != AF_INET6) { - continue; - } - - dns_v6_addr = (struct sockaddr_in6 *)dns_server->Address.lpSockaddr; - if (is_site_local_dns_broadcast(&dns_v6_addr->sin6_addr) == 0) { - print_dns_v6_address(dns_v6_addr->sin6_addr); - *dns_server_address = dns_v6_addr->sin6_addr; - *scope_id = dns_v6_addr->sin6_scope_id; - - g_free(addresses); - return 0; - } - } - } - - DEBUG_ERROR("No IPv6 DNS servers found.\n"); - -failure: - g_free(addresses); - return -1; -} - -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id) -{ - if (!in6_zero(&dns6_addr) && (curtime - dns6_addr_time) < TIMEOUT_DEFAULT) { - *pdns6_addr = dns6_addr; - *scope_id = dns6_scope_id; - return 0; - } - - if (get_ipv6_dns_server(pdns6_addr, scope_id) == 0) { - dns6_addr = *pdns6_addr; - dns6_addr_time = curtime; - dns6_scope_id = *scope_id; - return 0; - } - - return -1; -} - -static void winsock_cleanup(void) -{ - WSACleanup(); -} - -#elif defined(__APPLE__) - -#include - -static int get_dns_addr_cached(void *pdns_addr, void *cached_addr, - socklen_t addrlen, unsigned *cached_time) -{ - if (curtime - *cached_time < TIMEOUT_DEFAULT) { - memcpy(pdns_addr, cached_addr, addrlen); - return 0; - } - return 1; -} - -static int get_dns_addr_libresolv(int af, void *pdns_addr, void *cached_addr, - socklen_t addrlen, - uint32_t *scope_id, uint32_t *cached_scope_id, - unsigned *cached_time) -{ - struct __res_state state; - union res_sockaddr_union servers[NI_MAXSERV]; - int count; - int found; - void *addr; - - // we only support IPv4 and IPv4, we assume it's one or the other - assert(af == AF_INET || af == AF_INET6); - - if (res_ninit(&state) != 0) { - return -1; - } - - count = res_getservers(&state, servers, NI_MAXSERV); - found = 0; - DEBUG_MISC("IP address of your DNS(s):"); - for (int i = 0; i < count; i++) { - if (af == servers[i].sin.sin_family) { - found++; - } - if (af == AF_INET) { - addr = &servers[i].sin.sin_addr; - } else { // af == AF_INET6 - addr = &servers[i].sin6.sin6_addr; - } - - // we use the first found entry - if (found == 1) { - memcpy(pdns_addr, addr, addrlen); - memcpy(cached_addr, addr, addrlen); - if (scope_id) { - *scope_id = 0; - } - if (cached_scope_id) { - *cached_scope_id = 0; - } - *cached_time = curtime; - } - - if (found > 3) { - DEBUG_MISC(" (more)"); - break; - } else if (slirp_debug & DBG_MISC) { - char s[INET6_ADDRSTRLEN]; - const char *res = inet_ntop(af, addr, s, sizeof(s)); - if (!res) { - res = " (string conversion error)"; - } - DEBUG_MISC(" %s", res); - } - } - - res_ndestroy(&state); - if (!found) - return -1; - return 0; -} - -int get_dns_addr(struct in_addr *pdns_addr) -{ - if (dns_addr.s_addr != 0) { - int ret; - ret = get_dns_addr_cached(pdns_addr, &dns_addr, sizeof(dns_addr), - &dns_addr_time); - if (ret <= 0) { - return ret; - } - } - return get_dns_addr_libresolv(AF_INET, pdns_addr, &dns_addr, - sizeof(dns_addr), NULL, NULL, &dns_addr_time); -} - -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id) -{ - if (!in6_zero(&dns6_addr)) { - int ret; - ret = get_dns_addr_cached(pdns6_addr, &dns6_addr, sizeof(dns6_addr), - &dns6_addr_time); - if (ret == 0) { - *scope_id = dns6_scope_id; - } - if (ret <= 0) { - return ret; - } - } - return get_dns_addr_libresolv(AF_INET6, pdns6_addr, &dns6_addr, - sizeof(dns6_addr), - scope_id, &dns6_scope_id, &dns6_addr_time); -} - -#else // !defined(_WIN32) && !defined(__APPLE__) - -#if defined(__HAIKU__) -#define RESOLV_CONF_PATH "/boot/system/settings/network/resolv.conf" -#else -#define RESOLV_CONF_PATH "/etc/resolv.conf" -#endif - -static int get_dns_addr_cached(void *pdns_addr, void *cached_addr, - socklen_t addrlen, struct stat *cached_stat, - unsigned *cached_time) -{ - struct stat old_stat; - if (curtime - *cached_time < TIMEOUT_DEFAULT) { - memcpy(pdns_addr, cached_addr, addrlen); - return 0; - } - old_stat = *cached_stat; - if (stat(RESOLV_CONF_PATH, cached_stat) != 0) { - return -1; - } - if (cached_stat->st_dev == old_stat.st_dev && - cached_stat->st_ino == old_stat.st_ino && - cached_stat->st_size == old_stat.st_size && - cached_stat->st_mtime == old_stat.st_mtime) { - memcpy(pdns_addr, cached_addr, addrlen); - return 0; - } - return 1; -} - -static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr, - socklen_t addrlen, - uint32_t *scope_id, uint32_t *cached_scope_id, - unsigned *cached_time) -{ - char buff[512]; - char buff2[257]; - FILE *f; - int found = 0; - union { - struct in_addr dns_addr; - struct in6_addr dns6_addr; - } tmp_addr; - unsigned if_index; - - assert(sizeof(tmp_addr) >= addrlen); - f = fopen(RESOLV_CONF_PATH, "r"); - if (!f) - return -1; - - DEBUG_MISC("IP address of your DNS(s):"); - while (fgets(buff, 512, f) != NULL) { - if (sscanf(buff, "nameserver%*[ \t]%256s", buff2) == 1) { - char *c = strchr(buff2, '%'); - if (c) { - if_index = if_nametoindex(c + 1); - *c = '\0'; - } else { - if_index = 0; - } - - if (!inet_pton(af, buff2, &tmp_addr)) { - continue; - } - /* If it's the first one, set it to dns_addr */ - if (!found) { - memcpy(pdns_addr, &tmp_addr, addrlen); - memcpy(cached_addr, &tmp_addr, addrlen); - if (scope_id) { - *scope_id = if_index; - } - if (cached_scope_id) { - *cached_scope_id = if_index; - } - *cached_time = curtime; - } - - if (++found > 3) { - DEBUG_MISC(" (more)"); - break; - } else if (slirp_debug & DBG_MISC) { - char s[INET6_ADDRSTRLEN]; - const char *res = inet_ntop(af, &tmp_addr, s, sizeof(s)); - if (!res) { - res = " (string conversion error)"; - } - DEBUG_MISC(" %s", res); - } - } - } - fclose(f); - if (!found) - return -1; - return 0; -} - -int get_dns_addr(struct in_addr *pdns_addr) -{ - static struct stat dns_addr_stat; - - if (dns_addr.s_addr != 0) { - int ret; - ret = get_dns_addr_cached(pdns_addr, &dns_addr, sizeof(dns_addr), - &dns_addr_stat, &dns_addr_time); - if (ret <= 0) { - return ret; - } - } - return get_dns_addr_resolv_conf(AF_INET, pdns_addr, &dns_addr, - sizeof(dns_addr), - NULL, NULL, &dns_addr_time); -} - -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id) -{ - static struct stat dns6_addr_stat; - - if (!in6_zero(&dns6_addr)) { - int ret; - ret = get_dns_addr_cached(pdns6_addr, &dns6_addr, sizeof(dns6_addr), - &dns6_addr_stat, &dns6_addr_time); - if (ret == 0) { - *scope_id = dns6_scope_id; - } - if (ret <= 0) { - return ret; - } - } - return get_dns_addr_resolv_conf(AF_INET6, pdns6_addr, &dns6_addr, - sizeof(dns6_addr), - scope_id, &dns6_scope_id, &dns6_addr_time); -} - -#endif - -static void slirp_init_once(void) -{ - static int initialized; - const char *debug; -#ifdef _WIN32 - WSADATA Data; -#endif - - if (initialized) { - return; - } - initialized = 1; - -#ifdef _WIN32 - WSAStartup(MAKEWORD(2, 0), &Data); - atexit(winsock_cleanup); -#endif - - loopback_addr.s_addr = htonl(INADDR_LOOPBACK); - loopback_mask = htonl(IN_CLASSA_NET); - - debug = g_getenv("SLIRP_DEBUG"); - if (debug) { - const GDebugKey keys[] = { - { "call", DBG_CALL }, - { "misc", DBG_MISC }, - { "error", DBG_ERROR }, - { "tftp", DBG_TFTP }, - { "verbose_call", DBG_VERBOSE_CALL }, - }; - slirp_debug = g_parse_debug_string(debug, keys, G_N_ELEMENTS(keys)); - } -} - -static void ra_timer_handler_cb(void *opaque) -{ - Slirp *slirp = opaque; - - return ra_timer_handler(slirp, NULL); -} - -void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque) -{ -// g_return_if_fail(id >= 0 && id < SLIRP_TIMER_NUM); - - switch (id) { - case SLIRP_TIMER_RA: - return ra_timer_handler(slirp, cb_opaque); - default: - abort(); - } -} - -void *slirp_timer_new(Slirp *slirp, SlirpTimerId id, void *cb_opaque) -{ - g_return_val_if_fail(id >= 0 && id < SLIRP_TIMER_NUM, NULL); - - if (slirp->cfg_version >= 4 && slirp->cb->timer_new_opaque) { - return slirp->cb->timer_new_opaque(id, cb_opaque, slirp->opaque); - } - - switch (id) { - case SLIRP_TIMER_RA: - g_return_val_if_fail(cb_opaque == NULL, NULL); - return slirp->cb->timer_new(ra_timer_handler_cb, slirp, slirp->opaque); - - default: - abort(); - } -} - -Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks, void *opaque) -{ - Slirp *slirp; - - g_return_val_if_fail(cfg != NULL, NULL); - g_return_val_if_fail(cfg->version >= SLIRP_CONFIG_VERSION_MIN, NULL); - g_return_val_if_fail(cfg->version <= SLIRP_CONFIG_VERSION_MAX, NULL); - g_return_val_if_fail(cfg->if_mtu >= IF_MTU_MIN || cfg->if_mtu == 0, NULL); - g_return_val_if_fail(cfg->if_mtu <= IF_MTU_MAX, NULL); - g_return_val_if_fail(cfg->if_mru >= IF_MRU_MIN || cfg->if_mru == 0, NULL); - g_return_val_if_fail(cfg->if_mru <= IF_MRU_MAX, NULL); - g_return_val_if_fail(!cfg->bootfile || - (strlen(cfg->bootfile) < - G_SIZEOF_MEMBER(struct bootp_t, bp_file)), NULL); - - slirp = g_malloc0(sizeof(Slirp)); - - slirp_init_once(); - - slirp->cfg_version = cfg->version; - slirp->opaque = opaque; - slirp->cb = callbacks; - slirp->grand = g_rand_new(); - slirp->restricted = cfg->restricted; - - slirp->in_enabled = cfg->in_enabled; - slirp->in6_enabled = cfg->in6_enabled; - - if_init(slirp); - ip_init(slirp); - - m_init(slirp); - - slirp->vnetwork_addr = cfg->vnetwork; - slirp->vnetwork_mask = cfg->vnetmask; - slirp->vhost_addr = cfg->vhost; - slirp->vprefix_addr6 = cfg->vprefix_addr6; - slirp->vprefix_len = cfg->vprefix_len; - slirp->vhost_addr6 = cfg->vhost6; - if (cfg->vhostname) { - slirp_pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname), - cfg->vhostname); - } - slirp->tftp_prefix = g_strdup(cfg->tftp_path); - slirp->bootp_filename = g_strdup(cfg->bootfile); - slirp->vdomainname = g_strdup(cfg->vdomainname); - slirp->vdhcp_startaddr = cfg->vdhcp_start; - slirp->vnameserver_addr = cfg->vnameserver; - slirp->vnameserver_addr6 = cfg->vnameserver6; - slirp->tftp_server_name = g_strdup(cfg->tftp_server_name); - - if (cfg->vdnssearch) { - translate_dnssearch(slirp, cfg->vdnssearch); - } - slirp->if_mtu = cfg->if_mtu == 0 ? IF_MTU_DEFAULT : cfg->if_mtu; - slirp->if_mru = cfg->if_mru == 0 ? IF_MRU_DEFAULT : cfg->if_mru; - slirp->disable_host_loopback = cfg->disable_host_loopback; - slirp->enable_emu = cfg->enable_emu; - - if (cfg->version >= 2) { - slirp->outbound_addr = cfg->outbound_addr; - slirp->outbound_addr6 = cfg->outbound_addr6; - } else { - slirp->outbound_addr = NULL; - slirp->outbound_addr6 = NULL; - } - - if (cfg->version >= 3) { - slirp->disable_dns = cfg->disable_dns; - } else { - slirp->disable_dns = false; - } - - if (cfg->version >= 4) { - slirp->disable_dhcp = cfg->disable_dhcp; - } else { - slirp->disable_dhcp = false; - } - - if (slirp->cfg_version >= 4 && slirp->cb->init_completed) { - slirp->cb->init_completed(slirp, slirp->opaque); - } - - ip6_post_init(slirp); - return slirp; -} - -Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, - struct in_addr vnetmask, struct in_addr vhost, - bool in6_enabled, struct in6_addr vprefix_addr6, - uint8_t vprefix_len, struct in6_addr vhost6, - const char *vhostname, const char *tftp_server_name, - const char *tftp_path, const char *bootfile, - struct in_addr vdhcp_start, struct in_addr vnameserver, - struct in6_addr vnameserver6, const char **vdnssearch, - const char *vdomainname, const SlirpCb *callbacks, - void *opaque) -{ - SlirpConfig cfg; - memset(&cfg, 0, sizeof(cfg)); - cfg.version = 1; - cfg.restricted = restricted; - cfg.in_enabled = in_enabled; - cfg.vnetwork = vnetwork; - cfg.vnetmask = vnetmask; - cfg.vhost = vhost; - cfg.in6_enabled = in6_enabled; - cfg.vprefix_addr6 = vprefix_addr6; - cfg.vprefix_len = vprefix_len; - cfg.vhost6 = vhost6; - cfg.vhostname = vhostname; - cfg.tftp_server_name = tftp_server_name; - cfg.tftp_path = tftp_path; - cfg.bootfile = bootfile; - cfg.vdhcp_start = vdhcp_start; - cfg.vnameserver = vnameserver; - cfg.vnameserver6 = vnameserver6; - cfg.vdnssearch = vdnssearch; - cfg.vdomainname = vdomainname; - return slirp_new(&cfg, callbacks, opaque); -} - -void slirp_cleanup(Slirp *slirp) -{ - struct gfwd_list *e, *next; - - for (e = slirp->guestfwd_list; e; e = next) { - next = e->ex_next; - g_free(e->ex_exec); - g_free(e->ex_unix); - g_free(e); - } - - ip_cleanup(slirp); - ip6_cleanup(slirp); - m_cleanup(slirp); - - g_rand_free(slirp->grand); - - g_free(slirp->vdnssearch); - g_free(slirp->tftp_prefix); - g_free(slirp->bootp_filename); - g_free(slirp->vdomainname); - g_free(slirp); -} - -#define CONN_CANFSEND(so) \ - (((so)->so_state & (SS_FCANTSENDMORE | SS_ISFCONNECTED)) == SS_ISFCONNECTED) -#define CONN_CANFRCV(so) \ - (((so)->so_state & (SS_FCANTRCVMORE | SS_ISFCONNECTED)) == SS_ISFCONNECTED) - -static void slirp_update_timeout(Slirp *slirp, uint32_t *timeout) -{ - uint32_t t; - - if (*timeout <= TIMEOUT_FAST) { - return; - } - - t = MIN(1000, *timeout); - - /* If we have tcp timeout with slirp, then we will fill @timeout with - * more precise value. - */ - if (slirp->time_fasttimo) { - *timeout = TIMEOUT_FAST; - return; - } - if (slirp->do_slowtimo) { - t = MIN(TIMEOUT_SLOW, t); - } - *timeout = t; -} - -void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout, - SlirpAddPollCb add_poll, void *opaque) -{ - struct socket *so, *so_next; - - /* - * First, TCP sockets - */ - - /* - * *_slowtimo needs calling if there are IP fragments - * in the fragment queue, or there are TCP connections active - */ - slirp->do_slowtimo = ((slirp->tcb.so_next != &slirp->tcb) || - (&slirp->ipq.ip_link != slirp->ipq.ip_link.next)); - - for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so_next) { - int events = 0; - - so_next = so->so_next; - - so->pollfds_idx = -1; - - /* - * See if we need a tcp_fasttimo - */ - if (slirp->time_fasttimo == 0 && so->so_tcpcb->t_flags & TF_DELACK) { - slirp->time_fasttimo = curtime; /* Flag when want a fasttimo */ - } - - /* - * NOFDREF can include still connecting to local-host, - * newly socreated() sockets etc. Don't want to select these. - */ - if (so->so_state & SS_NOFDREF || so->s == -1) { - continue; - } - - /* - * Set for reading sockets which are accepting - */ - if (so->so_state & SS_FACCEPTCONN) { - so->pollfds_idx = add_poll( - so->s, SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); - continue; - } - - /* - * Set for writing sockets which are connecting - */ - if (so->so_state & SS_ISFCONNECTING) { - so->pollfds_idx = - add_poll(so->s, SLIRP_POLL_OUT | SLIRP_POLL_ERR, opaque); - continue; - } - - /* - * Set for writing if we are connected, can send more, and - * we have something to send - */ - if (CONN_CANFSEND(so) && so->so_rcv.sb_cc) { - events |= SLIRP_POLL_OUT | SLIRP_POLL_ERR; - } - - /* - * Set for reading (and urgent data) if we are connected, can - * receive more, and we have room for it. - * - * If sb is already half full, we will wait for the guest to consume it, - * and notify again in sbdrop() when the sb becomes less than half full. - */ - if (CONN_CANFRCV(so) && - (so->so_snd.sb_cc < (so->so_snd.sb_datalen / 2))) { - events |= SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR | - SLIRP_POLL_PRI; - } - - if (events) { - so->pollfds_idx = add_poll(so->s, events, opaque); - } - } - - /* - * UDP sockets - */ - for (so = slirp->udb.so_next; so != &slirp->udb; so = so_next) { - so_next = so->so_next; - - so->pollfds_idx = -1; - - /* - * See if it's timed out - */ - if (so->so_expire) { - if (so->so_expire <= curtime) { - udp_detach(so); - continue; - } else { - slirp->do_slowtimo = true; /* Let socket expire */ - } - } - - /* - * When UDP packets are received from over the - * link, they're sendto()'d straight away, so - * no need for setting for writing - * Limit the number of packets queued by this session - * to 4. Note that even though we try and limit this - * to 4 packets, the session could have more queued - * if the packets needed to be fragmented - * (XXX <= 4 ?) - */ - if ((so->so_state & SS_ISFCONNECTED) && so->so_queued <= 4) { - so->pollfds_idx = add_poll( - so->s, SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); - } - } - - /* - * ICMP sockets - */ - for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so_next) { - so_next = so->so_next; - - so->pollfds_idx = -1; - - /* - * See if it's timed out - */ - if (so->so_expire) { - if (so->so_expire <= curtime) { - icmp_detach(so); - continue; - } else { - slirp->do_slowtimo = true; /* Let socket expire */ - } - } - - if (so->so_state & SS_ISFCONNECTED) { - so->pollfds_idx = add_poll( - so->s, SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR, opaque); - } - } - - slirp_update_timeout(slirp, timeout); -} - -void slirp_pollfds_poll(Slirp *slirp, int select_error, - SlirpGetREventsCb get_revents, void *opaque) -{ - struct socket *so, *so_next; - int ret; - - curtime = slirp->cb->clock_get_ns(slirp->opaque) / SCALE_MS; - - /* - * See if anything has timed out - */ - if (slirp->time_fasttimo && - ((curtime - slirp->time_fasttimo) >= TIMEOUT_FAST)) { - tcp_fasttimo(slirp); - slirp->time_fasttimo = 0; - } - if (slirp->do_slowtimo && - ((curtime - slirp->last_slowtimo) >= TIMEOUT_SLOW)) { - ip_slowtimo(slirp); - tcp_slowtimo(slirp); - slirp->last_slowtimo = curtime; - } - - /* - * Check sockets - */ - if (!select_error) { - /* - * Check TCP sockets - */ - for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so_next) { - int revents; - - so_next = so->so_next; - - revents = 0; - if (so->pollfds_idx != -1) { - revents = get_revents(so->pollfds_idx, opaque); - } - - if (so->so_state & SS_NOFDREF || so->s == -1) { - continue; - } - -#ifndef __APPLE__ - /* - * Check for URG data - * This will soread as well, so no need to - * test for SLIRP_POLL_IN below if this succeeds. - * - * This is however disabled on MacOS, which apparently always - * reports data as PRI when it is the last data of the - * connection. We would then report it out of band, which the guest - * would most probably not be ready for. - */ - if (revents & SLIRP_POLL_PRI) { - ret = sorecvoob(so); - if (ret < 0) { - /* Socket error might have resulted in the socket being - * removed, do not try to do anything more with it. */ - continue; - } - } - /* - * Check sockets for reading - */ - else -#endif - if (revents & - (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR | SLIRP_POLL_PRI)) { - /* - * Check for incoming connections - */ - if (so->so_state & SS_FACCEPTCONN) { - tcp_connect(so); - continue; - } /* else */ - ret = soread(so); - - /* Output it if we read something */ - if (ret > 0) { - tcp_output(sototcpcb(so)); - } - if (ret < 0) { - /* Socket error might have resulted in the socket being - * removed, do not try to do anything more with it. */ - continue; - } - } - - /* - * Check sockets for writing - */ - if (!(so->so_state & SS_NOFDREF) && - (revents & (SLIRP_POLL_OUT | SLIRP_POLL_ERR))) { - /* - * Check for non-blocking, still-connecting sockets - */ - if (so->so_state & SS_ISFCONNECTING) { - /* Connected */ - so->so_state &= ~SS_ISFCONNECTING; - - ret = send(so->s, (const void *)&ret, 0, 0); - if (ret < 0) { - /* XXXXX Must fix, zero bytes is a NOP */ - if (errno == EAGAIN || errno == EWOULDBLOCK || - errno == EINPROGRESS || errno == ENOTCONN) { - continue; - } - - /* else failed */ - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_NOFDREF; - } - /* else so->so_state &= ~SS_ISFCONNECTING; */ - - /* - * Continue tcp_input - */ - tcp_input((struct mbuf *)NULL, sizeof(struct ip), so, - so->so_ffamily); - /* continue; */ - } else { - ret = sowrite(so); - if (ret > 0) { - /* Call tcp_output in case we need to send a window - * update to the guest, otherwise it will be stuck - * until it sends a window probe. */ - tcp_output(sototcpcb(so)); - } - } - } - } - - /* - * Now UDP sockets. - * Incoming packets are sent straight away, they're not buffered. - * Incoming UDP data isn't buffered either. - */ - for (so = slirp->udb.so_next; so != &slirp->udb; so = so_next) { - int revents; - - so_next = so->so_next; - - revents = 0; - if (so->pollfds_idx != -1) { - revents = get_revents(so->pollfds_idx, opaque); - } - - if (so->s != -1 && - (revents & (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR))) { - sorecvfrom(so); - } - } - - /* - * Check incoming ICMP relies. - */ - for (so = slirp->icmp.so_next; so != &slirp->icmp; so = so_next) { - int revents; - - so_next = so->so_next; - - revents = 0; - if (so->pollfds_idx != -1) { - revents = get_revents(so->pollfds_idx, opaque); - } - - if (so->s != -1 && - (revents & (SLIRP_POLL_IN | SLIRP_POLL_HUP | SLIRP_POLL_ERR))) { - icmp_receive(so); - } - } - } - - if_start(slirp); -} - -static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) -{ - const struct slirp_arphdr *ah = - (const struct slirp_arphdr *)(pkt + ETH_HLEN); - uint8_t arp_reply[MAX(ETH_HLEN + sizeof(struct slirp_arphdr), 64)]; - struct ethhdr *reh = (struct ethhdr *)arp_reply; - struct slirp_arphdr *rah = (struct slirp_arphdr *)(arp_reply + ETH_HLEN); - int ar_op; - struct gfwd_list *ex_ptr; - - if (!slirp->in_enabled) { - return; - } - - if (pkt_len < ETH_HLEN + sizeof(struct slirp_arphdr)) { - return; /* packet too short */ - } - - ar_op = ntohs(ah->ar_op); - switch (ar_op) { - case ARPOP_REQUEST: - if (ah->ar_tip == ah->ar_sip) { - /* Gratuitous ARP */ - arp_table_add(slirp, ah->ar_sip, ah->ar_sha); - return; - } - - if ((ah->ar_tip & slirp->vnetwork_mask.s_addr) == - slirp->vnetwork_addr.s_addr) { - if (ah->ar_tip == slirp->vnameserver_addr.s_addr || - ah->ar_tip == slirp->vhost_addr.s_addr) - goto arp_ok; - /* TODO: IPv6 */ - for (ex_ptr = slirp->guestfwd_list; ex_ptr; - ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_addr.s_addr == ah->ar_tip) - goto arp_ok; - } - return; - arp_ok: - memset(arp_reply, 0, sizeof(arp_reply)); - - arp_table_add(slirp, ah->ar_sip, ah->ar_sha); - - /* ARP request for alias/dns mac address */ - memcpy(reh->h_dest, pkt + ETH_ALEN, ETH_ALEN); - memcpy(reh->h_source, special_ethaddr, ETH_ALEN - 4); - memcpy(&reh->h_source[2], &ah->ar_tip, 4); - reh->h_proto = htons(ETH_P_ARP); - - rah->ar_hrd = htons(1); - rah->ar_pro = htons(ETH_P_IP); - rah->ar_hln = ETH_ALEN; - rah->ar_pln = 4; - rah->ar_op = htons(ARPOP_REPLY); - memcpy(rah->ar_sha, reh->h_source, ETH_ALEN); - rah->ar_sip = ah->ar_tip; - memcpy(rah->ar_tha, ah->ar_sha, ETH_ALEN); - rah->ar_tip = ah->ar_sip; - slirp_send_packet_all(slirp, arp_reply, sizeof(arp_reply)); - } - break; - case ARPOP_REPLY: - arp_table_add(slirp, ah->ar_sip, ah->ar_sha); - break; - default: - break; - } -} - -void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len) -{ - struct mbuf *m; - int proto; - - if (pkt_len < ETH_HLEN) - return; - - proto = (((uint16_t)pkt[12]) << 8) + pkt[13]; - switch (proto) { - case ETH_P_ARP: - arp_input(slirp, pkt, pkt_len); - break; - case ETH_P_IP: - case ETH_P_IPV6: - m = m_get(slirp); - if (!m) - return; - /* Note: we add 2 to align the IP header on 4 bytes, - * and add the margin for the tcpiphdr overhead */ - if (M_FREEROOM(m) < pkt_len + TCPIPHDR_DELTA + 2) { - m_inc(m, pkt_len + TCPIPHDR_DELTA + 2); - } - m->m_len = pkt_len + TCPIPHDR_DELTA + 2; - memcpy(m->m_data + TCPIPHDR_DELTA + 2, pkt, pkt_len); - - m->m_data += TCPIPHDR_DELTA + 2 + ETH_HLEN; - m->m_len -= TCPIPHDR_DELTA + 2 + ETH_HLEN; - - if (proto == ETH_P_IP) { - ip_input(m); - } else if (proto == ETH_P_IPV6) { - ip6_input(m); - } - break; - - case ETH_P_NCSI: - ncsi_input(slirp, pkt, pkt_len); - break; - - default: - break; - } -} - -/* Prepare the IPv4 packet to be sent to the ethernet device. Returns 1 if no - * packet should be sent, 0 if the packet must be re-queued, 2 if the packet - * is ready to go. - */ -static int if_encap4(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, - uint8_t ethaddr[ETH_ALEN]) -{ - const struct ip *iph = (const struct ip *)ifm->m_data; - - if (!arp_table_search(slirp, iph->ip_dst.s_addr, ethaddr)) { - uint8_t arp_req[ETH_HLEN + sizeof(struct slirp_arphdr)]; - struct ethhdr *reh = (struct ethhdr *)arp_req; - struct slirp_arphdr *rah = (struct slirp_arphdr *)(arp_req + ETH_HLEN); - - if (!ifm->resolution_requested) { - /* If the client addr is not known, send an ARP request */ - memset(reh->h_dest, 0xff, ETH_ALEN); - memcpy(reh->h_source, special_ethaddr, ETH_ALEN - 4); - memcpy(&reh->h_source[2], &slirp->vhost_addr, 4); - reh->h_proto = htons(ETH_P_ARP); - rah->ar_hrd = htons(1); - rah->ar_pro = htons(ETH_P_IP); - rah->ar_hln = ETH_ALEN; - rah->ar_pln = 4; - rah->ar_op = htons(ARPOP_REQUEST); - - /* source hw addr */ - memcpy(rah->ar_sha, special_ethaddr, ETH_ALEN - 4); - memcpy(&rah->ar_sha[2], &slirp->vhost_addr, 4); - - /* source IP */ - rah->ar_sip = slirp->vhost_addr.s_addr; - - /* target hw addr (none) */ - memset(rah->ar_tha, 0, ETH_ALEN); - - /* target IP */ - rah->ar_tip = iph->ip_dst.s_addr; - slirp->client_ipaddr = iph->ip_dst; - slirp_send_packet_all(slirp, arp_req, sizeof(arp_req)); - ifm->resolution_requested = true; - - /* Expire request and drop outgoing packet after 1 second */ - ifm->expiration_date = - slirp->cb->clock_get_ns(slirp->opaque) + 1000000000ULL; - } - return 0; - } else { - memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 4); - /* XXX: not correct */ - memcpy(&eh->h_source[2], &slirp->vhost_addr, 4); - eh->h_proto = htons(ETH_P_IP); - - /* Send this */ - return 2; - } -} - -/* Prepare the IPv6 packet to be sent to the ethernet device. Returns 1 if no - * packet should be sent, 0 if the packet must be re-queued, 2 if the packet - * is ready to go. - */ -static int if_encap6(Slirp *slirp, struct mbuf *ifm, struct ethhdr *eh, - uint8_t ethaddr[ETH_ALEN]) -{ - const struct ip6 *ip6h = mtod(ifm, const struct ip6 *); - if (!ndp_table_search(slirp, ip6h->ip_dst, ethaddr)) { - if (!ifm->resolution_requested) { - ndp_send_ns(slirp, ip6h->ip_dst); - ifm->resolution_requested = true; - ifm->expiration_date = - slirp->cb->clock_get_ns(slirp->opaque) + 1000000000ULL; - } - return 0; - } else { - eh->h_proto = htons(ETH_P_IPV6); - in6_compute_ethaddr(ip6h->ip_src, eh->h_source); - - /* Send this */ - return 2; - } -} - -/* Output the IP packet to the ethernet device. Returns 0 if the packet must be - * re-queued. - */ -int if_encap(Slirp *slirp, struct mbuf *ifm) -{ - uint8_t buf[IF_MTU_MAX + 100]; - struct ethhdr *eh = (struct ethhdr *)buf; - uint8_t ethaddr[ETH_ALEN]; - const struct ip *iph = (const struct ip *)ifm->m_data; - int ret; -// char ethaddr_str[ETH_ADDRSTRLEN]; - - if (ifm->m_len + ETH_HLEN > sizeof(buf)) { - return 1; - } - - switch (iph->ip_v) { - case IPVERSION: - ret = if_encap4(slirp, ifm, eh, ethaddr); - if (ret < 2) { - return ret; - } - break; - - case IP6VERSION: - ret = if_encap6(slirp, ifm, eh, ethaddr); - if (ret < 2) { - return ret; - } - break; - - default: - g_assert_not_reached(); - } - - memcpy(eh->h_dest, ethaddr, ETH_ALEN); -/* - DEBUG_ARG("src = %s", slirp_ether_ntoa(eh->h_source, ethaddr_str, - sizeof(ethaddr_str))); - DEBUG_ARG("dst = %s", slirp_ether_ntoa(eh->h_dest, ethaddr_str, - sizeof(ethaddr_str))); -*/ - memcpy(buf + sizeof(struct ethhdr), ifm->m_data, ifm->m_len); - slirp_send_packet_all(slirp, buf, ifm->m_len + ETH_HLEN); - return 1; -} - -/* Drop host forwarding rule, return 0 if found. */ -int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, - int host_port) -{ - struct socket *so; - struct socket *head = (is_udp ? &slirp->udb : &slirp->tcb); - struct sockaddr_in addr; - int port = htons(host_port); - socklen_t addr_len; - - for (so = head->so_next; so != head; so = so->so_next) { - addr_len = sizeof(addr); - if ((so->so_state & SS_HOSTFWD) && - getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 && - addr_len == sizeof(addr) && - addr.sin_family == AF_INET && - addr.sin_addr.s_addr == host_addr.s_addr && - addr.sin_port == port) { - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sofree(so); - return 0; - } - } - - return -1; -} - -int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, - int host_port, struct in_addr guest_addr, int guest_port) -{ - if (!guest_addr.s_addr) { - guest_addr = slirp->vdhcp_startaddr; - } - if (is_udp) { - if (!udp_listen(slirp, host_addr.s_addr, htons(host_port), - guest_addr.s_addr, htons(guest_port), SS_HOSTFWD)) - return -1; - } else { - if (!tcp_listen(slirp, host_addr.s_addr, htons(host_port), - guest_addr.s_addr, htons(guest_port), SS_HOSTFWD)) - return -1; - } - return 0; -} - -int slirp_remove_hostxfwd(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - int flags) -{ - struct socket *so; - struct socket *head = (flags & SLIRP_HOSTFWD_UDP ? &slirp->udb : &slirp->tcb); - struct sockaddr_storage addr; - socklen_t addr_len; - - for (so = head->so_next; so != head; so = so->so_next) { - addr_len = sizeof(addr); - if ((so->so_state & SS_HOSTFWD) && - getsockname(so->s, (struct sockaddr *)&addr, &addr_len) == 0 && - sockaddr_equal(&addr, (const struct sockaddr_storage *) haddr)) { - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sofree(so); - return 0; - } - } - - return -1; -} - -int slirp_add_hostxfwd(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *gaddr, socklen_t gaddrlen, - int flags) -{ - struct sockaddr_in gdhcp_addr; - int fwd_flags = SS_HOSTFWD; - - if (flags & SLIRP_HOSTFWD_V6ONLY) - fwd_flags |= SS_HOSTFWD_V6ONLY; - - if (gaddr->sa_family == AF_INET) { - const struct sockaddr_in *gaddr_in = (const struct sockaddr_in *) gaddr; - - if (gaddrlen < sizeof(struct sockaddr_in)) { - errno = EINVAL; - return -1; - } - - if (!gaddr_in->sin_addr.s_addr) { - gdhcp_addr = *gaddr_in; - gdhcp_addr.sin_addr = slirp->vdhcp_startaddr; - gaddr = (struct sockaddr *) &gdhcp_addr; - gaddrlen = sizeof(gdhcp_addr); - } - } else { - if (gaddrlen < sizeof(struct sockaddr_in6)) { - errno = EINVAL; - return -1; - } - - /* - * Libslirp currently only provides a stateless DHCPv6 server, thus - * we can't translate "addr-any" to the guest here. Instead, we defer - * performing the translation to when it's needed. See - * soassign_guest_addr_if_needed(). - */ - } - - if (flags & SLIRP_HOSTFWD_UDP) { - if (!udpx_listen(slirp, haddr, haddrlen, - gaddr, gaddrlen, - fwd_flags)) - return -1; - } else { - if (!tcpx_listen(slirp, haddr, haddrlen, - gaddr, gaddrlen, - fwd_flags)) - return -1; - } - return 0; -} - -/* TODO: IPv6 */ -static bool check_guestfwd(Slirp *slirp, struct in_addr *guest_addr, - int guest_port) -{ - struct gfwd_list *tmp_ptr; - - if (!guest_addr->s_addr) { - guest_addr->s_addr = slirp->vnetwork_addr.s_addr | - (htonl(0x0204) & ~slirp->vnetwork_mask.s_addr); - } - if ((guest_addr->s_addr & slirp->vnetwork_mask.s_addr) != - slirp->vnetwork_addr.s_addr || - guest_addr->s_addr == slirp->vhost_addr.s_addr || - guest_addr->s_addr == slirp->vnameserver_addr.s_addr) { - return false; - } - - /* check if the port is "bound" */ - for (tmp_ptr = slirp->guestfwd_list; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) { - if (guest_port == tmp_ptr->ex_fport && - guest_addr->s_addr == tmp_ptr->ex_addr.s_addr) - return false; - } - - return true; -} - -int slirp_add_exec(Slirp *slirp, const char *cmdline, - struct in_addr *guest_addr, int guest_port) -{ - if (!check_guestfwd(slirp, guest_addr, guest_port)) { - return -1; - } - - add_exec(&slirp->guestfwd_list, cmdline, *guest_addr, htons(guest_port)); - return 0; -} - -int slirp_add_unix(Slirp *slirp, const char *unixsock, - struct in_addr *guest_addr, int guest_port) -{ -#ifdef G_OS_UNIX - if (!check_guestfwd(slirp, guest_addr, guest_port)) { - return -1; - } - - add_unix(&slirp->guestfwd_list, unixsock, *guest_addr, htons(guest_port)); - return 0; -#else - g_warn_if_reached(); - return -1; -#endif -} - -int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque, - struct in_addr *guest_addr, int guest_port) -{ - if (!check_guestfwd(slirp, guest_addr, guest_port)) { - return -1; - } - - add_guestfwd(&slirp->guestfwd_list, write_cb, opaque, *guest_addr, - htons(guest_port)); - return 0; -} - -int slirp_remove_guestfwd(Slirp *slirp, struct in_addr guest_addr, - int guest_port) -{ - return remove_guestfwd(&slirp->guestfwd_list, guest_addr, - htons(guest_port)); -} - -ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags) -{ - if (so->s == -1 && so->guestfwd) { - /* XXX this blocks entire thread. Rewrite to use - * qemu_chr_fe_write and background I/O callbacks */ - so->guestfwd->write_cb(buf, len, so->guestfwd->opaque); - return len; - } - - if (so->s == -1) { - /* - * This should in theory not happen but it is hard to be - * sure because some code paths will end up with so->s == -1 - * on a failure but don't dispose of the struct socket. - * Check specifically, so we don't pass -1 to send(). - */ - errno = EBADF; - return -1; - } - - return send(so->s, buf, len, flags); -} - -struct socket *slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, - int guest_port) -{ - struct socket *so; - - /* TODO: IPv6 */ - for (so = slirp->tcb.so_next; so != &slirp->tcb; so = so->so_next) { - if (so->so_faddr.s_addr == guest_addr.s_addr && - htons(so->so_fport) == guest_port) { - return so; - } - } - return NULL; -} - -size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr, - int guest_port) -{ - struct iovec iov[2]; - struct socket *so; - - so = slirp_find_ctl_socket(slirp, guest_addr, guest_port); - - if (!so || so->so_state & SS_NOFDREF) { - return 0; - } - - if (!CONN_CANFRCV(so) || so->so_snd.sb_cc >= (so->so_snd.sb_datalen / 2)) { - /* If the sb is already half full, we will wait for the guest to consume it, - * and notify again in sbdrop() when the sb becomes less than half full. */ - return 0; - } - - return sopreprbuf(so, iov, NULL); -} - -void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port, - const uint8_t *buf, int size) -{ - int ret; - struct socket *so = slirp_find_ctl_socket(slirp, guest_addr, guest_port); - - if (!so) - return; - - ret = soreadbuf(so, (const char *)buf, size); - - if (ret > 0) - tcp_output(sototcpcb(so)); -} - -void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len) -{ - ssize_t ret = slirp->cb->send_packet(buf, len, slirp->opaque); - - if (ret < 0) { - g_critical("Failed to send packet, ret: %ld", (long)ret); - } else if (ret < len) { - DEBUG_ERROR("send_packet() didn't send all data: %ld < %lu", (long)ret, - (unsigned long)len); - } -} diff --git a/src/network/slirp/slirp.h b/src/network/slirp/slirp.h deleted file mode 100644 index e50c2ffe4..000000000 --- a/src/network/slirp/slirp.h +++ /dev/null @@ -1,293 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#ifndef SLIRP_H -#define SLIRP_H - -#ifdef _WIN32 - -/* as defined in sdkddkver.h */ -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0600 /* Windows Vista */ -#endif -/* reduces the number of implicitly included headers */ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include -#include -#include -#include -#include - -#else -#define O_BINARY 0 -#endif - -#ifndef _WIN32 -#include -#include -#include -#include -#include -#endif - -#ifdef __APPLE__ -#include -#endif - -#include "debug.h" -#include "util.h" - -#include "libslirp.h" -#include "ip.h" -#include "ip6.h" -#include "tcp.h" -#include "tcp_timer.h" -#include "tcp_var.h" -#include "tcpip.h" -#include "udp.h" -#include "ip_icmp.h" -#include "ip6_icmp.h" -#include "mbuf.h" -#include "sbuf.h" -#include "socket.h" -#include "if.h" -#include "main.h" -#include "misc.h" - -#include "bootp.h" -#include "tftp.h" - -#define ARPOP_REQUEST 1 /* ARP request */ -#define ARPOP_REPLY 2 /* ARP reply */ - -struct ethhdr { - unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ - unsigned char h_source[ETH_ALEN]; /* source ether addr */ - unsigned short h_proto; /* packet type ID field */ -}; - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct slirp_arphdr { - unsigned short ar_hrd; /* format of hardware address */ - unsigned short ar_pro; /* format of protocol address */ - unsigned char ar_hln; /* length of hardware address */ - unsigned char ar_pln; /* length of protocol address */ - unsigned short ar_op; /* ARP opcode (command) */ - - /* - * Ethernet looks like this : This bit is variable sized however... - */ - uint8_t ar_sha[ETH_ALEN]; /* sender hardware address */ - uint32_t ar_sip; /* sender IP address */ - uint8_t ar_tha[ETH_ALEN]; /* target hardware address */ - uint32_t ar_tip; /* target IP address */ -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#define ARP_TABLE_SIZE 16 - -typedef struct ArpTable { - struct slirp_arphdr table[ARP_TABLE_SIZE]; - int next_victim; -} ArpTable; - -void arp_table_add(Slirp *slirp, uint32_t ip_addr, - const uint8_t ethaddr[ETH_ALEN]); - -bool arp_table_search(Slirp *slirp, uint32_t ip_addr, - uint8_t out_ethaddr[ETH_ALEN]); - -struct ndpentry { - uint8_t eth_addr[ETH_ALEN]; /* sender hardware address */ - struct in6_addr ip_addr; /* sender IP address */ -}; - -#define NDP_TABLE_SIZE 16 - -typedef struct NdpTable { - struct ndpentry table[NDP_TABLE_SIZE]; - /* - * The table is a cache with old entries overwritten when the table fills. - * Preserve the first entry: it is the guest, which is needed for lazy - * hostfwd guest address assignment. - */ - struct in6_addr guest_in6_addr; - int next_victim; -} NdpTable; - -void ndp_table_add(Slirp *slirp, struct in6_addr ip_addr, - uint8_t ethaddr[ETH_ALEN]); -bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr, - uint8_t out_ethaddr[ETH_ALEN]); - -struct Slirp { - int cfg_version; - - unsigned time_fasttimo; - unsigned last_slowtimo; - bool do_slowtimo; - - bool in_enabled, in6_enabled; - - /* virtual network configuration */ - struct in_addr vnetwork_addr; - struct in_addr vnetwork_mask; - struct in_addr vhost_addr; - struct in6_addr vprefix_addr6; - uint8_t vprefix_len; - struct in6_addr vhost_addr6; - bool disable_dhcp; /* slirp will not reply to any DHCP requests */ - struct in_addr vdhcp_startaddr; - struct in_addr vnameserver_addr; - struct in6_addr vnameserver_addr6; - - struct in_addr client_ipaddr; - char client_hostname[33]; - - int restricted; - struct gfwd_list *guestfwd_list; - - int if_mtu; - int if_mru; - - bool disable_host_loopback; - - /* mbuf states */ - struct slirp_quehead m_freelist; - struct slirp_quehead m_usedlist; - int mbuf_alloced; - - /* if states */ - struct slirp_quehead if_fastq; /* fast queue (for interactive data) */ - struct slirp_quehead if_batchq; /* queue for non-interactive data */ - bool if_start_busy; /* avoid if_start recursion */ - - /* ip states */ - struct ipq ipq; /* ip reass. queue */ - uint16_t ip_id; /* ip packet ctr, for ids */ - - /* bootp/dhcp states */ - BOOTPClient bootp_clients[NB_BOOTP_CLIENTS]; - char *bootp_filename; - size_t vdnssearch_len; - uint8_t *vdnssearch; - char *vdomainname; - - /* tcp states */ - struct socket tcb; - struct socket *tcp_last_so; - tcp_seq tcp_iss; /* tcp initial send seq # */ - uint32_t tcp_now; /* for RFC 1323 timestamps */ - - /* udp states */ - struct socket udb; - struct socket *udp_last_so; - - /* icmp states */ - struct socket icmp; - struct socket *icmp_last_so; - - /* tftp states */ - char *tftp_prefix; - struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX]; - char *tftp_server_name; - - ArpTable arp_table; - NdpTable ndp_table; - - GRand *grand; - void *ra_timer; - - bool enable_emu; - - const SlirpCb *cb; - void *opaque; - - struct sockaddr_in *outbound_addr; - struct sockaddr_in6 *outbound_addr6; - bool disable_dns; /* slirp will not redirect/serve any DNS packet */ -}; - -void if_start(Slirp *); - -int get_dns_addr(struct in_addr *pdns_addr); -int get_dns6_addr(struct in6_addr *pdns6_addr, uint32_t *scope_id); - -/* ncsi.c */ -void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); - -#ifndef _WIN32 -#include -#endif - - -extern bool slirp_do_keepalive; - -#define TCP_MAXIDLE (TCPTV_KEEPCNT * TCPTV_KEEPINTVL) - -/* dnssearch.c */ -int translate_dnssearch(Slirp *s, const char **names); - -/* cksum.c */ -int cksum(struct mbuf *m, int len); -int ip6_cksum(struct mbuf *m); - -/* if.c */ -void if_init(Slirp *); -void if_output(struct socket *, struct mbuf *); - -/* ip_input.c */ -void ip_init(Slirp *); -void ip_cleanup(Slirp *); -void ip_input(struct mbuf *); -void ip_slowtimo(Slirp *); -void ip_stripoptions(register struct mbuf *, struct mbuf *); - -/* ip_output.c */ -int ip_output(struct socket *, struct mbuf *); - -/* ip6_input.c */ -void ip6_post_init(Slirp *); -void ip6_cleanup(Slirp *); -void ip6_input(struct mbuf *); - -/* ip6_output */ -int ip6_output(struct socket *, struct mbuf *, int fast); - -/* tcp_input.c */ -void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af); -int tcp_mss(register struct tcpcb *, unsigned); - -/* tcp_output.c */ -int tcp_output(register struct tcpcb *); -void tcp_setpersist(register struct tcpcb *); - -/* tcp_subr.c */ -void tcp_init(Slirp *); -void tcp_cleanup(Slirp *); -void tcp_template(struct tcpcb *); -void tcp_respond(struct tcpcb *, register struct tcpiphdr *, - register struct mbuf *, tcp_seq, tcp_seq, int, unsigned short); -struct tcpcb *tcp_newtcpcb(struct socket *); -struct tcpcb *tcp_close(register struct tcpcb *); -void tcp_sockclosed(struct tcpcb *); -int tcp_fconnect(struct socket *, unsigned short af); -void tcp_connect(struct socket *); -void tcp_attach(struct socket *); -uint8_t tcp_tos(struct socket *); -int tcp_emu(struct socket *, struct mbuf *); -int tcp_ctl(struct socket *); -struct tcpcb *tcp_drop(struct tcpcb *tp, int err); - -struct socket *slirp_find_ctl_socket(Slirp *slirp, struct in_addr guest_addr, - int guest_port); - -void slirp_send_packet_all(Slirp *slirp, const void *buf, size_t len); -void *slirp_timer_new(Slirp *slirp, SlirpTimerId id, void *cb_opaque); - -#endif diff --git a/src/network/slirp/socket.c b/src/network/slirp/socket.c deleted file mode 100644 index 22144ffb8..000000000 --- a/src/network/slirp/socket.c +++ /dev/null @@ -1,1233 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" -#include "ip_icmp.h" -#ifdef __sun__ -#include -#endif -#ifdef __linux__ -#include -#endif - -static void sofcantrcvmore(struct socket *so); -static void sofcantsendmore(struct socket *so); - -struct socket *solookup(struct socket **last, struct socket *head, - struct sockaddr_storage *lhost, - struct sockaddr_storage *fhost) -{ - struct socket *so = *last; - - /* Optimisation */ - if (so != head && sockaddr_equal(&(so->lhost.ss), lhost) && - (!fhost || sockaddr_equal(&so->fhost.ss, fhost))) { - return so; - } - - for (so = head->so_next; so != head; so = so->so_next) { - if (sockaddr_equal(&(so->lhost.ss), lhost) && - (!fhost || sockaddr_equal(&so->fhost.ss, fhost))) { - *last = so; - return so; - } - } - - return (struct socket *)NULL; -} - -/* - * Create a new socket, initialise the fields - * It is the responsibility of the caller to - * slirp_insque() it into the correct linked-list - */ -struct socket *socreate(Slirp *slirp, int type) -{ - struct socket *so = g_new(struct socket, 1); - - memset(so, 0, sizeof(struct socket)); - so->so_type = type; - so->so_state = SS_NOFDREF; - so->s = -1; - so->s_aux = -1; - so->slirp = slirp; - so->pollfds_idx = -1; - - return so; -} - -/* - * Remove references to so from the given message queue. - */ -static void soqfree(struct socket *so, struct slirp_quehead *qh) -{ - struct mbuf *ifq; - - for (ifq = (struct mbuf *)qh->qh_link; (struct slirp_quehead *)ifq != qh; - ifq = ifq->ifq_next) { - if (ifq->ifq_so == so) { - struct mbuf *ifm; - ifq->ifq_so = NULL; - for (ifm = ifq->ifs_next; ifm != ifq; ifm = ifm->ifs_next) { - ifm->ifq_so = NULL; - } - } - } -} - -/* - * slirp_remque and free a socket, clobber cache - */ -void sofree(struct socket *so) -{ - Slirp *slirp = so->slirp; - - if (so->s_aux != -1) { - closesocket(so->s_aux); - } - - soqfree(so, &slirp->if_fastq); - soqfree(so, &slirp->if_batchq); - - if (so == slirp->tcp_last_so) { - slirp->tcp_last_so = &slirp->tcb; - } else if (so == slirp->udp_last_so) { - slirp->udp_last_so = &slirp->udb; - } else if (so == slirp->icmp_last_so) { - slirp->icmp_last_so = &slirp->icmp; - } - m_free(so->so_m); - - if (so->so_next && so->so_prev) - slirp_remque(so); /* crashes if so is not in a queue */ - - if (so->so_tcpcb) { - g_free(so->so_tcpcb); - } - g_free(so); -} - -size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np) -{ - int n, lss, total; - struct sbuf *sb = &so->so_snd; - int len = sb->sb_datalen - sb->sb_cc; - int mss = so->so_tcpcb->t_maxseg; - - DEBUG_CALL("sopreprbuf"); - DEBUG_ARG("so = %p", so); - - if (len <= 0) - return 0; - - iov[0].iov_base = sb->sb_wptr; - iov[1].iov_base = NULL; - iov[1].iov_len = 0; - if (sb->sb_wptr < sb->sb_rptr) { - iov[0].iov_len = sb->sb_rptr - sb->sb_wptr; - /* Should never succeed, but... */ - if (iov[0].iov_len > len) - iov[0].iov_len = len; - if (iov[0].iov_len > mss) - iov[0].iov_len -= iov[0].iov_len % mss; - n = 1; - } else { - iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr; - /* Should never succeed, but... */ - if (iov[0].iov_len > len) - iov[0].iov_len = len; - len -= iov[0].iov_len; - if (len) { - iov[1].iov_base = sb->sb_data; - iov[1].iov_len = sb->sb_rptr - sb->sb_data; - if (iov[1].iov_len > len) - iov[1].iov_len = len; - total = iov[0].iov_len + iov[1].iov_len; - if (total > mss) { - lss = total % mss; - if (iov[1].iov_len > lss) { - iov[1].iov_len -= lss; - n = 2; - } else { - lss -= iov[1].iov_len; - iov[0].iov_len -= lss; - n = 1; - } - } else - n = 2; - } else { - if (iov[0].iov_len > mss) - iov[0].iov_len -= iov[0].iov_len % mss; - n = 1; - } - } - if (np) - *np = n; - - return iov[0].iov_len + (n - 1) * iov[1].iov_len; -} - -/* - * Read from so's socket into sb_snd, updating all relevant sbuf fields - * NOTE: This will only be called if it is select()ed for reading, so - * a read() of 0 (or less) means it's disconnected - */ -int soread(struct socket *so) -{ - int n = 0, nn; - size_t buf_len; - struct sbuf *sb = &so->so_snd; - struct iovec iov[2] = {{0, 0}, {0, 0}}; - - DEBUG_CALL("soread"); - DEBUG_ARG("so = %p", so); - - /* - * No need to check if there's enough room to read. - * soread wouldn't have been called if there weren't - */ - buf_len = sopreprbuf(so, iov, &n); - assert(buf_len != 0); - - nn = recv(so->s, iov[0].iov_base, iov[0].iov_len, 0); - if (nn <= 0) { - if (nn < 0 && (errno == EINTR || errno == EAGAIN)) - return 0; - else { - int err; - socklen_t elen = sizeof err; - struct sockaddr_storage addr; - struct sockaddr *paddr = (struct sockaddr *)&addr; - socklen_t alen = sizeof addr; - - err = errno; - if (nn == 0) { - int shutdown_wr = so->so_state & SS_FCANTSENDMORE; - - if (!shutdown_wr && getpeername(so->s, paddr, &alen) < 0) { - err = errno; - } else { - getsockopt(so->s, SOL_SOCKET, SO_ERROR, &err, &elen); - } - } - - DEBUG_MISC(" --- soread() disconnected, nn = %d, errno = %d-%s", nn, - errno, strerror(errno)); - sofcantrcvmore(so); - - if (err == ECONNABORTED || err == ECONNRESET || err == ECONNREFUSED || - err == ENOTCONN || err == EPIPE) { - tcp_drop(sototcpcb(so), err); - } else { - tcp_sockclosed(sototcpcb(so)); - } - return -1; - } - } - - /* - * If there was no error, try and read the second time round - * We read again if n = 2 (ie, there's another part of the buffer) - * and we read as much as we could in the first read - * We don't test for <= 0 this time, because there legitimately - * might not be any more data (since the socket is non-blocking), - * a close will be detected on next iteration. - * A return of -1 won't (shouldn't) happen, since it didn't happen above - */ - if (n == 2 && nn == iov[0].iov_len) { - int ret; - ret = recv(so->s, iov[1].iov_base, iov[1].iov_len, 0); - if (ret > 0) - nn += ret; - } - - DEBUG_MISC(" ... read nn = %d bytes", nn); - - /* Update fields */ - sb->sb_cc += nn; - sb->sb_wptr += nn; - if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen)) - sb->sb_wptr -= sb->sb_datalen; - return nn; -} - -int soreadbuf(struct socket *so, const char *buf, int size) -{ - int n, nn, copy = size; - struct sbuf *sb = &so->so_snd; - struct iovec iov[2] = {{0, 0}, {0, 0}}; - - DEBUG_CALL("soreadbuf"); - DEBUG_ARG("so = %p", so); - - /* - * No need to check if there's enough room to read. - * soread wouldn't have been called if there weren't - */ - assert(size > 0); - if (sopreprbuf(so, iov, &n) < size) - goto err; - - nn = MIN(iov[0].iov_len, copy); - memcpy(iov[0].iov_base, buf, nn); - - copy -= nn; - buf += nn; - - if (copy == 0) - goto done; - - memcpy(iov[1].iov_base, buf, copy); - -done: - /* Update fields */ - sb->sb_cc += size; - sb->sb_wptr += size; - if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen)) - sb->sb_wptr -= sb->sb_datalen; - return size; -err: - - sofcantrcvmore(so); - tcp_sockclosed(sototcpcb(so)); - g_critical("soreadbuf buffer too small"); - return -1; -} - -/* - * Get urgent data - * - * When the socket is created, we set it SO_OOBINLINE, - * so when OOB data arrives, we soread() it and everything - * in the send buffer is sent as urgent data - */ -int sorecvoob(struct socket *so) -{ - struct tcpcb *tp = sototcpcb(so); - int ret; - - DEBUG_CALL("sorecvoob"); - DEBUG_ARG("so = %p", so); - - /* - * We take a guess at how much urgent data has arrived. - * In most situations, when urgent data arrives, the next - * read() should get all the urgent data. This guess will - * be wrong however if more data arrives just after the - * urgent data, or the read() doesn't return all the - * urgent data. - */ - ret = soread(so); - if (ret > 0) { - tp->snd_up = tp->snd_una + so->so_snd.sb_cc; - tp->t_force = 1; - tcp_output(tp); - tp->t_force = 0; - } - - return ret; -} - -/* - * Send urgent data - * There's a lot duplicated code here, but... - */ -int sosendoob(struct socket *so) -{ - struct sbuf *sb = &so->so_rcv; - char buff[2048]; /* XXX Shouldn't be sending more oob data than this */ - - int n; - - DEBUG_CALL("sosendoob"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("sb->sb_cc = %d", sb->sb_cc); - - if (so->so_urgc > sizeof(buff)) - so->so_urgc = sizeof(buff); /* XXXX */ - - if (sb->sb_rptr < sb->sb_wptr) { - /* We can send it directly */ - n = slirp_send(so, sb->sb_rptr, so->so_urgc, - (MSG_OOB)); /* |MSG_DONTWAIT)); */ - } else { - /* - * Since there's no sendv or sendtov like writev, - * we must copy all data to a linear buffer then - * send it all - */ - uint32_t urgc = so->so_urgc; /* Amount of room left in buff */ - int len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; - if (len > urgc) { - len = urgc; - } - memcpy(buff, sb->sb_rptr, len); - urgc -= len; - if (urgc) { - /* We still have some room for the rest */ - n = sb->sb_wptr - sb->sb_data; - if (n > urgc) { - n = urgc; - } - memcpy((buff + len), sb->sb_data, n); - len += n; - } - n = slirp_send(so, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */ -#ifdef SLIRP_DEBUG - if (n != len) { - DEBUG_ERROR("Didn't send all data urgently XXXXX"); - } -#endif - } - - if (n < 0) { - return n; - } - so->so_urgc -= n; - DEBUG_MISC(" ---2 sent %d bytes urgent data, %d urgent bytes left", n, - so->so_urgc); - - sb->sb_cc -= n; - sb->sb_rptr += n; - if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen)) - sb->sb_rptr -= sb->sb_datalen; - - return n; -} - -/* - * Write data from so_rcv to so's socket, - * updating all sbuf field as necessary - */ -int sowrite(struct socket *so) -{ - int n, nn; - struct sbuf *sb = &so->so_rcv; - int len = sb->sb_cc; - struct iovec iov[2] = {{0, 0}, {0, 0}}; - - DEBUG_CALL("sowrite"); - DEBUG_ARG("so = %p", so); - - if (so->so_urgc) { - uint32_t expected = so->so_urgc; - if (sosendoob(so) < expected) { - /* Treat a short write as a fatal error too, - * rather than continuing on and sending the urgent - * data as if it were non-urgent and leaving the - * so_urgc count wrong. - */ - goto err_disconnected; - } - if (sb->sb_cc == 0) - return 0; - } - - /* - * No need to check if there's something to write, - * sowrite wouldn't have been called otherwise - */ - - iov[0].iov_base = sb->sb_rptr; - iov[1].iov_base = NULL; - iov[1].iov_len = 0; - if (sb->sb_rptr < sb->sb_wptr) { - iov[0].iov_len = sb->sb_wptr - sb->sb_rptr; - /* Should never succeed, but... */ - if (iov[0].iov_len > len) - iov[0].iov_len = len; - n = 1; - } else { - iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; - if (iov[0].iov_len > len) - iov[0].iov_len = len; - len -= iov[0].iov_len; - if (len) { - iov[1].iov_base = sb->sb_data; - iov[1].iov_len = sb->sb_wptr - sb->sb_data; - if (iov[1].iov_len > len) - iov[1].iov_len = len; - n = 2; - } else - n = 1; - } - /* Check if there's urgent data to send, and if so, send it */ - - nn = slirp_send(so, iov[0].iov_base, iov[0].iov_len, 0); - /* This should never happen, but people tell me it does *shrug* */ - if (nn < 0 && (errno == EAGAIN || errno == EINTR)) - return 0; - - if (nn <= 0) { - goto err_disconnected; - } - - if (n == 2 && nn == iov[0].iov_len) { - int ret; - ret = slirp_send(so, iov[1].iov_base, iov[1].iov_len, 0); - if (ret > 0) - nn += ret; - } - DEBUG_MISC(" ... wrote nn = %d bytes", nn); - - /* Update sbuf */ - sb->sb_cc -= nn; - sb->sb_rptr += nn; - if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen)) - sb->sb_rptr -= sb->sb_datalen; - - /* - * If in DRAIN mode, and there's no more data, set - * it CANTSENDMORE - */ - if ((so->so_state & SS_FWDRAIN) && sb->sb_cc == 0) - sofcantsendmore(so); - - return nn; - -err_disconnected: - DEBUG_MISC(" --- sowrite disconnected, so->so_state = %x, errno = %d", - so->so_state, errno); - sofcantsendmore(so); - tcp_sockclosed(sototcpcb(so)); - return -1; -} - -/* - * recvfrom() a UDP socket - */ -void sorecvfrom(struct socket *so) -{ - struct sockaddr_storage addr; - struct sockaddr_storage saddr, daddr; - socklen_t addrlen = sizeof(struct sockaddr_storage); - char buff[256]; - -#ifdef __linux__ - ssize_t size; - struct msghdr msg; - struct iovec iov; - char control[1024]; - - /* First look for errors */ - memset(&msg, 0, sizeof(msg)); - msg.msg_name = &saddr; - msg.msg_namelen = sizeof(saddr); - msg.msg_control = control; - msg.msg_controllen = sizeof(control); - iov.iov_base = buff; - iov.iov_len = sizeof(buff); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - - size = recvmsg(so->s, &msg, MSG_ERRQUEUE); - if (size >= 0) { - struct cmsghdr *cmsg; - for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { - - if (cmsg->cmsg_level == IPPROTO_IP && - cmsg->cmsg_type == IP_RECVERR) { - struct sock_extended_err *ee = - (struct sock_extended_err *) CMSG_DATA(cmsg); - - if (ee->ee_origin == SO_EE_ORIGIN_ICMP) { - /* Got an ICMP error, forward it */ - struct sockaddr_in *sin; - - sin = (struct sockaddr_in *) SO_EE_OFFENDER(ee); - icmp_forward_error(so->so_m, ee->ee_type, ee->ee_code, - 0, NULL, &sin->sin_addr); - } - } - else if (cmsg->cmsg_level == IPPROTO_IPV6 && - cmsg->cmsg_type == IPV6_RECVERR) { - struct sock_extended_err *ee = - (struct sock_extended_err *) CMSG_DATA(cmsg); - - if (ee->ee_origin == SO_EE_ORIGIN_ICMP6) { - /* Got an ICMPv6 error, forward it */ - struct sockaddr_in6 *sin6; - - sin6 = (struct sockaddr_in6 *) SO_EE_OFFENDER(ee); - icmp6_forward_error(so->so_m, ee->ee_type, ee->ee_code, - &sin6->sin6_addr); - } - } - } - return; - } -#endif - - DEBUG_CALL("sorecvfrom"); - DEBUG_ARG("so = %p", so); - - if (so->so_type == IPPROTO_ICMP) { /* This is a "ping" reply */ - int len; - - len = recvfrom(so->s, buff, 256, 0, (struct sockaddr *)&addr, &addrlen); - /* XXX Check if reply is "correct"? */ - - if (len == -1 || len == 0) { - uint8_t code = ICMP_UNREACH_PORT; - - if (errno == EHOSTUNREACH) - code = ICMP_UNREACH_HOST; - else if (errno == ENETUNREACH) - code = ICMP_UNREACH_NET; - - DEBUG_MISC(" udp icmp rx errno = %d-%s", errno, strerror(errno)); - icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, strerror(errno)); - } else { - icmp_reflect(so->so_m); - so->so_m = NULL; /* Don't m_free() it again! */ - } - /* No need for this socket anymore, udp_detach it */ - udp_detach(so); - } else { /* A "normal" UDP packet */ - struct mbuf *m; - int len; -#ifdef _WIN32 - unsigned long n; -#else - int n; -#endif - - if (ioctlsocket(so->s, FIONREAD, &n) != 0) { - DEBUG_MISC(" ioctlsocket errno = %d-%s\n", errno, strerror(errno)); - return; - } - - m = m_get(so->slirp); - if (!m) { - return; - } - switch (so->so_ffamily) { - case AF_INET: - m->m_data += IF_MAXLINKHDR + sizeof(struct udpiphdr); - break; - case AF_INET6: - m->m_data += - IF_MAXLINKHDR + sizeof(struct ip6) + sizeof(struct udphdr); - break; - default: - g_assert_not_reached(); - } - - /* - * XXX Shouldn't FIONREAD packets destined for port 53, - * but I don't know the max packet size for DNS lookups - */ - len = M_FREEROOM(m); - /* if (so->so_fport != htons(53)) { */ - - if (n > len) { - n = (m->m_data - m->m_dat) + m->m_len + n + 1; - m_inc(m, n); - len = M_FREEROOM(m); - } - /* } */ - - m->m_len = recvfrom(so->s, m->m_data, len, 0, (struct sockaddr *)&addr, - &addrlen); - DEBUG_MISC(" did recvfrom %d, errno = %d-%s", m->m_len, errno, - strerror(errno)); - if (m->m_len < 0) { - /* Report error as ICMP */ - switch (so->so_lfamily) { - uint8_t code; - case AF_INET: - code = ICMP_UNREACH_PORT; - - if (errno == EHOSTUNREACH) { - code = ICMP_UNREACH_HOST; - } else if (errno == ENETUNREACH) { - code = ICMP_UNREACH_NET; - } - - DEBUG_MISC(" rx error, tx icmp ICMP_UNREACH:%i", code); - icmp_send_error(so->so_m, ICMP_UNREACH, code, 0, - strerror(errno)); - break; - case AF_INET6: - code = ICMP6_UNREACH_PORT; - - if (errno == EHOSTUNREACH) { - code = ICMP6_UNREACH_ADDRESS; - } else if (errno == ENETUNREACH) { - code = ICMP6_UNREACH_NO_ROUTE; - } - - DEBUG_MISC(" rx error, tx icmp6 ICMP_UNREACH:%i", code); - icmp6_send_error(so->so_m, ICMP6_UNREACH, code); - break; - default: - g_assert_not_reached(); - } - m_free(m); - } else { - /* - * Hack: domain name lookup will be used the most for UDP, - * and since they'll only be used once there's no need - * for the 4 minute (or whatever) timeout... So we time them - * out much quicker (10 seconds for now...) - */ - if (so->so_expire) { - if (so->so_fport == htons(53)) - so->so_expire = curtime + SO_EXPIREFAST; - else - so->so_expire = curtime + SO_EXPIRE; - } - - /* - * If this packet was destined for CTL_ADDR, - * make it look like that's where it came from - */ - saddr = addr; - sotranslate_in(so, &saddr); - - /* Perform lazy guest IP address resolution if needed. */ - if (so->so_state & SS_HOSTFWD) { - if (soassign_guest_addr_if_needed(so) < 0) { - DEBUG_MISC(" guest address not available yet"); - switch (so->so_lfamily) { - case AF_INET: - icmp_send_error(so->so_m, ICMP_UNREACH, - ICMP_UNREACH_HOST, 0, - "guest address not available yet"); - break; - case AF_INET6: - icmp6_send_error(so->so_m, ICMP6_UNREACH, - ICMP6_UNREACH_ADDRESS); - break; - default: - g_assert_not_reached(); - } - m_free(m); - return; - } - } - daddr = so->lhost.ss; - - switch (so->so_ffamily) { - case AF_INET: - udp_output(so, m, (struct sockaddr_in *)&saddr, - (struct sockaddr_in *)&daddr, so->so_iptos); - break; - case AF_INET6: - udp6_output(so, m, (struct sockaddr_in6 *)&saddr, - (struct sockaddr_in6 *)&daddr); - break; - default: - g_assert_not_reached(); - } - } /* rx error */ - } /* if ping packet */ -} - -/* - * sendto() a socket - */ -int sosendto(struct socket *so, struct mbuf *m) -{ - int ret; - struct sockaddr_storage addr; - - DEBUG_CALL("sosendto"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - - addr = so->fhost.ss; - DEBUG_CALL(" sendto()ing)"); - if (sotranslate_out(so, &addr) < 0) { - return -1; - } - - /* Don't care what port we get */ - ret = sendto(so->s, m->m_data, m->m_len, 0, (struct sockaddr *)&addr, - sockaddr_size(&addr)); - if (ret < 0) - return -1; - - /* - * Kill the socket if there's no reply in 4 minutes, - * but only if it's an expirable socket - */ - if (so->so_expire) - so->so_expire = curtime + SO_EXPIRE; - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_ISFCONNECTED; /* So that it gets select()ed */ - return 0; -} - -/* - * Listen for incoming TCP connections - * On failure errno contains the reason. - */ -struct socket *tcpx_listen(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *laddr, socklen_t laddrlen, - int flags) -{ - struct socket *so; - int s, opt = 1; - socklen_t addrlen; - - DEBUG_CALL("tcpx_listen"); - /* AF_INET6 addresses are bigger than AF_INET, so this is big enough. */ - char addrstr[INET6_ADDRSTRLEN]; - char portstr[6]; - int ret; - switch (haddr->sa_family) { - case AF_INET: - case AF_INET6: - ret = getnameinfo(haddr, haddrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_ARG("hfamily = INET"); - DEBUG_ARG("haddr = %s", addrstr); - DEBUG_ARG("hport = %s", portstr); - break; -#ifndef _WIN32 - case AF_UNIX: - DEBUG_ARG("hfamily = UNIX"); - DEBUG_ARG("hpath = %s", ((struct sockaddr_un *) haddr)->sun_path); - break; -#endif - default: - g_assert_not_reached(); - } - switch (laddr->sa_family) { - case AF_INET: - case AF_INET6: - ret = getnameinfo(laddr, laddrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_ARG("laddr = %s", addrstr); - DEBUG_ARG("lport = %s", portstr); - break; - default: - g_assert_not_reached(); - } - DEBUG_ARG("flags = %x", flags); - - /* - * SS_HOSTFWD sockets can be accepted multiple times, so they can't be - * SS_FACCEPTONCE. Also, SS_HOSTFWD connections can be accepted and - * immediately closed if the guest address isn't available yet, which is - * incompatible with the "accept once" concept. Correct code will never - * request both, so disallow their combination by assertion. - */ - g_assert(!((flags & SS_HOSTFWD) && (flags & SS_FACCEPTONCE))); - - so = socreate(slirp, IPPROTO_TCP); - - /* Don't tcp_attach... we don't need so_snd nor so_rcv */ - so->so_tcpcb = tcp_newtcpcb(so); - slirp_insque(so, &slirp->tcb); - - /* - * SS_FACCEPTONCE sockets must time out. - */ - if (flags & SS_FACCEPTONCE) - so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT * 2; - - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= (SS_FACCEPTCONN | flags); - - sockaddr_copy(&so->lhost.sa, sizeof(so->lhost), laddr, laddrlen); - - s = slirp_socket(haddr->sa_family, SOCK_STREAM, 0); - if ((s < 0) || - (haddr->sa_family == AF_INET6 && slirp_socket_set_v6only(s, (flags & SS_HOSTFWD_V6ONLY) != 0) < 0) || - (slirp_socket_set_fast_reuse(s) < 0) || - (bind(s, haddr, haddrlen) < 0) || - (listen(s, 1) < 0)) { - int tmperrno = errno; /* Don't clobber the real reason we failed */ - if (s >= 0) { - closesocket(s); - } - sofree(so); - /* Restore the real errno */ -#ifdef _WIN32 - WSASetLastError(tmperrno); -#else - errno = tmperrno; -#endif - return NULL; - } - setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - slirp_socket_set_nodelay(s); - - addrlen = sizeof(so->fhost); - getsockname(s, &so->fhost.sa, &addrlen); - sotranslate_accept(so); - - so->s = s; - return so; -} - -struct socket *tcp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, - uint32_t laddr, unsigned lport, int flags) -{ - struct sockaddr_in hsa, lsa; - - memset(&hsa, 0, sizeof(hsa)); - hsa.sin_family = AF_INET; - hsa.sin_addr.s_addr = haddr; - hsa.sin_port = hport; - - memset(&lsa, 0, sizeof(lsa)); - lsa.sin_family = AF_INET; - lsa.sin_addr.s_addr = laddr; - lsa.sin_port = lport; - - return tcpx_listen(slirp, (const struct sockaddr *) &hsa, sizeof(hsa), (struct sockaddr *) &lsa, sizeof(lsa), flags); -} - -/* - * Various session state calls - * XXX Should be #define's - * The socket state stuff needs work, these often get call 2 or 3 - * times each when only 1 was needed - */ -void soisfconnecting(struct socket *so) -{ - so->so_state &= ~(SS_NOFDREF | SS_ISFCONNECTED | SS_FCANTRCVMORE | - SS_FCANTSENDMORE | SS_FWDRAIN); - so->so_state |= SS_ISFCONNECTING; /* Clobber other states */ -} - -void soisfconnected(struct socket *so) -{ - so->so_state &= ~(SS_ISFCONNECTING | SS_FWDRAIN | SS_NOFDREF); - so->so_state |= SS_ISFCONNECTED; /* Clobber other states */ -} - -static void sofcantrcvmore(struct socket *so) -{ - if ((so->so_state & SS_NOFDREF) == 0) { - shutdown(so->s, 0); - } - so->so_state &= ~(SS_ISFCONNECTING); - if (so->so_state & SS_FCANTSENDMORE) { - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_NOFDREF; /* Don't select it */ - } else { - so->so_state |= SS_FCANTRCVMORE; - } -} - -static void sofcantsendmore(struct socket *so) -{ - if ((so->so_state & SS_NOFDREF) == 0) { - shutdown(so->s, 1); /* send FIN to fhost */ - } - so->so_state &= ~(SS_ISFCONNECTING); - if (so->so_state & SS_FCANTRCVMORE) { - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_NOFDREF; /* as above */ - } else { - so->so_state |= SS_FCANTSENDMORE; - } -} - -/* - * Set write drain mode - * Set CANTSENDMORE once all data has been write()n - */ -void sofwdrain(struct socket *so) -{ - if (so->so_rcv.sb_cc) - so->so_state |= SS_FWDRAIN; - else - sofcantsendmore(so); -} - -static bool sotranslate_out4(Slirp *s, struct socket *so, struct sockaddr_in *sin) -{ - if (!s->disable_dns && so->so_faddr.s_addr == s->vnameserver_addr.s_addr) { - return so->so_fport == htons(53) && get_dns_addr(&sin->sin_addr) >= 0; - } - - if (so->so_faddr.s_addr == s->vhost_addr.s_addr || - so->so_faddr.s_addr == 0xffffffff) { - if (s->disable_host_loopback) { - return false; - } - - sin->sin_addr = loopback_addr; - } - - return true; -} - -static bool sotranslate_out6(Slirp *s, struct socket *so, struct sockaddr_in6 *sin) -{ - if (!s->disable_dns && in6_equal(&so->so_faddr6, &s->vnameserver_addr6)) { - uint32_t scope_id; - if (so->so_fport == htons(53) && get_dns6_addr(&sin->sin6_addr, &scope_id) >= 0) { - sin->sin6_scope_id = scope_id; - return true; - } - return false; - } - - if (in6_equal_net(&so->so_faddr6, &s->vprefix_addr6, s->vprefix_len) || - in6_equal(&so->so_faddr6, &(struct in6_addr)ALLNODES_MULTICAST)) { - if (s->disable_host_loopback) { - return false; - } - - sin->sin6_addr = in6addr_loopback; - } - - return true; -} - - -/* - * Translate addr in host addr when it is a virtual address - */ -int sotranslate_out(struct socket *so, struct sockaddr_storage *addr) -{ - bool ok = true; - - switch (addr->ss_family) { - case AF_INET: - ok = sotranslate_out4(so->slirp, so, (struct sockaddr_in *)addr); - break; - case AF_INET6: - ok = sotranslate_out6(so->slirp, so, (struct sockaddr_in6 *)addr); - break; - } - - if (!ok) { - errno = EPERM; - return -1; - } - - return 0; -} - -void sotranslate_in(struct socket *so, struct sockaddr_storage *addr) -{ - Slirp *slirp = so->slirp; - struct sockaddr_in *sin = (struct sockaddr_in *)addr; - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr; - - switch (addr->ss_family) { - case AF_INET: - if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) == - slirp->vnetwork_addr.s_addr) { - uint32_t inv_mask = ~slirp->vnetwork_mask.s_addr; - - if ((so->so_faddr.s_addr & inv_mask) == inv_mask) { - sin->sin_addr = slirp->vhost_addr; - } else if (sin->sin_addr.s_addr == loopback_addr.s_addr || - so->so_faddr.s_addr != slirp->vhost_addr.s_addr) { - sin->sin_addr = so->so_faddr; - } - } - break; - - case AF_INET6: - if (in6_equal_net(&so->so_faddr6, &slirp->vprefix_addr6, - slirp->vprefix_len)) { - if (in6_equal(&sin6->sin6_addr, &in6addr_loopback) || - !in6_equal(&so->so_faddr6, &slirp->vhost_addr6)) { - sin6->sin6_addr = so->so_faddr6; - } - } - break; - - default: - break; - } -} - -/* - * Translate connections from localhost to the real hostname - */ -void sotranslate_accept(struct socket *so) -{ - Slirp *slirp = so->slirp; - - switch (so->so_ffamily) { - case AF_INET: - if (so->so_faddr.s_addr == INADDR_ANY || - (so->so_faddr.s_addr & loopback_mask) == - (loopback_addr.s_addr & loopback_mask)) { - so->so_faddr = slirp->vhost_addr; - } - break; - - case AF_INET6: - if (in6_equal(&so->so_faddr6, &in6addr_any) || - in6_equal(&so->so_faddr6, &in6addr_loopback)) { - so->so_faddr6 = slirp->vhost_addr6; - } - break; - - case AF_UNIX: { - /* Translate Unix socket to random ephemeral source port. We obtain - * this source port by binding to port 0 so that the OS allocates a - * port for us. If this fails, we fall back to choosing a random port - * with a random number generator. */ - int s; - struct sockaddr_in in_addr; - struct sockaddr_in6 in6_addr; - socklen_t in_addr_len; - - if (so->slirp->in_enabled) { - so->so_ffamily = AF_INET; - so->so_faddr = slirp->vhost_addr; - so->so_fport = 0; - - switch (so->so_type) { - case IPPROTO_TCP: - s = slirp_socket(PF_INET, SOCK_STREAM, 0); - break; - case IPPROTO_UDP: - s = slirp_socket(PF_INET, SOCK_DGRAM, 0); - break; - default: - g_assert_not_reached(); - break; - } - if (s < 0) { - g_error("Ephemeral slirp_socket() allocation failed"); - goto unix2inet_cont; - } - memset(&in_addr, 0, sizeof(in_addr)); - in_addr.sin_family = AF_INET; - in_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - in_addr.sin_port = htons(0); - if (bind(s, (struct sockaddr *) &in_addr, sizeof(in_addr))) { - g_error("Ephemeral bind() failed"); - closesocket(s); - goto unix2inet_cont; - } - in_addr_len = sizeof(in_addr); - if (getsockname(s, (struct sockaddr *) &in_addr, &in_addr_len)) { - g_error("Ephemeral getsockname() failed"); - closesocket(s); - goto unix2inet_cont; - } - so->s_aux = s; - so->so_fport = in_addr.sin_port; - -unix2inet_cont: - if (!so->so_fport) { - g_warning("Falling back to random port allocation"); - so->so_fport = htons(g_rand_int_range(slirp->grand, 49152, 65536)); - } - } else if (so->slirp->in6_enabled) { - so->so_ffamily = AF_INET6; - so->so_faddr6 = slirp->vhost_addr6; - so->so_fport6 = 0; - - switch (so->so_type) { - case IPPROTO_TCP: - s = slirp_socket(PF_INET6, SOCK_STREAM, 0); - break; - case IPPROTO_UDP: - s = slirp_socket(PF_INET6, SOCK_DGRAM, 0); - break; - default: - g_assert_not_reached(); - break; - } - if (s < 0) { - g_error("Ephemeral slirp_socket() allocation failed"); - goto unix2inet6_cont; - } - memset(&in6_addr, 0, sizeof(in6_addr)); - in6_addr.sin6_family = AF_INET6; - in6_addr.sin6_addr = in6addr_loopback; - in6_addr.sin6_port = htons(0); - if (bind(s, (struct sockaddr *) &in6_addr, sizeof(in6_addr))) { - g_error("Ephemeral bind() failed"); - closesocket(s); - goto unix2inet6_cont; - } - in_addr_len = sizeof(in6_addr); - if (getsockname(s, (struct sockaddr *) &in6_addr, &in_addr_len)) { - g_error("Ephemeral getsockname() failed"); - closesocket(s); - goto unix2inet6_cont; - } - so->s_aux = s; - so->so_fport6 = in6_addr.sin6_port; - -unix2inet6_cont: - if (!so->so_fport6) { - g_warning("Falling back to random port allocation"); - so->so_fport6 = htons(g_rand_int_range(slirp->grand, 49152, 65536)); - } - } else { - g_assert_not_reached(); - } - break; - } /* case AF_UNIX */ - - default: - break; - } -} - -void sodrop(struct socket *s, int num) -{ - if (sbdrop(&s->so_snd, num)) { - s->slirp->cb->notify(s->slirp->opaque); - } -} - -/* - * Translate "addr-any" in so->lhost to the guest's actual address. - * Returns 0 for success, or -1 if the guest doesn't have an address yet - * with errno set to EHOSTUNREACH. - * - * The guest address is taken from the first entry in the ARP table for IPv4 - * and the first entry in the NDP table for IPv6. - * Note: The IPv4 path isn't exercised yet as all hostfwd "" guest translations - * are handled immediately by using slirp->vdhcp_startaddr. - */ -int soassign_guest_addr_if_needed(struct socket *so) -{ - Slirp *slirp = so->slirp; - /* AF_INET6 addresses are bigger than AF_INET, so this is big enough. */ - char addrstr[INET6_ADDRSTRLEN]; - char portstr[6]; - - g_assert(so->so_state & SS_HOSTFWD); - - switch (so->so_ffamily) { - case AF_INET: - if (so->so_laddr.s_addr == INADDR_ANY) { - g_assert_not_reached(); - } - break; - - case AF_INET6: - if (in6_zero(&so->so_laddr6)) { - int ret; - if (in6_zero(&slirp->ndp_table.guest_in6_addr)) { - errno = EHOSTUNREACH; - return -1; - } - so->so_laddr6 = slirp->ndp_table.guest_in6_addr; - ret = getnameinfo((const struct sockaddr *) &so->lhost.ss, - sizeof(so->lhost.ss), addrstr, sizeof(addrstr), - portstr, sizeof(portstr), - NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_MISC("%s: new ip = [%s]:%s", __func__, addrstr, portstr); - } - break; - - default: - break; - } - - return 0; -} diff --git a/src/network/slirp/socket.h b/src/network/slirp/socket.h deleted file mode 100644 index ca8c103ec..000000000 --- a/src/network/slirp/socket.h +++ /dev/null @@ -1,206 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1995 Danny Gasparovski. - */ - -#ifndef SLIRP_SOCKET_H -#define SLIRP_SOCKET_H - -#include - -#ifndef _WIN32 -#include -#endif - -#include "misc.h" -#include "sbuf.h" - -#define SO_EXPIRE 240000 -#define SO_EXPIREFAST 10000 - -/* Helps unify some in/in6 routines. */ -union in4or6_addr { - struct in_addr addr4; - struct in6_addr addr6; -}; -typedef union in4or6_addr in4or6_addr; - -/* - * Our socket structure - */ - -union slirp_sockaddr { - struct sockaddr sa; - struct sockaddr_storage ss; - struct sockaddr_in sin; - struct sockaddr_in6 sin6; -}; - -struct socket { - struct socket *so_next, *so_prev; /* For a linked list of sockets */ - - int s; /* The actual socket */ - int s_aux; /* An auxiliary socket for miscellaneous use. Currently used to - * reserve OS ports in UNIX-to-inet translation. */ - struct gfwd_list *guestfwd; - - int pollfds_idx; /* GPollFD GArray index */ - - Slirp *slirp; /* managing slirp instance */ - - /* XXX union these with not-yet-used sbuf params */ - struct mbuf *so_m; /* Pointer to the original SYN packet, - * for non-blocking connect()'s, and - * PING reply's */ - struct tcpiphdr *so_ti; /* Pointer to the original ti within - * so_mconn, for non-blocking connections */ - uint32_t so_urgc; - union slirp_sockaddr fhost; /* Foreign host */ -#define so_faddr fhost.sin.sin_addr -#define so_fport fhost.sin.sin_port -#define so_faddr6 fhost.sin6.sin6_addr -#define so_fport6 fhost.sin6.sin6_port -#define so_ffamily fhost.ss.ss_family - - union slirp_sockaddr lhost; /* Local host */ -#define so_laddr lhost.sin.sin_addr -#define so_lport lhost.sin.sin_port -#define so_laddr6 lhost.sin6.sin6_addr -#define so_lport6 lhost.sin6.sin6_port -#define so_lfamily lhost.ss.ss_family - - uint8_t so_iptos; /* Type of service */ - uint8_t so_emu; /* Is the socket emulated? */ - - uint8_t so_type; /* Protocol of the socket. May be 0 if loading old - * states. */ - int32_t so_state; /* internal state flags SS_*, below */ - - struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */ - unsigned so_expire; /* When the socket will expire */ - - int so_queued; /* Number of packets queued from this socket */ - int so_nqueued; /* Number of packets queued in a row - * Used to determine when to "downgrade" a session - * from fastq to batchq */ - - struct sbuf so_rcv; /* Receive buffer */ - struct sbuf so_snd; /* Send buffer */ -}; - - -/* - * Socket state bits. (peer means the host on the Internet, - * local host means the host on the other end of the modem) - */ -#define SS_NOFDREF 0x001 /* No fd reference */ - -#define SS_ISFCONNECTING \ - 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */ -#define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */ -#define SS_FCANTRCVMORE \ - 0x008 /* Socket can't receive more from peer (for half-closes) */ -#define SS_FCANTSENDMORE \ - 0x010 /* Socket can't send more to peer (for half-closes) */ -#define SS_FWDRAIN \ - 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */ - -#define SS_CTL 0x080 -#define SS_FACCEPTCONN \ - 0x100 /* Socket is accepting connections from a host on the internet */ -#define SS_FACCEPTONCE \ - 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */ - -#define SS_PERSISTENT_MASK 0xf000 /* Unremovable state bits */ -#define SS_HOSTFWD 0x1000 /* Socket describes host->guest forwarding */ -#define SS_INCOMING \ - 0x2000 /* Connection was initiated by a host on the internet */ -#define SS_HOSTFWD_V6ONLY 0x4000 /* Only bind on v6 addresses */ - -static inline int sockaddr_equal(const struct sockaddr_storage *a, - const struct sockaddr_storage *b) -{ - if (a->ss_family != b->ss_family) { - return 0; - } - - switch (a->ss_family) { - case AF_INET: { - const struct sockaddr_in *a4 = (const struct sockaddr_in *)a; - const struct sockaddr_in *b4 = (const struct sockaddr_in *)b; - return a4->sin_addr.s_addr == b4->sin_addr.s_addr && - a4->sin_port == b4->sin_port; - } - case AF_INET6: { - const struct sockaddr_in6 *a6 = (const struct sockaddr_in6 *)a; - const struct sockaddr_in6 *b6 = (const struct sockaddr_in6 *)b; - return (in6_equal(&a6->sin6_addr, &b6->sin6_addr) && - a6->sin6_port == b6->sin6_port); - } -#ifndef _WIN32 - case AF_UNIX: { - const struct sockaddr_un *aun = (const struct sockaddr_un *)a; - const struct sockaddr_un *bun = (const struct sockaddr_un *)b; - return strncmp(aun->sun_path, bun->sun_path, sizeof(aun->sun_path)) == 0; - } -#endif - default: - g_assert_not_reached(); - } - - return 0; -} - -static inline socklen_t sockaddr_size(const struct sockaddr_storage *a) -{ - switch (a->ss_family) { - case AF_INET: - return sizeof(struct sockaddr_in); - case AF_INET6: - return sizeof(struct sockaddr_in6); -#ifndef _WIN32 - case AF_UNIX: - return sizeof(struct sockaddr_un); -#endif - default: - g_assert_not_reached(); - } -} - -static inline void sockaddr_copy(struct sockaddr *dst, socklen_t dstlen, const struct sockaddr *src, socklen_t srclen) -{ - socklen_t len = sockaddr_size((const struct sockaddr_storage *) src); - g_assert(len <= srclen); - g_assert(len <= dstlen); - memcpy(dst, src, len); -} - -struct socket *solookup(struct socket **, struct socket *, - struct sockaddr_storage *, struct sockaddr_storage *); -struct socket *socreate(Slirp *, int); -void sofree(struct socket *); -int soread(struct socket *); -int sorecvoob(struct socket *); -int sosendoob(struct socket *); -int sowrite(struct socket *); -void sorecvfrom(struct socket *); -int sosendto(struct socket *, struct mbuf *); -struct socket *tcp_listen(Slirp *, uint32_t, unsigned, uint32_t, unsigned, int); -struct socket *tcpx_listen(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *laddr, socklen_t laddrlen, - int flags); -void soisfconnecting(register struct socket *); -void soisfconnected(register struct socket *); -void sofwdrain(struct socket *); -struct iovec; /* For win32 */ -size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np); -int soreadbuf(struct socket *so, const char *buf, int size); - -int sotranslate_out(struct socket *, struct sockaddr_storage *); -void sotranslate_in(struct socket *, struct sockaddr_storage *); -void sotranslate_accept(struct socket *); -void sodrop(struct socket *, int num); -int soassign_guest_addr_if_needed(struct socket *so); - -#endif /* SLIRP_SOCKET_H */ diff --git a/src/network/slirp/state.c b/src/network/slirp/state.c deleted file mode 100644 index 870854747..000000000 --- a/src/network/slirp/state.c +++ /dev/null @@ -1,379 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * libslirp - * - * Copyright (c) 2004-2008 Fabrice Bellard - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "slirp.h" -#include "vmstate.h" -#include "stream.h" - -static int slirp_tcp_post_load(void *opaque, int version) -{ - tcp_template((struct tcpcb *)opaque); - - return 0; -} - -static const VMStateDescription vmstate_slirp_tcp = { - .name = "slirp-tcp", - .version_id = 0, - .post_load = slirp_tcp_post_load, - .fields = (VMStateField[]){ VMSTATE_INT16(t_state, struct tcpcb), - VMSTATE_INT16_ARRAY(t_timer, struct tcpcb, - TCPT_NTIMERS), - VMSTATE_INT16(t_rxtshift, struct tcpcb), - VMSTATE_INT16(t_rxtcur, struct tcpcb), - VMSTATE_INT16(t_dupacks, struct tcpcb), - VMSTATE_UINT16(t_maxseg, struct tcpcb), - VMSTATE_UINT8(t_force, struct tcpcb), - VMSTATE_UINT16(t_flags, struct tcpcb), - VMSTATE_UINT32(snd_una, struct tcpcb), - VMSTATE_UINT32(snd_nxt, struct tcpcb), - VMSTATE_UINT32(snd_up, struct tcpcb), - VMSTATE_UINT32(snd_wl1, struct tcpcb), - VMSTATE_UINT32(snd_wl2, struct tcpcb), - VMSTATE_UINT32(iss, struct tcpcb), - VMSTATE_UINT32(snd_wnd, struct tcpcb), - VMSTATE_UINT32(rcv_wnd, struct tcpcb), - VMSTATE_UINT32(rcv_nxt, struct tcpcb), - VMSTATE_UINT32(rcv_up, struct tcpcb), - VMSTATE_UINT32(irs, struct tcpcb), - VMSTATE_UINT32(rcv_adv, struct tcpcb), - VMSTATE_UINT32(snd_max, struct tcpcb), - VMSTATE_UINT32(snd_cwnd, struct tcpcb), - VMSTATE_UINT32(snd_ssthresh, struct tcpcb), - VMSTATE_INT16(t_idle, struct tcpcb), - VMSTATE_INT16(t_rtt, struct tcpcb), - VMSTATE_UINT32(t_rtseq, struct tcpcb), - VMSTATE_INT16(t_srtt, struct tcpcb), - VMSTATE_INT16(t_rttvar, struct tcpcb), - VMSTATE_UINT16(t_rttmin, struct tcpcb), - VMSTATE_UINT32(max_sndwnd, struct tcpcb), - VMSTATE_UINT8(t_oobflags, struct tcpcb), - VMSTATE_UINT8(t_iobc, struct tcpcb), - VMSTATE_INT16(t_softerror, struct tcpcb), - VMSTATE_UINT8(snd_scale, struct tcpcb), - VMSTATE_UINT8(rcv_scale, struct tcpcb), - VMSTATE_UINT8(request_r_scale, struct tcpcb), - VMSTATE_UINT8(requested_s_scale, struct tcpcb), - VMSTATE_UINT32(ts_recent, struct tcpcb), - VMSTATE_UINT32(ts_recent_age, struct tcpcb), - VMSTATE_UINT32(last_ack_sent, struct tcpcb), - VMSTATE_END_OF_LIST() } -}; - -/* The sbuf has a pair of pointers that are migrated as offsets; - * we calculate the offsets and restore the pointers using - * pre_save/post_load on a tmp structure. - */ -struct sbuf_tmp { - struct sbuf *parent; - uint32_t roff, woff; -}; - -static int sbuf_tmp_pre_save(void *opaque) -{ - struct sbuf_tmp *tmp = opaque; - tmp->woff = tmp->parent->sb_wptr - tmp->parent->sb_data; - tmp->roff = tmp->parent->sb_rptr - tmp->parent->sb_data; - - return 0; -} - -static int sbuf_tmp_post_load(void *opaque, int version) -{ - struct sbuf_tmp *tmp = opaque; - uint32_t requested_len = tmp->parent->sb_datalen; - - /* Allocate the buffer space used by the field after the tmp */ - sbreserve(tmp->parent, tmp->parent->sb_datalen); - - if (tmp->woff >= requested_len || tmp->roff >= requested_len) { - g_critical("invalid sbuf offsets r/w=%u/%u len=%u", tmp->roff, - tmp->woff, requested_len); - return -EINVAL; - } - - tmp->parent->sb_wptr = tmp->parent->sb_data + tmp->woff; - tmp->parent->sb_rptr = tmp->parent->sb_data + tmp->roff; - - return 0; -} - - -static const VMStateDescription vmstate_slirp_sbuf_tmp = { - .name = "slirp-sbuf-tmp", - .post_load = sbuf_tmp_post_load, - .pre_save = sbuf_tmp_pre_save, - .version_id = 0, - .fields = (VMStateField[]){ VMSTATE_UINT32(woff, struct sbuf_tmp), - VMSTATE_UINT32(roff, struct sbuf_tmp), - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp_sbuf = { - .name = "slirp-sbuf", - .version_id = 0, - .fields = (VMStateField[]){ VMSTATE_UINT32(sb_cc, struct sbuf), - VMSTATE_UINT32(sb_datalen, struct sbuf), - VMSTATE_WITH_TMP(struct sbuf, struct sbuf_tmp, - vmstate_slirp_sbuf_tmp), - VMSTATE_VBUFFER_UINT32(sb_data, struct sbuf, 0, - NULL, sb_datalen), - VMSTATE_END_OF_LIST() } -}; - -static bool slirp_older_than_v4(void *opaque, int version_id) -{ - return version_id < 4; -} - -static bool slirp_family_inet(void *opaque, int version_id) -{ - union slirp_sockaddr *ssa = (union slirp_sockaddr *)opaque; - return ssa->ss.ss_family == AF_INET; -} - -static int slirp_socket_pre_load(void *opaque) -{ - struct socket *so = opaque; - - tcp_attach(so); - /* Older versions don't load these fields */ - so->so_ffamily = AF_INET; - so->so_lfamily = AF_INET; - return 0; -} - -#ifndef _WIN32 -#define VMSTATE_SIN4_ADDR(f, s, t) VMSTATE_UINT32_TEST(f, s, t) -#else -/* Win uses u_long rather than uint32_t - but it's still 32bits long */ -#define VMSTATE_SIN4_ADDR(f, s, t) \ - VMSTATE_SINGLE_TEST(f, s, t, 0, slirp_vmstate_info_uint32, u_long) -#endif - -/* The OS provided ss_family field isn't that portable; it's size - * and type varies (16/8 bit, signed, unsigned) - * and the values it contains aren't fully portable. - */ -typedef struct SS_FamilyTmpStruct { - union slirp_sockaddr *parent; - uint16_t portable_family; -} SS_FamilyTmpStruct; - -#define SS_FAMILY_MIG_IPV4 2 /* Linux, BSD, Win... */ -#define SS_FAMILY_MIG_IPV6 10 /* Linux */ -#define SS_FAMILY_MIG_OTHER 0xffff - -static int ss_family_pre_save(void *opaque) -{ - SS_FamilyTmpStruct *tss = opaque; - - tss->portable_family = SS_FAMILY_MIG_OTHER; - - if (tss->parent->ss.ss_family == AF_INET) { - tss->portable_family = SS_FAMILY_MIG_IPV4; - } else if (tss->parent->ss.ss_family == AF_INET6) { - tss->portable_family = SS_FAMILY_MIG_IPV6; - } - - return 0; -} - -static int ss_family_post_load(void *opaque, int version_id) -{ - SS_FamilyTmpStruct *tss = opaque; - - switch (tss->portable_family) { - case SS_FAMILY_MIG_IPV4: - tss->parent->ss.ss_family = AF_INET; - break; - case SS_FAMILY_MIG_IPV6: - case 23: /* compatibility: AF_INET6 from mingw */ - case 28: /* compatibility: AF_INET6 from FreeBSD sys/socket.h */ - tss->parent->ss.ss_family = AF_INET6; - break; - default: - g_critical("invalid ss_family type %x", tss->portable_family); - return -EINVAL; - } - - return 0; -} - -static const VMStateDescription vmstate_slirp_ss_family = { - .name = "slirp-socket-addr/ss_family", - .pre_save = ss_family_pre_save, - .post_load = ss_family_post_load, - .fields = - (VMStateField[]){ VMSTATE_UINT16(portable_family, SS_FamilyTmpStruct), - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp_socket_addr = { - .name = "slirp-socket-addr", - .version_id = 4, - .fields = - (VMStateField[]){ - VMSTATE_WITH_TMP(union slirp_sockaddr, SS_FamilyTmpStruct, - vmstate_slirp_ss_family), - VMSTATE_SIN4_ADDR(sin.sin_addr.s_addr, union slirp_sockaddr, - slirp_family_inet), - VMSTATE_UINT16_TEST(sin.sin_port, union slirp_sockaddr, - slirp_family_inet), - -#if 0 - /* Untested: Needs checking by someone with IPv6 test */ - VMSTATE_BUFFER_TEST(sin6.sin6_addr, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT16_TEST(sin6.sin6_port, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT32_TEST(sin6.sin6_flowinfo, union slirp_sockaddr, - slirp_family_inet6), - VMSTATE_UINT32_TEST(sin6.sin6_scope_id, union slirp_sockaddr, - slirp_family_inet6), -#endif - - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp_socket = { - .name = "slirp-socket", - .version_id = 4, - .pre_load = slirp_socket_pre_load, - .fields = - (VMStateField[]){ - VMSTATE_UINT32(so_urgc, struct socket), - /* Pre-v4 versions */ - VMSTATE_SIN4_ADDR(so_faddr.s_addr, struct socket, - slirp_older_than_v4), - VMSTATE_SIN4_ADDR(so_laddr.s_addr, struct socket, - slirp_older_than_v4), - VMSTATE_UINT16_TEST(so_fport, struct socket, slirp_older_than_v4), - VMSTATE_UINT16_TEST(so_lport, struct socket, slirp_older_than_v4), - /* v4 and newer */ - VMSTATE_STRUCT(fhost, struct socket, 4, vmstate_slirp_socket_addr, - union slirp_sockaddr), - VMSTATE_STRUCT(lhost, struct socket, 4, vmstate_slirp_socket_addr, - union slirp_sockaddr), - - VMSTATE_UINT8(so_iptos, struct socket), - VMSTATE_UINT8(so_emu, struct socket), - VMSTATE_UINT8(so_type, struct socket), - VMSTATE_INT32(so_state, struct socket), - VMSTATE_STRUCT(so_rcv, struct socket, 0, vmstate_slirp_sbuf, - struct sbuf), - VMSTATE_STRUCT(so_snd, struct socket, 0, vmstate_slirp_sbuf, - struct sbuf), - VMSTATE_STRUCT_POINTER(so_tcpcb, struct socket, vmstate_slirp_tcp, - struct tcpcb), - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp_bootp_client = { - .name = "slirp_bootpclient", - .fields = (VMStateField[]){ VMSTATE_UINT16(allocated, BOOTPClient), - VMSTATE_BUFFER(macaddr, BOOTPClient), - VMSTATE_END_OF_LIST() } -}; - -static const VMStateDescription vmstate_slirp = { - .name = "slirp", - .version_id = 4, - .fields = (VMStateField[]){ VMSTATE_UINT16_V(ip_id, Slirp, 2), - VMSTATE_STRUCT_ARRAY( - bootp_clients, Slirp, NB_BOOTP_CLIENTS, 3, - vmstate_slirp_bootp_client, BOOTPClient), - VMSTATE_END_OF_LIST() } -}; - -void slirp_state_save(Slirp *slirp, SlirpWriteCb write_cb, void *opaque) -{ - struct gfwd_list *ex_ptr; - SlirpOStream f = { - .write_cb = write_cb, - .opaque = opaque, - }; - - for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) - if (ex_ptr->write_cb) { - struct socket *so; - so = slirp_find_ctl_socket(slirp, ex_ptr->ex_addr, - ntohs(ex_ptr->ex_fport)); - if (!so) { - continue; - } - - slirp_ostream_write_u8(&f, 42); - slirp_vmstate_save_state(&f, &vmstate_slirp_socket, so); - } - slirp_ostream_write_u8(&f, 0); - - slirp_vmstate_save_state(&f, &vmstate_slirp, slirp); -} - - -int slirp_state_load(Slirp *slirp, int version_id, SlirpReadCb read_cb, - void *opaque) -{ - struct gfwd_list *ex_ptr; - SlirpIStream f = { - .read_cb = read_cb, - .opaque = opaque, - }; - - while (slirp_istream_read_u8(&f)) { - int ret; - struct socket *so = socreate(slirp, -1); - - ret = - slirp_vmstate_load_state(&f, &vmstate_slirp_socket, so, version_id); - if (ret < 0) { - return ret; - } - - if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) != - slirp->vnetwork_addr.s_addr) { - return -EINVAL; - } - for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->write_cb && - so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr && - so->so_fport == ex_ptr->ex_fport) { - break; - } - } - if (!ex_ptr) { - return -EINVAL; - } - - so->guestfwd = ex_ptr; - } - - return slirp_vmstate_load_state(&f, &vmstate_slirp, slirp, version_id); -} - -int slirp_state_version(void) -{ - return 4; -} diff --git a/src/network/slirp/stream.c b/src/network/slirp/stream.c deleted file mode 100644 index 541986e6c..000000000 --- a/src/network/slirp/stream.c +++ /dev/null @@ -1,120 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * libslirp io streams - * - * Copyright (c) 2018 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "stream.h" -#include - -bool slirp_istream_read(SlirpIStream *f, void *buf, size_t size) -{ - return f->read_cb(buf, size, f->opaque) == size; -} - -bool slirp_ostream_write(SlirpOStream *f, const void *buf, size_t size) -{ - return f->write_cb(buf, size, f->opaque) == size; -} - -uint8_t slirp_istream_read_u8(SlirpIStream *f) -{ - uint8_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return b; - } - - return 0; -} - -bool slirp_ostream_write_u8(SlirpOStream *f, uint8_t b) -{ - return slirp_ostream_write(f, &b, sizeof(b)); -} - -uint16_t slirp_istream_read_u16(SlirpIStream *f) -{ - uint16_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return GUINT16_FROM_BE(b); - } - - return 0; -} - -bool slirp_ostream_write_u16(SlirpOStream *f, uint16_t b) -{ - b = GUINT16_TO_BE(b); - return slirp_ostream_write(f, &b, sizeof(b)); -} - -uint32_t slirp_istream_read_u32(SlirpIStream *f) -{ - uint32_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return GUINT32_FROM_BE(b); - } - - return 0; -} - -bool slirp_ostream_write_u32(SlirpOStream *f, uint32_t b) -{ - b = GUINT32_TO_BE(b); - return slirp_ostream_write(f, &b, sizeof(b)); -} - -int16_t slirp_istream_read_i16(SlirpIStream *f) -{ - int16_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return GINT16_FROM_BE(b); - } - - return 0; -} - -bool slirp_ostream_write_i16(SlirpOStream *f, int16_t b) -{ - b = GINT16_TO_BE(b); - return slirp_ostream_write(f, &b, sizeof(b)); -} - -int32_t slirp_istream_read_i32(SlirpIStream *f) -{ - int32_t b; - - if (slirp_istream_read(f, &b, sizeof(b))) { - return GINT32_FROM_BE(b); - } - - return 0; -} - -bool slirp_ostream_write_i32(SlirpOStream *f, int32_t b) -{ - b = GINT32_TO_BE(b); - return slirp_ostream_write(f, &b, sizeof(b)); -} diff --git a/src/network/slirp/stream.h b/src/network/slirp/stream.h deleted file mode 100644 index 08bb5b661..000000000 --- a/src/network/slirp/stream.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#ifndef STREAM_H_ -#define STREAM_H_ - -#include "libslirp.h" - -typedef struct SlirpIStream { - SlirpReadCb read_cb; - void *opaque; -} SlirpIStream; - -typedef struct SlirpOStream { - SlirpWriteCb write_cb; - void *opaque; -} SlirpOStream; - -bool slirp_istream_read(SlirpIStream *f, void *buf, size_t size); -bool slirp_ostream_write(SlirpOStream *f, const void *buf, size_t size); - -uint8_t slirp_istream_read_u8(SlirpIStream *f); -bool slirp_ostream_write_u8(SlirpOStream *f, uint8_t b); - -uint16_t slirp_istream_read_u16(SlirpIStream *f); -bool slirp_ostream_write_u16(SlirpOStream *f, uint16_t b); - -uint32_t slirp_istream_read_u32(SlirpIStream *f); -bool slirp_ostream_write_u32(SlirpOStream *f, uint32_t b); - -int16_t slirp_istream_read_i16(SlirpIStream *f); -bool slirp_ostream_write_i16(SlirpOStream *f, int16_t b); - -int32_t slirp_istream_read_i32(SlirpIStream *f); -bool slirp_ostream_write_i32(SlirpOStream *f, int32_t b); - -#endif /* STREAM_H_ */ diff --git a/src/network/slirp/tcp.h b/src/network/slirp/tcp.h deleted file mode 100644 index 211dfec39..000000000 --- a/src/network/slirp/tcp.h +++ /dev/null @@ -1,169 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp.h 8.1 (Berkeley) 6/10/93 - * tcp.h,v 1.3 1994/08/21 05:27:34 paul Exp - */ - -#ifndef TCP_H -#define TCP_H - -#include - -typedef uint32_t tcp_seq; - -#define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */ -#define PR_FASTHZ 5 /* 5 fast timeouts per second (not important) */ - -#define TCP_SNDSPACE 1024 * 128 -#define TCP_RCVSPACE 1024 * 128 -#define TCP_MAXSEG_MAX 32768 - -/* - * TCP header. - * Per RFC 793, September, 1981. - */ -#define tcphdr slirp_tcphdr -struct tcphdr { - uint16_t th_sport; /* source port */ - uint16_t th_dport; /* destination port */ - tcp_seq th_seq; /* sequence number */ - tcp_seq th_ack; /* acknowledgement number */ -#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER) - uint8_t th_off : 4, /* data offset */ - th_x2 : 4; /* (unused) */ -#else - uint8_t th_x2 : 4, /* (unused) */ - th_off : 4; /* data offset */ -#endif - uint8_t th_flags; - uint16_t th_win; /* window */ - uint16_t th_sum; /* checksum */ - uint16_t th_urp; /* urgent pointer */ -}; - -#include "tcp_var.h" - -#ifndef TH_FIN -#define TH_FIN 0x01 -#define TH_SYN 0x02 -#define TH_RST 0x04 -#define TH_PUSH 0x08 -#define TH_ACK 0x10 -#define TH_URG 0x20 -#endif - -#ifndef TCPOPT_EOL -#define TCPOPT_EOL 0 -#define TCPOPT_NOP 1 -#define TCPOPT_MAXSEG 2 -#define TCPOPT_WINDOW 3 -#define TCPOPT_SACK_PERMITTED 4 /* Experimental */ -#define TCPOPT_SACK 5 /* Experimental */ -#define TCPOPT_TIMESTAMP 8 - -#define TCPOPT_TSTAMP_HDR \ - (TCPOPT_NOP << 24 | TCPOPT_NOP << 16 | TCPOPT_TIMESTAMP << 8 | \ - TCPOLEN_TIMESTAMP) -#endif - -#ifndef TCPOLEN_MAXSEG -#define TCPOLEN_MAXSEG 4 -#define TCPOLEN_WINDOW 3 -#define TCPOLEN_SACK_PERMITTED 2 -#define TCPOLEN_TIMESTAMP 10 -#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP + 2) /* appendix A */ -#endif - -#undef TCP_MAXWIN -#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ - -#undef TCP_MAX_WINSHIFT -#define TCP_MAX_WINSHIFT 14 /* maximum window shift */ - -/* - * User-settable options (used with setsockopt). - * - * We don't use the system headers on unix because we have conflicting - * local structures. We can't avoid the system definitions on Windows, - * so we undefine them. - */ -#undef TCP_NODELAY -#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ -#undef TCP_MAXSEG - -/* - * TCP FSM state definitions. - * Per RFC793, September, 1981. - */ - -#define TCP_NSTATES 11 - -#define TCPS_CLOSED 0 /* closed */ -#define TCPS_LISTEN 1 /* listening for connection */ -#define TCPS_SYN_SENT 2 /* active, have sent syn */ -#define TCPS_SYN_RECEIVED 3 /* have send and received syn */ -/* states < TCPS_ESTABLISHED are those where connections not established */ -#define TCPS_ESTABLISHED 4 /* established */ -#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ -/* states > TCPS_CLOSE_WAIT are those where user has closed */ -#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ -#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ -#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ -/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ -#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ -#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ - -#define TCPS_HAVERCVDSYN(s) ((s) >= TCPS_SYN_RECEIVED) -#define TCPS_HAVEESTABLISHED(s) ((s) >= TCPS_ESTABLISHED) -#define TCPS_HAVERCVDFIN(s) ((s) >= TCPS_TIME_WAIT) - -/* - * TCP sequence numbers are 32 bit integers operated - * on with modular arithmetic. These macros can be - * used to compare such integers. - */ -#define SEQ_LT(a, b) ((int)((a) - (b)) < 0) -#define SEQ_LEQ(a, b) ((int)((a) - (b)) <= 0) -#define SEQ_GT(a, b) ((int)((a) - (b)) > 0) -#define SEQ_GEQ(a, b) ((int)((a) - (b)) >= 0) - -/* - * Macros to initialize tcp sequence numbers for - * send and receive from initial send and receive - * sequence numbers. - */ -#define tcp_rcvseqinit(tp) (tp)->rcv_adv = (tp)->rcv_nxt = (tp)->irs + 1 - -#define tcp_sendseqinit(tp) \ - (tp)->snd_una = (tp)->snd_nxt = (tp)->snd_max = (tp)->snd_up = (tp)->iss - -#define TCP_ISSINCR (125 * 1024) /* increment for tcp_iss each second */ - -#endif diff --git a/src/network/slirp/tcp_input.c b/src/network/slirp/tcp_input.c deleted file mode 100644 index ecca972ee..000000000 --- a/src/network/slirp/tcp_input.c +++ /dev/null @@ -1,1552 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_input.c 8.5 (Berkeley) 4/10/94 - * tcp_input.c,v 1.10 1994/10/13 18:36:32 wollman Exp - */ - -/* - * Changes and additions relating to SLiRP - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" -#include "ip_icmp.h" - -#define TCPREXMTTHRESH 3 - -#define TCP_PAWS_IDLE (24 * 24 * 60 * 60 * PR_SLOWHZ) - -/* for modulo comparisons of timestamps */ -#define TSTMP_LT(a, b) ((int)((a) - (b)) < 0) -#define TSTMP_GEQ(a, b) ((int)((a) - (b)) >= 0) - -/* - * Insert segment ti into reassembly queue of tcp with - * control block tp. Return TH_FIN if reassembly now includes - * a segment with FIN. The macro form does the common case inline - * (segment is the next to be received on an established connection, - * and the queue is empty), avoiding linkage into and removal - * from the queue and repetition of various conversions. - * Set DELACK for segments received in order, but ack immediately - * when segments are out of order (so fast retransmit can work). - */ -#define TCP_REASS(tp, ti, m, so, flags) \ - { \ - if ((ti)->ti_seq == (tp)->rcv_nxt && tcpfrag_list_empty(tp) && \ - (tp)->t_state == TCPS_ESTABLISHED) { \ - tp->t_flags |= TF_DELACK; \ - (tp)->rcv_nxt += (ti)->ti_len; \ - flags = (ti)->ti_flags & TH_FIN; \ - if (so->so_emu) { \ - if (tcp_emu((so), (m))) \ - sbappend(so, (m)); \ - } else \ - sbappend((so), (m)); \ - } else { \ - (flags) = tcp_reass((tp), (ti), (m)); \ - tp->t_flags |= TF_ACKNOW; \ - } \ - } - -static void tcp_dooptions(struct tcpcb *tp, uint8_t *cp, int cnt, - struct tcpiphdr *ti); -static void tcp_xmit_timer(register struct tcpcb *tp, int rtt); - -static int tcp_reass(register struct tcpcb *tp, register struct tcpiphdr *ti, - struct mbuf *m) -{ - register struct tcpiphdr *q; - struct socket *so = tp->t_socket; - int flags; - - /* - * Call with ti==NULL after become established to - * force pre-ESTABLISHED data up to user socket. - */ - if (ti == NULL) - goto present; - - /* - * Find a segment which begins after this one does. - */ - for (q = tcpfrag_list_first(tp); !tcpfrag_list_end(q, tp); - q = tcpiphdr_next(q)) - if (SEQ_GT(q->ti_seq, ti->ti_seq)) - break; - - /* - * If there is a preceding segment, it may provide some of - * our data already. If so, drop the data from the incoming - * segment. If it provides all of our data, drop us. - */ - if (!tcpfrag_list_end(tcpiphdr_prev(q), tp)) { - register int i; - q = tcpiphdr_prev(q); - /* conversion to int (in i) handles seq wraparound */ - i = q->ti_seq + q->ti_len - ti->ti_seq; - if (i > 0) { - if (i >= ti->ti_len) { - m_free(m); - /* - * Try to present any queued data - * at the left window edge to the user. - * This is needed after the 3-WHS - * completes. - */ - goto present; /* ??? */ - } - m_adj(m, i); - ti->ti_len -= i; - ti->ti_seq += i; - } - q = tcpiphdr_next(q); - } - ti->ti_mbuf = m; - - /* - * While we overlap succeeding segments trim them or, - * if they are completely covered, dequeue them. - */ - while (!tcpfrag_list_end(q, tp)) { - register int i = (ti->ti_seq + ti->ti_len) - q->ti_seq; - if (i <= 0) - break; - if (i < q->ti_len) { - q->ti_seq += i; - q->ti_len -= i; - m_adj(q->ti_mbuf, i); - break; - } - q = tcpiphdr_next(q); - m = tcpiphdr_prev(q)->ti_mbuf; - slirp_remque(tcpiphdr2qlink(tcpiphdr_prev(q))); - m_free(m); - } - - /* - * Stick new segment in its place. - */ - slirp_insque(tcpiphdr2qlink(ti), tcpiphdr2qlink(tcpiphdr_prev(q))); - -present: - /* - * Present data to user, advancing rcv_nxt through - * completed sequence space. - */ - if (!TCPS_HAVEESTABLISHED(tp->t_state)) - return (0); - ti = tcpfrag_list_first(tp); - if (tcpfrag_list_end(ti, tp) || ti->ti_seq != tp->rcv_nxt) - return (0); - if (tp->t_state == TCPS_SYN_RECEIVED && ti->ti_len) - return (0); - do { - tp->rcv_nxt += ti->ti_len; - flags = ti->ti_flags & TH_FIN; - slirp_remque(tcpiphdr2qlink(ti)); - m = ti->ti_mbuf; - ti = tcpiphdr_next(ti); - if (so->so_state & SS_FCANTSENDMORE) - m_free(m); - else { - if (so->so_emu) { - if (tcp_emu(so, m)) - sbappend(so, m); - } else - sbappend(so, m); - } - } while (ti != (struct tcpiphdr *)tp && ti->ti_seq == tp->rcv_nxt); - return (flags); -} - -/* - * TCP input routine, follows pages 65-76 of the - * protocol specification dated September, 1981 very closely. - */ -void tcp_input(struct mbuf *m, int iphlen, struct socket *inso, - unsigned short af) -{ - struct ip save_ip, *ip; - struct ip6 save_ip6, *ip6; - register struct tcpiphdr *ti; - char *optp = NULL; - int optlen = 0; - int len, tlen, off; - register struct tcpcb *tp = NULL; - register int tiflags; - struct socket *so = NULL; - int todrop, acked, ourfinisacked, needoutput = 0; - int iss = 0; - uint32_t tiwin; - int ret; - struct sockaddr_storage lhost, fhost; - struct sockaddr_in *lhost4, *fhost4; - struct sockaddr_in6 *lhost6, *fhost6; - struct gfwd_list *ex_ptr; - Slirp *slirp; - - DEBUG_CALL("tcp_input"); - DEBUG_ARG("m = %p iphlen = %2d inso = %p", m, iphlen, inso); - - memset(&lhost, 0, sizeof(struct sockaddr_storage)); - memset(&fhost, 0, sizeof(struct sockaddr_storage)); - - /* - * If called with m == 0, then we're continuing the connect - */ - if (m == NULL) { - so = inso; - slirp = so->slirp; - - /* Re-set a few variables */ - tp = sototcpcb(so); - m = so->so_m; - so->so_m = NULL; - ti = so->so_ti; - tiwin = ti->ti_win; - tiflags = ti->ti_flags; - - goto cont_conn; - } - slirp = m->slirp; - switch (af) { - case AF_INET: - M_DUP_DEBUG(slirp, m, 0, - sizeof(struct tcpiphdr) - sizeof(struct ip) - sizeof(struct tcphdr)); - break; - case AF_INET6: - M_DUP_DEBUG(slirp, m, 0, - sizeof(struct tcpiphdr) - sizeof(struct ip6) - sizeof(struct tcphdr)); - break; - } - - ip = mtod(m, struct ip *); - ip6 = mtod(m, struct ip6 *); - - switch (af) { - case AF_INET: - if (iphlen > sizeof(struct ip)) { - ip_stripoptions(m, (struct mbuf *)0); - iphlen = sizeof(struct ip); - } - /* XXX Check if too short */ - - - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip = *ip; - save_ip.ip_len += iphlen; - - /* - * Get IP and TCP header together in first mbuf. - * Note: IP leaves IP header in first mbuf. - */ - m->m_data -= - sizeof(struct tcpiphdr) - sizeof(struct ip) - sizeof(struct tcphdr); - m->m_len += - sizeof(struct tcpiphdr) - sizeof(struct ip) - sizeof(struct tcphdr); - ti = mtod(m, struct tcpiphdr *); - - /* - * Checksum extended TCP header and data. - */ - tlen = ip->ip_len; - tcpiphdr2qlink(ti)->next = tcpiphdr2qlink(ti)->prev = NULL; - memset(&ti->ih_mbuf, 0, sizeof(struct mbuf_ptr)); - memset(&ti->ti, 0, sizeof(ti->ti)); - ti->ti_x0 = 0; - ti->ti_src = save_ip.ip_src; - ti->ti_dst = save_ip.ip_dst; - ti->ti_pr = save_ip.ip_p; - ti->ti_len = htons((uint16_t)tlen); - break; - - case AF_INET6: - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip6 = *ip6; - /* - * Get IP and TCP header together in first mbuf. - * Note: IP leaves IP header in first mbuf. - */ - m->m_data -= sizeof(struct tcpiphdr) - - (sizeof(struct ip6) + sizeof(struct tcphdr)); - m->m_len += sizeof(struct tcpiphdr) - - (sizeof(struct ip6) + sizeof(struct tcphdr)); - ti = mtod(m, struct tcpiphdr *); - - tlen = ip6->ip_pl; - tcpiphdr2qlink(ti)->next = tcpiphdr2qlink(ti)->prev = NULL; - memset(&ti->ih_mbuf, 0, sizeof(struct mbuf_ptr)); - memset(&ti->ti, 0, sizeof(ti->ti)); - ti->ti_x0 = 0; - ti->ti_src6 = save_ip6.ip_src; - ti->ti_dst6 = save_ip6.ip_dst; - ti->ti_nh6 = save_ip6.ip_nh; - ti->ti_len = htons((uint16_t)tlen); - break; - - default: - g_assert_not_reached(); - } - - len = ((sizeof(struct tcpiphdr) - sizeof(struct tcphdr)) + tlen); - if (cksum(m, len)) { - goto drop; - } - - /* - * Check that TCP offset makes sense, - * pull out TCP options and adjust length. XXX - */ - off = ti->ti_off << 2; - if (off < sizeof(struct tcphdr) || off > tlen) { - goto drop; - } - tlen -= off; - ti->ti_len = tlen; - if (off > sizeof(struct tcphdr)) { - optlen = off - sizeof(struct tcphdr); - optp = mtod(m, char *) + sizeof(struct tcpiphdr); - } - tiflags = ti->ti_flags; - - /* - * Convert TCP protocol specific fields to host format. - */ - NTOHL(ti->ti_seq); - NTOHL(ti->ti_ack); - NTOHS(ti->ti_win); - NTOHS(ti->ti_urp); - - /* - * Drop TCP, IP headers and TCP options. - */ - m->m_data += sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); - m->m_len -= sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); - - /* - * Locate pcb for segment. - */ -findso: - lhost.ss_family = af; - fhost.ss_family = af; - switch (af) { - case AF_INET: - lhost4 = (struct sockaddr_in *)&lhost; - lhost4->sin_addr = ti->ti_src; - lhost4->sin_port = ti->ti_sport; - fhost4 = (struct sockaddr_in *)&fhost; - fhost4->sin_addr = ti->ti_dst; - fhost4->sin_port = ti->ti_dport; - break; - case AF_INET6: - lhost6 = (struct sockaddr_in6 *)&lhost; - lhost6->sin6_addr = ti->ti_src6; - lhost6->sin6_port = ti->ti_sport; - fhost6 = (struct sockaddr_in6 *)&fhost; - fhost6->sin6_addr = ti->ti_dst6; - fhost6->sin6_port = ti->ti_dport; - break; - default: - g_assert_not_reached(); - } - - so = solookup(&slirp->tcp_last_so, &slirp->tcb, &lhost, &fhost); - - /* - * If the state is CLOSED (i.e., TCB does not exist) then - * all data in the incoming segment is discarded. - * If the TCB exists but is in CLOSED state, it is embryonic, - * but should either do a listen or a connect soon. - * - * state == CLOSED means we've done socreate() but haven't - * attached it to a protocol yet... - * - * XXX If a TCB does not exist, and the TH_SYN flag is - * the only flag set, then create a session, mark it - * as if it was LISTENING, and continue... - */ - if (so == NULL) { - /* TODO: IPv6 */ - if (slirp->restricted) { - /* Any hostfwds will have an existing socket, so we only get here - * for non-hostfwd connections. These should be dropped, unless it - * happens to be a guestfwd. - */ - for (ex_ptr = slirp->guestfwd_list; ex_ptr; - ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_fport == ti->ti_dport && - ti->ti_dst.s_addr == ex_ptr->ex_addr.s_addr) { - break; - } - } - if (!ex_ptr) { - goto dropwithreset; - } - } - - if ((tiflags & (TH_SYN | TH_FIN | TH_RST | TH_URG | TH_ACK)) != TH_SYN) - goto dropwithreset; - - so = socreate(slirp, IPPROTO_TCP); - tcp_attach(so); - - sbreserve(&so->so_snd, TCP_SNDSPACE); - sbreserve(&so->so_rcv, TCP_RCVSPACE); - - so->lhost.ss = lhost; - so->fhost.ss = fhost; - - so->so_iptos = tcp_tos(so); - if (so->so_iptos == 0) { - switch (af) { - case AF_INET: - so->so_iptos = ((struct ip *)ti)->ip_tos; - break; - case AF_INET6: - break; - default: - g_assert_not_reached(); - } - } - - tp = sototcpcb(so); - tp->t_state = TCPS_LISTEN; - } - - /* - * If this is a still-connecting socket, this probably - * a retransmit of the SYN. Whether it's a retransmit SYN - * or something else, we nuke it. - */ - if (so->so_state & SS_ISFCONNECTING) - goto drop; - - tp = sototcpcb(so); - - /* XXX Should never fail */ - if (tp == NULL) - goto dropwithreset; - if (tp->t_state == TCPS_CLOSED) - goto drop; - - tiwin = ti->ti_win; - - /* - * Segment received on connection. - * Reset idle time and keep-alive timer. - */ - tp->t_idle = 0; - if (slirp_do_keepalive) - tp->t_timer[TCPT_KEEP] = TCPTV_KEEPINTVL; - else - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_IDLE; - - /* - * Process options if not in LISTEN state, - * else do it below (after getting remote address). - */ - if (optp && tp->t_state != TCPS_LISTEN) - tcp_dooptions(tp, (uint8_t *)optp, optlen, ti); - - /* - * Header prediction: check for the two common cases - * of a uni-directional data xfer. If the packet has - * no control flags, is in-sequence, the window didn't - * change and we're not retransmitting, it's a - * candidate. If the length is zero and the ack moved - * forward, we're the sender side of the xfer. Just - * free the data acked & wake any higher level process - * that was blocked waiting for space. If the length - * is non-zero and the ack didn't move, we're the - * receiver side. If we're getting packets in-order - * (the reassembly queue is empty), add the data to - * the socket buffer and note that we need a delayed ack. - * - * XXX Some of these tests are not needed - * eg: the tiwin == tp->snd_wnd prevents many more - * predictions.. with no *real* advantage.. - */ - if (tp->t_state == TCPS_ESTABLISHED && - (tiflags & (TH_SYN | TH_FIN | TH_RST | TH_URG | TH_ACK)) == TH_ACK && - ti->ti_seq == tp->rcv_nxt && tiwin && tiwin == tp->snd_wnd && - tp->snd_nxt == tp->snd_max) { - if (ti->ti_len == 0) { - if (SEQ_GT(ti->ti_ack, tp->snd_una) && - SEQ_LEQ(ti->ti_ack, tp->snd_max) && - tp->snd_cwnd >= tp->snd_wnd) { - /* - * this is a pure ack for outstanding data. - */ - if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq)) - tcp_xmit_timer(tp, tp->t_rtt); - acked = ti->ti_ack - tp->snd_una; - sodrop(so, acked); - tp->snd_una = ti->ti_ack; - m_free(m); - - /* - * If all outstanding data are acked, stop - * retransmit timer, otherwise restart timer - * using current (possibly backed-off) value. - * If process is waiting for space, - * wakeup/selwakeup/signal. If data - * are ready to send, let tcp_output - * decide between more output or persist. - */ - if (tp->snd_una == tp->snd_max) - tp->t_timer[TCPT_REXMT] = 0; - else if (tp->t_timer[TCPT_PERSIST] == 0) - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - - /* - * This is called because sowwakeup might have - * put data into so_snd. Since we don't so sowwakeup, - * we don't need this.. XXX??? - */ - if (so->so_snd.sb_cc) - tcp_output(tp); - - return; - } - } else if (ti->ti_ack == tp->snd_una && tcpfrag_list_empty(tp) && - ti->ti_len <= sbspace(&so->so_rcv)) { - /* - * this is a pure, in-sequence data packet - * with nothing on the reassembly queue and - * we have enough buffer space to take it. - */ - tp->rcv_nxt += ti->ti_len; - /* - * Add data to socket buffer. - */ - if (so->so_emu) { - if (tcp_emu(so, m)) - sbappend(so, m); - } else - sbappend(so, m); - - /* - * If this is a short packet, then ACK now - with Nagel - * congestion avoidance sender won't send more until - * he gets an ACK. - * - * It is better to not delay acks at all to maximize - * TCP throughput. See RFC 2581. - */ - tp->t_flags |= TF_ACKNOW; - tcp_output(tp); - return; - } - } /* header prediction */ - /* - * Calculate amount of space in receive window, - * and then do TCP input processing. - * Receive window is amount of space in rcv queue, - * but not less than advertised window. - */ - { - int win; - win = sbspace(&so->so_rcv); - if (win < 0) - win = 0; - tp->rcv_wnd = MAX(win, (int)(tp->rcv_adv - tp->rcv_nxt)); - } - - switch (tp->t_state) { - /* - * If the state is LISTEN then ignore segment if it contains an RST. - * If the segment contains an ACK then it is bad and send a RST. - * If it does not contain a SYN then it is not interesting; drop it. - * Don't bother responding if the destination was a broadcast. - * Otherwise initialize tp->rcv_nxt, and tp->irs, select an initial - * tp->iss, and send a segment: - * - * Also initialize tp->snd_nxt to tp->iss+1 and tp->snd_una to tp->iss. - * Fill in remote peer address fields if not previously specified. - * Enter SYN_RECEIVED state, and process any other fields of this - * segment in this state. - */ - case TCPS_LISTEN: { - if (tiflags & TH_RST) - goto drop; - if (tiflags & TH_ACK) - goto dropwithreset; - if ((tiflags & TH_SYN) == 0) - goto drop; - - /* - * This has way too many gotos... - * But a bit of spaghetti code never hurt anybody :) - */ - - /* - * If this is destined for the control address, then flag to - * tcp_ctl once connected, otherwise connect - */ - /* TODO: IPv6 */ - if (af == AF_INET && - (so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) == - slirp->vnetwork_addr.s_addr) { - if (so->so_faddr.s_addr != slirp->vhost_addr.s_addr && - so->so_faddr.s_addr != slirp->vnameserver_addr.s_addr) { - /* May be an add exec */ - for (ex_ptr = slirp->guestfwd_list; ex_ptr; - ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_fport == so->so_fport && - so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { - so->so_state |= SS_CTL; - break; - } - } - if (so->so_state & SS_CTL) { - goto cont_input; - } - } - /* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */ - } - - if (so->so_emu & EMU_NOCONNECT) { - so->so_emu &= ~EMU_NOCONNECT; - goto cont_input; - } - - if ((tcp_fconnect(so, so->so_ffamily) == -1) && (errno != EAGAIN) && - (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) { - uint8_t code; - DEBUG_MISC(" tcp fconnect errno = %d-%s", errno, strerror(errno)); - if (errno == ECONNREFUSED) { - /* ACK the SYN, send RST to refuse the connection */ - tcp_respond(tp, ti, m, ti->ti_seq + 1, (tcp_seq)0, - TH_RST | TH_ACK, af); - } else { - switch (af) { - case AF_INET: - code = ICMP_UNREACH_NET; - if (errno == EHOSTUNREACH) { - code = ICMP_UNREACH_HOST; - } - break; - case AF_INET6: - code = ICMP6_UNREACH_NO_ROUTE; - if (errno == EHOSTUNREACH) { - code = ICMP6_UNREACH_ADDRESS; - } - break; - default: - g_assert_not_reached(); - } - HTONL(ti->ti_seq); /* restore tcp header */ - HTONL(ti->ti_ack); - HTONS(ti->ti_win); - HTONS(ti->ti_urp); - m->m_data -= - sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); - m->m_len += - sizeof(struct tcpiphdr) + off - sizeof(struct tcphdr); - switch (af) { - case AF_INET: - m->m_data += sizeof(struct tcpiphdr) - sizeof(struct ip) - - sizeof(struct tcphdr); - m->m_len -= sizeof(struct tcpiphdr) - sizeof(struct ip) - - sizeof(struct tcphdr); - *ip = save_ip; - icmp_send_error(m, ICMP_UNREACH, code, 0, strerror(errno)); - break; - case AF_INET6: - m->m_data += sizeof(struct tcpiphdr) - - (sizeof(struct ip6) + sizeof(struct tcphdr)); - m->m_len -= sizeof(struct tcpiphdr) - - (sizeof(struct ip6) + sizeof(struct tcphdr)); - *ip6 = save_ip6; - icmp6_send_error(m, ICMP6_UNREACH, code); - break; - default: - g_assert_not_reached(); - } - } - tcp_close(tp); - m_free(m); - } else { - /* - * Haven't connected yet, save the current mbuf - * and ti, and return - * XXX Some OS's don't tell us whether the connect() - * succeeded or not. So we must time it out. - */ - so->so_m = m; - so->so_ti = ti; - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - tp->t_state = TCPS_SYN_RECEIVED; - /* - * Initialize receive sequence numbers now so that we can send a - * valid RST if the remote end rejects our connection. - */ - tp->irs = ti->ti_seq; - tcp_rcvseqinit(tp); - tcp_template(tp); - } - return; - - cont_conn: - /* m==NULL - * Check if the connect succeeded - */ - if (so->so_state & SS_NOFDREF) { - tp = tcp_close(tp); - goto dropwithreset; - } - cont_input: - tcp_template(tp); - - if (optp) - tcp_dooptions(tp, (uint8_t *)optp, optlen, ti); - - if (iss) - tp->iss = iss; - else - tp->iss = slirp->tcp_iss; - slirp->tcp_iss += TCP_ISSINCR / 2; - tp->irs = ti->ti_seq; - tcp_sendseqinit(tp); - tcp_rcvseqinit(tp); - tp->t_flags |= TF_ACKNOW; - tp->t_state = TCPS_SYN_RECEIVED; - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - goto trimthenstep6; - } /* case TCPS_LISTEN */ - - /* - * If the state is SYN_SENT: - * if seg contains an ACK, but not for our SYN, drop the input. - * if seg contains a RST, then drop the connection. - * if seg does not contain SYN, then drop it. - * Otherwise this is an acceptable SYN segment - * initialize tp->rcv_nxt and tp->irs - * if seg contains ack then advance tp->snd_una - * if SYN has been acked change to ESTABLISHED else SYN_RCVD state - * arrange for segment to be acked (eventually) - * continue processing rest of data/controls, beginning with URG - */ - case TCPS_SYN_SENT: - if ((tiflags & TH_ACK) && - (SEQ_LEQ(ti->ti_ack, tp->iss) || SEQ_GT(ti->ti_ack, tp->snd_max))) - goto dropwithreset; - - if (tiflags & TH_RST) { - if (tiflags & TH_ACK) { - tcp_drop(tp, 0); /* XXX Check t_softerror! */ - } - goto drop; - } - - if ((tiflags & TH_SYN) == 0) - goto drop; - if (tiflags & TH_ACK) { - tp->snd_una = ti->ti_ack; - if (SEQ_LT(tp->snd_nxt, tp->snd_una)) - tp->snd_nxt = tp->snd_una; - } - - tp->t_timer[TCPT_REXMT] = 0; - tp->irs = ti->ti_seq; - tcp_rcvseqinit(tp); - tp->t_flags |= TF_ACKNOW; - if (tiflags & TH_ACK && SEQ_GT(tp->snd_una, tp->iss)) { - soisfconnected(so); - tp->t_state = TCPS_ESTABLISHED; - - tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0); - /* - * if we didn't have to retransmit the SYN, - * use its rtt as our initial srtt & rtt var. - */ - if (tp->t_rtt) - tcp_xmit_timer(tp, tp->t_rtt); - } else - tp->t_state = TCPS_SYN_RECEIVED; - - trimthenstep6: - /* - * Advance ti->ti_seq to correspond to first data byte. - * If data, trim to stay within window, - * dropping FIN if necessary. - */ - ti->ti_seq++; - if (ti->ti_len > tp->rcv_wnd) { - todrop = ti->ti_len - tp->rcv_wnd; - m_adj(m, -todrop); - ti->ti_len = tp->rcv_wnd; - tiflags &= ~TH_FIN; - } - tp->snd_wl1 = ti->ti_seq - 1; - tp->rcv_up = ti->ti_seq; - goto step6; - } /* switch tp->t_state */ - /* - * States other than LISTEN or SYN_SENT. - * Check that at least some bytes of segment are within - * receive window. If segment begins before rcv_nxt, - * drop leading data (and SYN); if nothing left, just ack. - */ - todrop = tp->rcv_nxt - ti->ti_seq; - if (todrop > 0) { - if (tiflags & TH_SYN) { - tiflags &= ~TH_SYN; - ti->ti_seq++; - if (ti->ti_urp > 1) - ti->ti_urp--; - else - tiflags &= ~TH_URG; - todrop--; - } - /* - * Following if statement from Stevens, vol. 2, p. 960. - */ - if (todrop > ti->ti_len || - (todrop == ti->ti_len && (tiflags & TH_FIN) == 0)) { - /* - * Any valid FIN must be to the left of the window. - * At this point the FIN must be a duplicate or out - * of sequence; drop it. - */ - tiflags &= ~TH_FIN; - - /* - * Send an ACK to resynchronize and drop any data. - * But keep on processing for RST or ACK. - */ - tp->t_flags |= TF_ACKNOW; - todrop = ti->ti_len; - } - m_adj(m, todrop); - ti->ti_seq += todrop; - ti->ti_len -= todrop; - if (ti->ti_urp > todrop) - ti->ti_urp -= todrop; - else { - tiflags &= ~TH_URG; - ti->ti_urp = 0; - } - } - /* - * If new data are received on a connection after the - * user processes are gone, then RST the other end. - */ - if ((so->so_state & SS_NOFDREF) && tp->t_state > TCPS_CLOSE_WAIT && - ti->ti_len) { - tp = tcp_close(tp); - goto dropwithreset; - } - - /* - * If segment ends after window, drop trailing data - * (and PUSH and FIN); if nothing left, just ACK. - */ - todrop = (ti->ti_seq + ti->ti_len) - (tp->rcv_nxt + tp->rcv_wnd); - if (todrop > 0) { - if (todrop >= ti->ti_len) { - /* - * If a new connection request is received - * while in TIME_WAIT, drop the old connection - * and start over if the sequence numbers - * are above the previous ones. - */ - if (tiflags & TH_SYN && tp->t_state == TCPS_TIME_WAIT && - SEQ_GT(ti->ti_seq, tp->rcv_nxt)) { - iss = tp->rcv_nxt + TCP_ISSINCR; - tp = tcp_close(tp); - goto findso; - } - /* - * If window is closed can only take segments at - * window edge, and have to drop data and PUSH from - * incoming segments. Continue processing, but - * remember to ack. Otherwise, drop segment - * and ack. - */ - if (tp->rcv_wnd == 0 && ti->ti_seq == tp->rcv_nxt) { - tp->t_flags |= TF_ACKNOW; - } else { - goto dropafterack; - } - } - m_adj(m, -todrop); - ti->ti_len -= todrop; - tiflags &= ~(TH_PUSH | TH_FIN); - } - - /* - * If the RST bit is set examine the state: - * SYN_RECEIVED STATE: - * If passive open, return to LISTEN state. - * If active open, inform user that connection was refused. - * ESTABLISHED, FIN_WAIT_1, FIN_WAIT2, CLOSE_WAIT STATES: - * Inform user that connection was reset, and close tcb. - * CLOSING, LAST_ACK, TIME_WAIT STATES - * Close the tcb. - */ - if (tiflags & TH_RST) - switch (tp->t_state) { - case TCPS_SYN_RECEIVED: - case TCPS_ESTABLISHED: - case TCPS_FIN_WAIT_1: - case TCPS_FIN_WAIT_2: - case TCPS_CLOSE_WAIT: - tp->t_state = TCPS_CLOSED; - tcp_close(tp); - goto drop; - - case TCPS_CLOSING: - case TCPS_LAST_ACK: - case TCPS_TIME_WAIT: - tcp_close(tp); - goto drop; - } - - /* - * If a SYN is in the window, then this is an - * error and we send an RST and drop the connection. - */ - if (tiflags & TH_SYN) { - tp = tcp_drop(tp, 0); - goto dropwithreset; - } - - /* - * If the ACK bit is off we drop the segment and return. - */ - if ((tiflags & TH_ACK) == 0) - goto drop; - - /* - * Ack processing. - */ - switch (tp->t_state) { - /* - * In SYN_RECEIVED state if the ack ACKs our SYN then enter - * ESTABLISHED state and continue processing, otherwise - * send an RST. una<=ack<=max - */ - case TCPS_SYN_RECEIVED: - - if (SEQ_GT(tp->snd_una, ti->ti_ack) || SEQ_GT(ti->ti_ack, tp->snd_max)) - goto dropwithreset; - tp->t_state = TCPS_ESTABLISHED; - /* - * The sent SYN is ack'ed with our sequence number +1 - * The first data byte already in the buffer will get - * lost if no correction is made. This is only needed for - * SS_CTL since the buffer is empty otherwise. - * tp->snd_una++; or: - */ - tp->snd_una = ti->ti_ack; - if (so->so_state & SS_CTL) { - /* So tcp_ctl reports the right state */ - ret = tcp_ctl(so); - if (ret == 1) { - soisfconnected(so); - so->so_state &= ~SS_CTL; /* success XXX */ - } else if (ret == 2) { - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_NOFDREF; /* CTL_CMD */ - } else { - needoutput = 1; - tp->t_state = TCPS_FIN_WAIT_1; - } - } else { - soisfconnected(so); - } - - tcp_reass(tp, (struct tcpiphdr *)0, (struct mbuf *)0); - tp->snd_wl1 = ti->ti_seq - 1; - /* Avoid ack processing; snd_una==ti_ack => dup ack */ - goto synrx_to_est; - /* fall into ... */ - - /* - * In ESTABLISHED state: drop duplicate ACKs; ACK out of range - * ACKs. If the ack is in the range - * tp->snd_una < ti->ti_ack <= tp->snd_max - * then advance tp->snd_una to ti->ti_ack and drop - * data from the retransmission queue. If this ACK reflects - * more up to date window information we update our window information. - */ - case TCPS_ESTABLISHED: - case TCPS_FIN_WAIT_1: - case TCPS_FIN_WAIT_2: - case TCPS_CLOSE_WAIT: - case TCPS_CLOSING: - case TCPS_LAST_ACK: - case TCPS_TIME_WAIT: - - if (SEQ_LEQ(ti->ti_ack, tp->snd_una)) { - if (ti->ti_len == 0 && tiwin == tp->snd_wnd) { - DEBUG_MISC(" dup ack m = %p so = %p", m, so); - /* - * If we have outstanding data (other than - * a window probe), this is a completely - * duplicate ack (ie, window info didn't - * change), the ack is the biggest we've - * seen and we've seen exactly our rexmt - * threshold of them, assume a packet - * has been dropped and retransmit it. - * Kludge snd_nxt & the congestion - * window so we send only this one - * packet. - * - * We know we're losing at the current - * window size so do congestion avoidance - * (set ssthresh to half the current window - * and pull our congestion window back to - * the new ssthresh). - * - * Dup acks mean that packets have left the - * network (they're now cached at the receiver) - * so bump cwnd by the amount in the receiver - * to keep a constant cwnd packets in the - * network. - */ - if (tp->t_timer[TCPT_REXMT] == 0 || ti->ti_ack != tp->snd_una) - tp->t_dupacks = 0; - else if (++tp->t_dupacks == TCPREXMTTHRESH) { - tcp_seq onxt = tp->snd_nxt; - unsigned win = - MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg; - - if (win < 2) - win = 2; - tp->snd_ssthresh = win * tp->t_maxseg; - tp->t_timer[TCPT_REXMT] = 0; - tp->t_rtt = 0; - tp->snd_nxt = ti->ti_ack; - tp->snd_cwnd = tp->t_maxseg; - tcp_output(tp); - tp->snd_cwnd = - tp->snd_ssthresh + tp->t_maxseg * tp->t_dupacks; - if (SEQ_GT(onxt, tp->snd_nxt)) - tp->snd_nxt = onxt; - goto drop; - } else if (tp->t_dupacks > TCPREXMTTHRESH) { - tp->snd_cwnd += tp->t_maxseg; - tcp_output(tp); - goto drop; - } - } else - tp->t_dupacks = 0; - break; - } - synrx_to_est: - /* - * If the congestion window was inflated to account - * for the other side's cached packets, retract it. - */ - if (tp->t_dupacks > TCPREXMTTHRESH && tp->snd_cwnd > tp->snd_ssthresh) - tp->snd_cwnd = tp->snd_ssthresh; - tp->t_dupacks = 0; - if (SEQ_GT(ti->ti_ack, tp->snd_max)) { - goto dropafterack; - } - acked = ti->ti_ack - tp->snd_una; - - /* - * If transmit timer is running and timed sequence - * number was acked, update smoothed round trip time. - * Since we now have an rtt measurement, cancel the - * timer backoff (cf., Phil Karn's retransmit alg.). - * Recompute the initial retransmit timer. - */ - if (tp->t_rtt && SEQ_GT(ti->ti_ack, tp->t_rtseq)) - tcp_xmit_timer(tp, tp->t_rtt); - - /* - * If all outstanding data is acked, stop retransmit - * timer and remember to restart (more output or persist). - * If there is more data to be acked, restart retransmit - * timer, using current (possibly backed-off) value. - */ - if (ti->ti_ack == tp->snd_max) { - tp->t_timer[TCPT_REXMT] = 0; - needoutput = 1; - } else if (tp->t_timer[TCPT_PERSIST] == 0) - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - /* - * When new data is acked, open the congestion window. - * If the window gives us less than ssthresh packets - * in flight, open exponentially (maxseg per packet). - * Otherwise open linearly: maxseg per window - * (maxseg^2 / cwnd per packet). - */ - { - register unsigned cw = tp->snd_cwnd; - register unsigned incr = tp->t_maxseg; - - if (cw > tp->snd_ssthresh) - incr = incr * incr / cw; - tp->snd_cwnd = MIN(cw + incr, TCP_MAXWIN << tp->snd_scale); - } - if (acked > so->so_snd.sb_cc) { - tp->snd_wnd -= so->so_snd.sb_cc; - sodrop(so, (int)so->so_snd.sb_cc); - ourfinisacked = 1; - } else { - sodrop(so, acked); - tp->snd_wnd -= acked; - ourfinisacked = 0; - } - tp->snd_una = ti->ti_ack; - if (SEQ_LT(tp->snd_nxt, tp->snd_una)) - tp->snd_nxt = tp->snd_una; - - switch (tp->t_state) { - /* - * In FIN_WAIT_1 STATE in addition to the processing - * for the ESTABLISHED state if our FIN is now acknowledged - * then enter FIN_WAIT_2. - */ - case TCPS_FIN_WAIT_1: - if (ourfinisacked) { - /* - * If we can't receive any more - * data, then closing user can proceed. - * Starting the timer is contrary to the - * specification, but if we don't get a FIN - * we'll hang forever. - */ - if (so->so_state & SS_FCANTRCVMORE) { - tp->t_timer[TCPT_2MSL] = TCP_MAXIDLE; - } - tp->t_state = TCPS_FIN_WAIT_2; - } - break; - - /* - * In CLOSING STATE in addition to the processing for - * the ESTABLISHED state if the ACK acknowledges our FIN - * then enter the TIME-WAIT state, otherwise ignore - * the segment. - */ - case TCPS_CLOSING: - if (ourfinisacked) { - tp->t_state = TCPS_TIME_WAIT; - tcp_canceltimers(tp); - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; - } - break; - - /* - * In LAST_ACK, we may still be waiting for data to drain - * and/or to be acked, as well as for the ack of our FIN. - * If our FIN is now acknowledged, delete the TCB, - * enter the closed state and return. - */ - case TCPS_LAST_ACK: - if (ourfinisacked) { - tcp_close(tp); - goto drop; - } - break; - - /* - * In TIME_WAIT state the only thing that should arrive - * is a retransmission of the remote FIN. Acknowledge - * it and restart the finack timer. - */ - case TCPS_TIME_WAIT: - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; - goto dropafterack; - } - } /* switch(tp->t_state) */ - -step6: - /* - * Update window information. - * Don't look at window if no ACK: TAC's send garbage on first SYN. - */ - if ((tiflags & TH_ACK) && - (SEQ_LT(tp->snd_wl1, ti->ti_seq) || - (tp->snd_wl1 == ti->ti_seq && - (SEQ_LT(tp->snd_wl2, ti->ti_ack) || - (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))))) { - tp->snd_wnd = tiwin; - tp->snd_wl1 = ti->ti_seq; - tp->snd_wl2 = ti->ti_ack; - if (tp->snd_wnd > tp->max_sndwnd) - tp->max_sndwnd = tp->snd_wnd; - needoutput = 1; - } - - /* - * Process segments with URG. - */ - if ((tiflags & TH_URG) && ti->ti_urp && - TCPS_HAVERCVDFIN(tp->t_state) == 0) { - /* - * This is a kludge, but if we receive and accept - * random urgent pointers, we'll crash in - * soreceive. It's hard to imagine someone - * actually wanting to send this much urgent data. - */ - if (ti->ti_urp + so->so_rcv.sb_cc > so->so_rcv.sb_datalen) { - ti->ti_urp = 0; - tiflags &= ~TH_URG; - goto dodata; - } - /* - * If this segment advances the known urgent pointer, - * then mark the data stream. This should not happen - * in CLOSE_WAIT, CLOSING, LAST_ACK or TIME_WAIT STATES since - * a FIN has been received from the remote side. - * In these states we ignore the URG. - * - * According to RFC961 (Assigned Protocols), - * the urgent pointer points to the last octet - * of urgent data. We continue, however, - * to consider it to indicate the first octet - * of data past the urgent section as the original - * spec states (in one of two places). - */ - if (SEQ_GT(ti->ti_seq + ti->ti_urp, tp->rcv_up)) { - tp->rcv_up = ti->ti_seq + ti->ti_urp; - so->so_urgc = - so->so_rcv.sb_cc + (tp->rcv_up - tp->rcv_nxt); /* -1; */ - tp->rcv_up = ti->ti_seq + ti->ti_urp; - } - } else - /* - * If no out of band data is expected, - * pull receive urgent pointer along - * with the receive window. - */ - if (SEQ_GT(tp->rcv_nxt, tp->rcv_up)) - tp->rcv_up = tp->rcv_nxt; -dodata: - - /* - * If this is a small packet, then ACK now - with Nagel - * congestion avoidance sender won't send more until - * he gets an ACK. - */ - if (ti->ti_len && (unsigned)ti->ti_len <= 5 && - ((struct tcpiphdr_2 *)ti)->first_char == (char)27) { - tp->t_flags |= TF_ACKNOW; - } - - /* - * Process the segment text, merging it into the TCP sequencing queue, - * and arranging for acknowledgment of receipt if necessary. - * This process logically involves adjusting tp->rcv_wnd as data - * is presented to the user (this happens in tcp_usrreq.c, - * case PRU_RCVD). If a FIN has already been received on this - * connection then we just ignore the text. - */ - if ((ti->ti_len || (tiflags & TH_FIN)) && - TCPS_HAVERCVDFIN(tp->t_state) == 0) { - TCP_REASS(tp, ti, m, so, tiflags); - } else { - m_free(m); - tiflags &= ~TH_FIN; - } - - /* - * If FIN is received ACK the FIN and let the user know - * that the connection is closing. - */ - if (tiflags & TH_FIN) { - if (TCPS_HAVERCVDFIN(tp->t_state) == 0) { - /* - * If we receive a FIN we can't send more data, - * set it SS_FDRAIN - * Shutdown the socket if there is no rx data in the - * buffer. - * soread() is called on completion of shutdown() and - * will got to TCPS_LAST_ACK, and use tcp_output() - * to send the FIN. - */ - sofwdrain(so); - - tp->t_flags |= TF_ACKNOW; - tp->rcv_nxt++; - } - switch (tp->t_state) { - /* - * In SYN_RECEIVED and ESTABLISHED STATES - * enter the CLOSE_WAIT state. - */ - case TCPS_SYN_RECEIVED: - case TCPS_ESTABLISHED: - if (so->so_emu == EMU_CTL) /* no shutdown on socket */ - tp->t_state = TCPS_LAST_ACK; - else - tp->t_state = TCPS_CLOSE_WAIT; - break; - - /* - * If still in FIN_WAIT_1 STATE FIN has not been acked so - * enter the CLOSING state. - */ - case TCPS_FIN_WAIT_1: - tp->t_state = TCPS_CLOSING; - break; - - /* - * In FIN_WAIT_2 state enter the TIME_WAIT state, - * starting the time-wait timer, turning off the other - * standard timers. - */ - case TCPS_FIN_WAIT_2: - tp->t_state = TCPS_TIME_WAIT; - tcp_canceltimers(tp); - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; - break; - - /* - * In TIME_WAIT state restart the 2 MSL time_wait timer. - */ - case TCPS_TIME_WAIT: - tp->t_timer[TCPT_2MSL] = 2 * TCPTV_MSL; - break; - } - } - - /* - * Return any desired output. - */ - if (needoutput || (tp->t_flags & TF_ACKNOW)) { - tcp_output(tp); - } - return; - -dropafterack: - /* - * Generate an ACK dropping incoming segment if it occupies - * sequence space, where the ACK reflects our state. - */ - if (tiflags & TH_RST) - goto drop; - m_free(m); - tp->t_flags |= TF_ACKNOW; - tcp_output(tp); - return; - -dropwithreset: - /* reuses m if m!=NULL, m_free() unnecessary */ - if (tiflags & TH_ACK) - tcp_respond(tp, ti, m, (tcp_seq)0, ti->ti_ack, TH_RST, af); - else { - if (tiflags & TH_SYN) - ti->ti_len++; - tcp_respond(tp, ti, m, ti->ti_seq + ti->ti_len, (tcp_seq)0, - TH_RST | TH_ACK, af); - } - - return; - -drop: - /* - * Drop space held by incoming segment and return. - */ - m_free(m); -} - -static void tcp_dooptions(struct tcpcb *tp, uint8_t *cp, int cnt, - struct tcpiphdr *ti) -{ - uint16_t mss; - int opt, optlen; - - DEBUG_CALL("tcp_dooptions"); - DEBUG_ARG("tp = %p cnt=%i", tp, cnt); - - for (; cnt > 0; cnt -= optlen, cp += optlen) { - opt = cp[0]; - if (opt == TCPOPT_EOL) - break; - if (opt == TCPOPT_NOP) - optlen = 1; - else { - optlen = cp[1]; - if (optlen <= 0) - break; - } - switch (opt) { - default: - continue; - - case TCPOPT_MAXSEG: - if (optlen != TCPOLEN_MAXSEG) - continue; - if (!(ti->ti_flags & TH_SYN)) - continue; - memcpy((char *)&mss, (char *)cp + 2, sizeof(mss)); - NTOHS(mss); - tcp_mss(tp, mss); /* sets t_maxseg */ - break; - } - } -} - -/* - * Collect new round-trip time estimate - * and update averages and current timeout. - */ - -static void tcp_xmit_timer(register struct tcpcb *tp, int rtt) -{ - register short delta; - - DEBUG_CALL("tcp_xmit_timer"); - DEBUG_ARG("tp = %p", tp); - DEBUG_ARG("rtt = %d", rtt); - - if (tp->t_srtt != 0) { - /* - * srtt is stored as fixed point with 3 bits after the - * binary point (i.e., scaled by 8). The following magic - * is equivalent to the smoothing algorithm in rfc793 with - * an alpha of .875 (srtt = rtt/8 + srtt*7/8 in fixed - * point). Adjust rtt to origin 0. - */ - delta = rtt - 1 - (tp->t_srtt >> TCP_RTT_SHIFT); - if ((tp->t_srtt += delta) <= 0) - tp->t_srtt = 1; - /* - * We accumulate a smoothed rtt variance (actually, a - * smoothed mean difference), then set the retransmit - * timer to smoothed rtt + 4 times the smoothed variance. - * rttvar is stored as fixed point with 2 bits after the - * binary point (scaled by 4). The following is - * equivalent to rfc793 smoothing with an alpha of .75 - * (rttvar = rttvar*3/4 + |delta| / 4). This replaces - * rfc793's wired-in beta. - */ - if (delta < 0) - delta = -delta; - delta -= (tp->t_rttvar >> TCP_RTTVAR_SHIFT); - if ((tp->t_rttvar += delta) <= 0) - tp->t_rttvar = 1; - } else { - /* - * No rtt measurement yet - use the unsmoothed rtt. - * Set the variance to half the rtt (so our first - * retransmit happens at 3*rtt). - */ - tp->t_srtt = rtt << TCP_RTT_SHIFT; - tp->t_rttvar = rtt << (TCP_RTTVAR_SHIFT - 1); - } - tp->t_rtt = 0; - tp->t_rxtshift = 0; - - /* - * the retransmit should happen at rtt + 4 * rttvar. - * Because of the way we do the smoothing, srtt and rttvar - * will each average +1/2 tick of bias. When we compute - * the retransmit timer, we want 1/2 tick of rounding and - * 1 extra tick because of +-1/2 tick uncertainty in the - * firing of the timer. The bias will give us exactly the - * 1.5 tick we need. But, because the bias is - * statistical, we have to test that we don't drop below - * the minimum feasible timer (which is 2 ticks). - */ - TCPT_RANGESET(tp->t_rxtcur, TCP_REXMTVAL(tp), (short)tp->t_rttmin, - TCPTV_REXMTMAX); /* XXX */ - - /* - * We received an ack for a packet that wasn't retransmitted; - * it is probably safe to discard any error indications we've - * received recently. This isn't quite right, but close enough - * for now (a route might have failed after we sent a segment, - * and the return path might not be symmetrical). - */ - tp->t_softerror = 0; -} - -/* - * Determine a reasonable value for maxseg size. - * If the route is known, check route for mtu. - * If none, use an mss that can be handled on the outgoing - * interface without forcing IP to fragment; if bigger than - * an mbuf cluster (MCLBYTES), round down to nearest multiple of MCLBYTES - * to utilize large mbufs. If no route is found, route has no mtu, - * or the destination isn't local, use a default, hopefully conservative - * size (usually 512 or the default IP max size, but no more than the mtu - * of the interface), as we can't discover anything about intervening - * gateways or networks. We also initialize the congestion/slow start - * window to be a single segment if the destination isn't local. - * While looking at the routing entry, we also initialize other path-dependent - * parameters from pre-set or cached values in the routing entry. - */ - -int tcp_mss(struct tcpcb *tp, unsigned offer) -{ - struct socket *so = tp->t_socket; - int mss; - - DEBUG_CALL("tcp_mss"); - DEBUG_ARG("tp = %p", tp); - DEBUG_ARG("offer = %d", offer); - - switch (so->so_ffamily) { - case AF_INET: - mss = MIN(so->slirp->if_mtu, so->slirp->if_mru) - - sizeof(struct tcphdr) - sizeof(struct ip); - break; - case AF_INET6: - mss = MIN(so->slirp->if_mtu, so->slirp->if_mru) - - sizeof(struct tcphdr) - sizeof(struct ip6); - break; - default: - g_assert_not_reached(); - } - - if (offer) - mss = MIN(mss, offer); - mss = MAX(mss, 32); - if (mss < tp->t_maxseg || offer != 0) - tp->t_maxseg = MIN(mss, TCP_MAXSEG_MAX); - - tp->snd_cwnd = mss; - - sbreserve(&so->so_snd, - TCP_SNDSPACE + - ((TCP_SNDSPACE % mss) ? (mss - (TCP_SNDSPACE % mss)) : 0)); - sbreserve(&so->so_rcv, - TCP_RCVSPACE + - ((TCP_RCVSPACE % mss) ? (mss - (TCP_RCVSPACE % mss)) : 0)); - - DEBUG_MISC(" returning mss = %d", mss); - - return mss; -} diff --git a/src/network/slirp/tcp_output.c b/src/network/slirp/tcp_output.c deleted file mode 100644 index 383fe31dc..000000000 --- a/src/network/slirp/tcp_output.c +++ /dev/null @@ -1,516 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_output.c 8.3 (Berkeley) 12/30/93 - * tcp_output.c,v 1.3 1994/09/15 10:36:55 davidg Exp - */ - -/* - * Changes and additions relating to SLiRP - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -static const uint8_t tcp_outflags[TCP_NSTATES] = { - TH_RST | TH_ACK, 0, TH_SYN, TH_SYN | TH_ACK, - TH_ACK, TH_ACK, TH_FIN | TH_ACK, TH_FIN | TH_ACK, - TH_FIN | TH_ACK, TH_ACK, TH_ACK, -}; - - -#undef MAX_TCPOPTLEN -#define MAX_TCPOPTLEN 32 /* max # bytes that go in options */ - -/* - * Tcp output routine: figure out what should be sent and send it. - */ -int tcp_output(struct tcpcb *tp) -{ - register struct socket *so = tp->t_socket; - register long len, win; - int off, flags, error; - register struct mbuf *m; - register struct tcpiphdr *ti, tcpiph_save; - struct ip *ip; - struct ip6 *ip6; - uint8_t opt[MAX_TCPOPTLEN]; - unsigned optlen, hdrlen; - int idle, sendalot; - - DEBUG_CALL("tcp_output"); - DEBUG_ARG("tp = %p", tp); - - /* - * Determine length of data that should be transmitted, - * and flags that will be used. - * If there is some data or critical controls (SYN, RST) - * to send, then transmit; otherwise, investigate further. - */ - idle = (tp->snd_max == tp->snd_una); - if (idle && tp->t_idle >= tp->t_rxtcur) - /* - * We have been idle for "a while" and no acks are - * expected to clock out any data we send -- - * slow start to get ack "clock" running again. - */ - tp->snd_cwnd = tp->t_maxseg; -again: - sendalot = 0; - off = tp->snd_nxt - tp->snd_una; - win = MIN(tp->snd_wnd, tp->snd_cwnd); - - flags = tcp_outflags[tp->t_state]; - - DEBUG_MISC(" --- tcp_output flags = 0x%x", flags); - - /* - * If in persist timeout with window of 0, send 1 byte. - * Otherwise, if window is small but nonzero - * and timer expired, we will send what we can - * and go to transmit state. - */ - if (tp->t_force) { - if (win == 0) { - /* - * If we still have some data to send, then - * clear the FIN bit. Usually this would - * happen below when it realizes that we - * aren't sending all the data. However, - * if we have exactly 1 byte of unset data, - * then it won't clear the FIN bit below, - * and if we are in persist state, we wind - * up sending the packet without recording - * that we sent the FIN bit. - * - * We can't just blindly clear the FIN bit, - * because if we don't have any more data - * to send then the probe will be the FIN - * itself. - */ - if (off < so->so_snd.sb_cc) - flags &= ~TH_FIN; - win = 1; - } else { - tp->t_timer[TCPT_PERSIST] = 0; - tp->t_rxtshift = 0; - } - } - - len = MIN(so->so_snd.sb_cc, win) - off; - - if (len < 0) { - /* - * If FIN has been sent but not acked, - * but we haven't been called to retransmit, - * len will be -1. Otherwise, window shrank - * after we sent into it. If window shrank to 0, - * cancel pending retransmit and pull snd_nxt - * back to (closed) window. We will enter persist - * state below. If the window didn't close completely, - * just wait for an ACK. - */ - len = 0; - if (win == 0) { - tp->t_timer[TCPT_REXMT] = 0; - tp->snd_nxt = tp->snd_una; - } - } - - if (len > tp->t_maxseg) { - len = tp->t_maxseg; - sendalot = 1; - } - if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc)) - flags &= ~TH_FIN; - - win = sbspace(&so->so_rcv); - - /* - * Sender silly window avoidance. If connection is idle - * and can send all data, a maximum segment, - * at least a maximum default-size segment do it, - * or are forced, do it; otherwise don't bother. - * If peer's buffer is tiny, then send - * when window is at least half open. - * If retransmitting (possibly after persist timer forced us - * to send into a small window), then must resend. - */ - if (len) { - if (len == tp->t_maxseg) - goto send; - if ((1 || idle || tp->t_flags & TF_NODELAY) && - len + off >= so->so_snd.sb_cc) - goto send; - if (tp->t_force) - goto send; - if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0) - goto send; - if (SEQ_LT(tp->snd_nxt, tp->snd_max)) - goto send; - } - - /* - * Compare available window to amount of window - * known to peer (as advertised window less - * next expected input). If the difference is at least two - * max size segments, or at least 50% of the maximum possible - * window, then want to send a window update to peer. - */ - if (win > 0) { - /* - * "adv" is the amount we can increase the window, - * taking into account that we are limited by - * TCP_MAXWIN << tp->rcv_scale. - */ - long adv = MIN(win, (long)TCP_MAXWIN << tp->rcv_scale) - - (tp->rcv_adv - tp->rcv_nxt); - - if (adv >= (long)(2 * tp->t_maxseg)) - goto send; - if (2 * adv >= (long)so->so_rcv.sb_datalen) - goto send; - } - - /* - * Send if we owe peer an ACK. - */ - if (tp->t_flags & TF_ACKNOW) - goto send; - if (flags & (TH_SYN | TH_RST)) - goto send; - if (SEQ_GT(tp->snd_up, tp->snd_una)) - goto send; - /* - * If our state indicates that FIN should be sent - * and we have not yet done so, or we're retransmitting the FIN, - * then we need to send. - */ - if (flags & TH_FIN && - ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una)) - goto send; - - /* - * TCP window updates are not reliable, rather a polling protocol - * using ``persist'' packets is used to insure receipt of window - * updates. The three ``states'' for the output side are: - * idle not doing retransmits or persists - * persisting to move a small or zero window - * (re)transmitting and thereby not persisting - * - * tp->t_timer[TCPT_PERSIST] - * is set when we are in persist state. - * tp->t_force - * is set when we are called to send a persist packet. - * tp->t_timer[TCPT_REXMT] - * is set when we are retransmitting - * The output side is idle when both timers are zero. - * - * If send window is too small, there is data to transmit, and no - * retransmit or persist is pending, then go to persist state. - * If nothing happens soon, send when timer expires: - * if window is nonzero, transmit what we can, - * otherwise force out a byte. - */ - if (so->so_snd.sb_cc && tp->t_timer[TCPT_REXMT] == 0 && - tp->t_timer[TCPT_PERSIST] == 0) { - tp->t_rxtshift = 0; - tcp_setpersist(tp); - } - - /* - * No reason to send a segment, just return. - */ - return (0); - -send: - /* - * Before ESTABLISHED, force sending of initial options - * unless TCP set not to do any options. - * NOTE: we assume that the IP/TCP header plus TCP options - * always fit in a single mbuf, leaving room for a maximum - * link header, i.e. - * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MHLEN - */ - optlen = 0; - hdrlen = sizeof(struct tcpiphdr); - if (flags & TH_SYN) { - tp->snd_nxt = tp->iss; - if ((tp->t_flags & TF_NOOPT) == 0) { - uint16_t mss; - - opt[0] = TCPOPT_MAXSEG; - opt[1] = 4; - mss = htons((uint16_t)tcp_mss(tp, 0)); - memcpy((char *)(opt + 2), (char *)&mss, sizeof(mss)); - optlen = 4; - } - } - - hdrlen += optlen; - - /* - * Adjust data length if insertion of options will - * bump the packet length beyond the t_maxseg length. - */ - if (len > tp->t_maxseg - optlen) { - len = tp->t_maxseg - optlen; - sendalot = 1; - } - - /* - * Grab a header mbuf, attaching a copy of data to - * be transmitted, and initialize the header from - * the template for sends on this connection. - */ - if (len) { - m = m_get(so->slirp); - if (m == NULL) { - error = 1; - goto out; - } - m->m_data += IF_MAXLINKHDR; - m->m_len = hdrlen; - - sbcopy(&so->so_snd, off, (int)len, mtod(m, char *) + hdrlen); - m->m_len += len; - - /* - * If we're sending everything we've got, set PUSH. - * (This will keep happy those implementations which only - * give data to the user when a buffer fills or - * a PUSH comes in.) - */ - if (off + len == so->so_snd.sb_cc) - flags |= TH_PUSH; - } else { - m = m_get(so->slirp); - if (m == NULL) { - error = 1; - goto out; - } - m->m_data += IF_MAXLINKHDR; - m->m_len = hdrlen; - } - - ti = mtod(m, struct tcpiphdr *); - - memcpy((char *)ti, &tp->t_template, sizeof(struct tcpiphdr)); - - /* - * Fill in fields, remembering maximum advertised - * window for use in delaying messages about window sizes. - * If resending a FIN, be sure not to use a new sequence number. - */ - if (flags & TH_FIN && tp->t_flags & TF_SENTFIN && - tp->snd_nxt == tp->snd_max) - tp->snd_nxt--; - /* - * If we are doing retransmissions, then snd_nxt will - * not reflect the first unsent octet. For ACK only - * packets, we do not want the sequence number of the - * retransmitted packet, we want the sequence number - * of the next unsent octet. So, if there is no data - * (and no SYN or FIN), use snd_max instead of snd_nxt - * when filling in ti_seq. But if we are in persist - * state, snd_max might reflect one byte beyond the - * right edge of the window, so use snd_nxt in that - * case, since we know we aren't doing a retransmission. - * (retransmit and persist are mutually exclusive...) - */ - if (len || (flags & (TH_SYN | TH_FIN)) || tp->t_timer[TCPT_PERSIST]) - ti->ti_seq = htonl(tp->snd_nxt); - else - ti->ti_seq = htonl(tp->snd_max); - ti->ti_ack = htonl(tp->rcv_nxt); - if (optlen) { - memcpy((char *)(ti + 1), (char *)opt, optlen); - ti->ti_off = (sizeof(struct tcphdr) + optlen) >> 2; - } - ti->ti_flags = flags; - /* - * Calculate receive window. Don't shrink window, - * but avoid silly window syndrome. - */ - if (win < (long)(so->so_rcv.sb_datalen / 4) && win < (long)tp->t_maxseg) - win = 0; - if (win > (long)TCP_MAXWIN << tp->rcv_scale) - win = (long)TCP_MAXWIN << tp->rcv_scale; - if (win < (long)(tp->rcv_adv - tp->rcv_nxt)) - win = (long)(tp->rcv_adv - tp->rcv_nxt); - ti->ti_win = htons((uint16_t)(win >> tp->rcv_scale)); - - if (SEQ_GT(tp->snd_up, tp->snd_una)) { - ti->ti_urp = htons((uint16_t)(tp->snd_up - ntohl(ti->ti_seq))); - ti->ti_flags |= TH_URG; - } else - /* - * If no urgent pointer to send, then we pull - * the urgent pointer to the left edge of the send window - * so that it doesn't drift into the send window on sequence - * number wraparound. - */ - tp->snd_up = tp->snd_una; /* drag it along */ - - /* - * Put TCP length in extended header, and then - * checksum extended header and data. - */ - if (len + optlen) - ti->ti_len = htons((uint16_t)(sizeof(struct tcphdr) + optlen + len)); - ti->ti_sum = cksum(m, (int)(hdrlen + len)); - - /* - * In transmit state, time the transmission and arrange for - * the retransmit. In persist state, just set snd_max. - */ - if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) { - tcp_seq startseq = tp->snd_nxt; - - /* - * Advance snd_nxt over sequence space of this segment. - */ - if (flags & (TH_SYN | TH_FIN)) { - if (flags & TH_SYN) - tp->snd_nxt++; - if (flags & TH_FIN) { - tp->snd_nxt++; - tp->t_flags |= TF_SENTFIN; - } - } - tp->snd_nxt += len; - if (SEQ_GT(tp->snd_nxt, tp->snd_max)) { - tp->snd_max = tp->snd_nxt; - /* - * Time this transmission if not a retransmission and - * not currently timing anything. - */ - if (tp->t_rtt == 0) { - tp->t_rtt = 1; - tp->t_rtseq = startseq; - } - } - - /* - * Set retransmit timer if not currently set, - * and not doing an ack or a keep-alive probe. - * Initial value for retransmit timer is smoothed - * round-trip time + 2 * round-trip time variance. - * Initialize shift counter which is used for backoff - * of retransmit time. - */ - if (tp->t_timer[TCPT_REXMT] == 0 && tp->snd_nxt != tp->snd_una) { - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - if (tp->t_timer[TCPT_PERSIST]) { - tp->t_timer[TCPT_PERSIST] = 0; - tp->t_rxtshift = 0; - } - } - } else if (SEQ_GT(tp->snd_nxt + len, tp->snd_max)) - tp->snd_max = tp->snd_nxt + len; - - /* - * Fill in IP length and desired time to live and - * send to IP level. There should be a better way - * to handle ttl and tos; we could keep them in - * the template, but need a way to checksum without them. - */ - m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */ - tcpiph_save = *mtod(m, struct tcpiphdr *); - - switch (so->so_ffamily) { - case AF_INET: - m->m_data += - sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - sizeof(struct ip); - m->m_len -= - sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - sizeof(struct ip); - ip = mtod(m, struct ip *); - - ip->ip_len = m->m_len; - ip->ip_dst = tcpiph_save.ti_dst; - ip->ip_src = tcpiph_save.ti_src; - ip->ip_p = tcpiph_save.ti_pr; - - ip->ip_ttl = IPDEFTTL; - ip->ip_tos = so->so_iptos; - error = ip_output(so, m); - break; - - case AF_INET6: - m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - - sizeof(struct ip6); - m->m_len -= sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - - sizeof(struct ip6); - ip6 = mtod(m, struct ip6 *); - - ip6->ip_pl = tcpiph_save.ti_len; - ip6->ip_dst = tcpiph_save.ti_dst6; - ip6->ip_src = tcpiph_save.ti_src6; - ip6->ip_nh = tcpiph_save.ti_nh6; - - error = ip6_output(so, m, 0); - break; - - default: - g_assert_not_reached(); - } - - if (error) { - out: - return (error); - } - - /* - * Data sent (as far as we can tell). - * If this advertises a larger window than any other segment, - * then remember the size of the advertised window. - * Any pending ACK has now been sent. - */ - if (win > 0 && SEQ_GT(tp->rcv_nxt + win, tp->rcv_adv)) - tp->rcv_adv = tp->rcv_nxt + win; - tp->last_ack_sent = tp->rcv_nxt; - tp->t_flags &= ~(TF_ACKNOW | TF_DELACK); - if (sendalot) - goto again; - - return (0); -} - -void tcp_setpersist(struct tcpcb *tp) -{ - int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1; - - /* - * Start/restart persistence timer. - */ - TCPT_RANGESET(tp->t_timer[TCPT_PERSIST], t * tcp_backoff[tp->t_rxtshift], - TCPTV_PERSMIN, TCPTV_PERSMAX); - if (tp->t_rxtshift < TCP_MAXRXTSHIFT) - tp->t_rxtshift++; -} diff --git a/src/network/slirp/tcp_subr.c b/src/network/slirp/tcp_subr.c deleted file mode 100644 index 112448483..000000000 --- a/src/network/slirp/tcp_subr.c +++ /dev/null @@ -1,1023 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_subr.c 8.1 (Berkeley) 6/10/93 - * tcp_subr.c,v 1.5 1994/10/08 22:39:58 phk Exp - */ - -/* - * Changes and additions relating to SLiRP - * Copyright (c) 1995 Danny Gasparovski. - */ - -#include "slirp.h" - -/* patchable/settable parameters for tcp */ -/* Don't do rfc1323 performance enhancements */ -#define TCP_DO_RFC1323 0 - -/* - * Tcp initialization - */ -void tcp_init(Slirp *slirp) -{ - slirp->tcp_iss = 1; /* wrong */ - slirp->tcb.so_next = slirp->tcb.so_prev = &slirp->tcb; - slirp->tcp_last_so = &slirp->tcb; -} - -void tcp_cleanup(Slirp *slirp) -{ - while (slirp->tcb.so_next != &slirp->tcb) { - tcp_close(sototcpcb(slirp->tcb.so_next)); - } -} - -/* - * Create template to be used to send tcp packets on a connection. - * Call after host entry created, fills - * in a skeletal tcp/ip header, minimizing the amount of work - * necessary when the connection is used. - */ -void tcp_template(struct tcpcb *tp) -{ - struct socket *so = tp->t_socket; - register struct tcpiphdr *n = &tp->t_template; - - n->ti_mbuf = NULL; - memset(&n->ti, 0, sizeof(n->ti)); - n->ti_x0 = 0; - switch (so->so_ffamily) { - case AF_INET: - n->ti_pr = IPPROTO_TCP; - n->ti_len = htons(sizeof(struct tcphdr)); - n->ti_src = so->so_faddr; - n->ti_dst = so->so_laddr; - n->ti_sport = so->so_fport; - n->ti_dport = so->so_lport; - break; - - case AF_INET6: - n->ti_nh6 = IPPROTO_TCP; - n->ti_len = htons(sizeof(struct tcphdr)); - n->ti_src6 = so->so_faddr6; - n->ti_dst6 = so->so_laddr6; - n->ti_sport = so->so_fport6; - n->ti_dport = so->so_lport6; - break; - - default: - g_assert_not_reached(); - } - - n->ti_seq = 0; - n->ti_ack = 0; - n->ti_x2 = 0; - n->ti_off = 5; - n->ti_flags = 0; - n->ti_win = 0; - n->ti_sum = 0; - n->ti_urp = 0; -} - -/* - * Send a single message to the TCP at address specified by - * the given TCP/IP header. If m == 0, then we make a copy - * of the tcpiphdr at ti and send directly to the addressed host. - * This is used to force keep alive messages out using the TCP - * template for a connection tp->t_template. If flags are given - * then we send a message back to the TCP which originated the - * segment ti, and discard the mbuf containing it and any other - * attached mbufs. - * - * In any case the ack and sequence number of the transmitted - * segment are as specified by the parameters. - */ -void tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m, - tcp_seq ack, tcp_seq seq, int flags, unsigned short af) -{ - register int tlen; - int win = 0; - - DEBUG_CALL("tcp_respond"); - DEBUG_ARG("tp = %p", tp); - DEBUG_ARG("ti = %p", ti); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("ack = %u", ack); - DEBUG_ARG("seq = %u", seq); - DEBUG_ARG("flags = %x", flags); - - if (tp) - win = sbspace(&tp->t_socket->so_rcv); - if (m == NULL) { - if (!tp || (m = m_get(tp->t_socket->slirp)) == NULL) - return; - tlen = 0; - m->m_data += IF_MAXLINKHDR; - *mtod(m, struct tcpiphdr *) = *ti; - ti = mtod(m, struct tcpiphdr *); - switch (af) { - case AF_INET: - ti->ti.ti_i4.ih_x1 = 0; - break; - case AF_INET6: - ti->ti.ti_i6.ih_x1 = 0; - break; - default: - g_assert_not_reached(); - } - flags = TH_ACK; - } else { - /* - * ti points into m so the next line is just making - * the mbuf point to ti - */ - m->m_data = (char *)ti; - - m->m_len = sizeof(struct tcpiphdr); - tlen = 0; -#define xchg(a, b, type) \ - { \ - type t; \ - t = a; \ - a = b; \ - b = t; \ - } - switch (af) { - case AF_INET: - xchg(ti->ti_dst.s_addr, ti->ti_src.s_addr, uint32_t); - xchg(ti->ti_dport, ti->ti_sport, uint16_t); - break; - case AF_INET6: - xchg(ti->ti_dst6, ti->ti_src6, struct in6_addr); - xchg(ti->ti_dport, ti->ti_sport, uint16_t); - break; - default: - g_assert_not_reached(); - } -#undef xchg - } - ti->ti_len = htons((uint16_t)(sizeof(struct tcphdr) + tlen)); - tlen += sizeof(struct tcpiphdr); - m->m_len = tlen; - - ti->ti_mbuf = NULL; - ti->ti_x0 = 0; - ti->ti_seq = htonl(seq); - ti->ti_ack = htonl(ack); - ti->ti_x2 = 0; - ti->ti_off = sizeof(struct tcphdr) >> 2; - ti->ti_flags = flags; - if (tp) - ti->ti_win = htons((uint16_t)(win >> tp->rcv_scale)); - else - ti->ti_win = htons((uint16_t)win); - ti->ti_urp = 0; - ti->ti_sum = 0; - ti->ti_sum = cksum(m, tlen); - - struct tcpiphdr tcpiph_save = *(mtod(m, struct tcpiphdr *)); - struct ip *ip; - struct ip6 *ip6; - - switch (af) { - case AF_INET: - m->m_data += - sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - sizeof(struct ip); - m->m_len -= - sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - sizeof(struct ip); - ip = mtod(m, struct ip *); - ip->ip_len = m->m_len; - ip->ip_dst = tcpiph_save.ti_dst; - ip->ip_src = tcpiph_save.ti_src; - ip->ip_p = tcpiph_save.ti_pr; - - if (flags & TH_RST) { - ip->ip_ttl = MAXTTL; - } else { - ip->ip_ttl = IPDEFTTL; - } - - ip_output(NULL, m); - break; - - case AF_INET6: - m->m_data += sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - - sizeof(struct ip6); - m->m_len -= sizeof(struct tcpiphdr) - sizeof(struct tcphdr) - - sizeof(struct ip6); - ip6 = mtod(m, struct ip6 *); - ip6->ip_pl = tcpiph_save.ti_len; - ip6->ip_dst = tcpiph_save.ti_dst6; - ip6->ip_src = tcpiph_save.ti_src6; - ip6->ip_nh = tcpiph_save.ti_nh6; - - ip6_output(NULL, m, 0); - break; - - default: - g_assert_not_reached(); - } -} - -/* - * Create a new TCP control block, making an - * empty reassembly queue and hooking it to the argument - * protocol control block. - */ -struct tcpcb *tcp_newtcpcb(struct socket *so) -{ - register struct tcpcb *tp; - - tp = g_new0(struct tcpcb, 1); - tp->seg_next = tp->seg_prev = (struct tcpiphdr *)tp; - /* - * 40: length of IPv4 header (20) + TCP header (20) - * 60: length of IPv6 header (40) + TCP header (20) - */ - tp->t_maxseg = - MIN(so->slirp->if_mtu - ((so->so_ffamily == AF_INET) ? 40 : 60), - TCP_MAXSEG_MAX); - - tp->t_flags = TCP_DO_RFC1323 ? (TF_REQ_SCALE | TF_REQ_TSTMP) : 0; - tp->t_socket = so; - - /* - * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no - * rtt estimate. Set rttvar so that srtt + 2 * rttvar gives - * reasonable initial retransmit time. - */ - tp->t_srtt = TCPTV_SRTTBASE; - tp->t_rttvar = TCPTV_SRTTDFLT << 2; - tp->t_rttmin = TCPTV_MIN; - - TCPT_RANGESET(tp->t_rxtcur, - ((TCPTV_SRTTBASE >> 2) + (TCPTV_SRTTDFLT << 2)) >> 1, - TCPTV_MIN, TCPTV_REXMTMAX); - - tp->snd_cwnd = TCP_MAXWIN << TCP_MAX_WINSHIFT; - tp->snd_ssthresh = TCP_MAXWIN << TCP_MAX_WINSHIFT; - tp->t_state = TCPS_CLOSED; - - so->so_tcpcb = tp; - - return (tp); -} - -/* - * Drop a TCP connection, reporting - * the specified error. If connection is synchronized, - * then send a RST to peer. - */ -struct tcpcb *tcp_drop(struct tcpcb *tp, int err) -{ - DEBUG_CALL("tcp_drop"); - DEBUG_ARG("tp = %p", tp); - DEBUG_ARG("errno = %d", errno); - - if (TCPS_HAVERCVDSYN(tp->t_state)) { - tp->t_state = TCPS_CLOSED; - tcp_output(tp); - } - return (tcp_close(tp)); -} - -/* - * Close a TCP control block: - * discard all space held by the tcp - * discard internet protocol block - * wake up any sleepers - */ -struct tcpcb *tcp_close(struct tcpcb *tp) -{ - register struct tcpiphdr *t; - struct socket *so = tp->t_socket; - Slirp *slirp = so->slirp; - register struct mbuf *m; - - DEBUG_CALL("tcp_close"); - DEBUG_ARG("tp = %p", tp); - - /* free the reassembly queue, if any */ - t = tcpfrag_list_first(tp); - while (!tcpfrag_list_end(t, tp)) { - t = tcpiphdr_next(t); - m = tcpiphdr_prev(t)->ti_mbuf; - slirp_remque(tcpiphdr2qlink(tcpiphdr_prev(t))); - m_free(m); - } - g_free(tp); - so->so_tcpcb = NULL; - /* clobber input socket cache if we're closing the cached connection */ - if (so == slirp->tcp_last_so) - slirp->tcp_last_so = &slirp->tcb; - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sbfree(&so->so_rcv); - sbfree(&so->so_snd); - sofree(so); - return ((struct tcpcb *)0); -} - -/* - * TCP protocol interface to socket abstraction. - */ - -/* - * User issued close, and wish to trail through shutdown states: - * if never received SYN, just forget it. If got a SYN from peer, - * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN. - * If already got a FIN from peer, then almost done; go to LAST_ACK - * state. In all other cases, have already sent FIN to peer (e.g. - * after PRU_SHUTDOWN), and just have to play tedious game waiting - * for peer to send FIN or not respond to keep-alives, etc. - * We can let the user exit from the close as soon as the FIN is acked. - */ -void tcp_sockclosed(struct tcpcb *tp) -{ - DEBUG_CALL("tcp_sockclosed"); - DEBUG_ARG("tp = %p", tp); - - if (!tp) { - return; - } - - switch (tp->t_state) { - case TCPS_CLOSED: - case TCPS_LISTEN: - case TCPS_SYN_SENT: - tp->t_state = TCPS_CLOSED; - tcp_close(tp); - return; - - case TCPS_SYN_RECEIVED: - case TCPS_ESTABLISHED: - tp->t_state = TCPS_FIN_WAIT_1; - break; - - case TCPS_CLOSE_WAIT: - tp->t_state = TCPS_LAST_ACK; - break; - } - tcp_output(tp); -} - -/* - * Connect to a host on the Internet - * Called by tcp_input - * Only do a connect, the tcp fields will be set in tcp_input - * return 0 if there's a result of the connect, - * else return -1 means we're still connecting - * The return value is almost always -1 since the socket is - * nonblocking. Connect returns after the SYN is sent, and does - * not wait for ACK+SYN. - */ -int tcp_fconnect(struct socket *so, unsigned short af) -{ - int ret = 0; - - DEBUG_CALL("tcp_fconnect"); - DEBUG_ARG("so = %p", so); - - ret = so->s = slirp_socket(af, SOCK_STREAM, 0); - if (ret >= 0) { - ret = slirp_bind_outbound(so, af); - if (ret < 0) { - // bind failed - close socket - closesocket(so->s); - so->s = -1; - return (ret); - } - } - - if (ret >= 0) { - int opt, s = so->s; - struct sockaddr_storage addr; - - slirp_set_nonblock(s); - so->slirp->cb->register_poll_fd(s, so->slirp->opaque); - slirp_socket_set_fast_reuse(s); - opt = 1; - setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt)); - opt = 1; - setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); - - addr = so->fhost.ss; - DEBUG_CALL(" connect()ing"); - if (sotranslate_out(so, &addr) < 0) { - return -1; - } - - /* We don't care what port we get */ - ret = connect(s, (struct sockaddr *)&addr, sockaddr_size(&addr)); - - /* - * If it's not in progress, it failed, so we just return 0, - * without clearing SS_NOFDREF - */ - soisfconnecting(so); - } - - return (ret); -} - -/* - * Accept the socket and connect to the local-host - * - * We have a problem. The correct thing to do would be - * to first connect to the local-host, and only if the - * connection is accepted, then do an accept() here. - * But, a) we need to know who's trying to connect - * to the socket to be able to SYN the local-host, and - * b) we are already connected to the foreign host by - * the time it gets to accept(), so... We simply accept - * here and SYN the local-host. - */ -void tcp_connect(struct socket *inso) -{ - Slirp *slirp = inso->slirp; - struct socket *so; - struct sockaddr_storage addr; - socklen_t addrlen; - struct tcpcb *tp; - int s, opt, ret; - /* AF_INET6 addresses are bigger than AF_INET, so this is big enough. */ - char addrstr[INET6_ADDRSTRLEN]; - char portstr[6]; - - DEBUG_CALL("tcp_connect"); - DEBUG_ARG("inso = %p", inso); - switch (inso->lhost.ss.ss_family) { - case AF_INET: - addrlen = sizeof(struct sockaddr_in); - break; - case AF_INET6: - addrlen = sizeof(struct sockaddr_in6); - break; - default: - g_assert_not_reached(); - } - ret = getnameinfo((const struct sockaddr *) &inso->lhost.ss, addrlen, addrstr, sizeof(addrstr), portstr, sizeof(portstr), NI_NUMERICHOST|NI_NUMERICSERV); - g_assert(ret == 0); - DEBUG_ARG("ip = [%s]:%s", addrstr, portstr); - DEBUG_ARG("so_state = 0x%x", inso->so_state); - - /* Perform lazy guest IP address resolution if needed. */ - if (inso->so_state & SS_HOSTFWD) { - /* - * We can only reject the connection request by accepting it and - * then immediately closing it. Note that SS_FACCEPTONCE sockets can't - * get here. - */ - if (soassign_guest_addr_if_needed(inso) < 0) { - /* - * Guest address isn't available yet. We could either try to defer - * completing this connection request until the guest address is - * available, or punt. It's easier to punt. Otherwise we need to - * complicate the mechanism by which we're called to defer calling - * us again until the guest address is available. - */ - DEBUG_MISC(" guest address not available yet"); - addrlen = sizeof(addr); - s = accept(inso->s, (struct sockaddr *)&addr, &addrlen); - if (s >= 0) { - closesocket(s); - } - return; - } - } - - /* - * If it's an SS_ACCEPTONCE socket, no need to socreate() - * another socket, just use the accept() socket. - */ - if (inso->so_state & SS_FACCEPTONCE) { - /* FACCEPTONCE already have a tcpcb */ - so = inso; - } else { - so = socreate(slirp, IPPROTO_TCP); - tcp_attach(so); - so->lhost = inso->lhost; - so->so_ffamily = inso->so_ffamily; - } - - tcp_mss(sototcpcb(so), 0); - - addrlen = sizeof(addr); - s = accept(inso->s, (struct sockaddr *)&addr, &addrlen); - if (s < 0) { - tcp_close(sototcpcb(so)); /* This will sofree() as well */ - return; - } - slirp_set_nonblock(s); - so->slirp->cb->register_poll_fd(s, so->slirp->opaque); - slirp_socket_set_fast_reuse(s); - opt = 1; - setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(int)); - slirp_socket_set_nodelay(s); - - so->fhost.ss = addr; - sotranslate_accept(so); - - /* Close the accept() socket, set right state */ - if (inso->so_state & SS_FACCEPTONCE) { - /* If we only accept once, close the accept() socket */ - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - - /* Don't select it yet, even though we have an FD */ - /* if it's not FACCEPTONCE, it's already NOFDREF */ - so->so_state = SS_NOFDREF; - } - so->s = s; - so->so_state |= SS_INCOMING; - - so->so_iptos = tcp_tos(so); - tp = sototcpcb(so); - - tcp_template(tp); - - tp->t_state = TCPS_SYN_SENT; - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; - tp->iss = slirp->tcp_iss; - slirp->tcp_iss += TCP_ISSINCR / 2; - tcp_sendseqinit(tp); - tcp_output(tp); -} - -/* - * Attach a TCPCB to a socket. - */ -void tcp_attach(struct socket *so) -{ - so->so_tcpcb = tcp_newtcpcb(so); - slirp_insque(so, &so->slirp->tcb); -} - -/* - * Set the socket's type of service field - */ -static const struct tos_t tcptos[] = { - { 0, 20, IPTOS_THROUGHPUT, 0 }, /* ftp data */ - { 21, 21, IPTOS_LOWDELAY, EMU_FTP }, /* ftp control */ - { 0, 23, IPTOS_LOWDELAY, 0 }, /* telnet */ - { 0, 80, IPTOS_THROUGHPUT, 0 }, /* WWW */ - { 0, 513, IPTOS_LOWDELAY, EMU_RLOGIN | EMU_NOCONNECT }, /* rlogin */ - { 0, 544, IPTOS_LOWDELAY, EMU_KSH }, /* kshell */ - { 0, 543, IPTOS_LOWDELAY, 0 }, /* klogin */ - { 0, 6667, IPTOS_THROUGHPUT, EMU_IRC }, /* IRC */ - { 0, 6668, IPTOS_THROUGHPUT, EMU_IRC }, /* IRC undernet */ - { 0, 7070, IPTOS_LOWDELAY, EMU_REALAUDIO }, /* RealAudio control */ - { 0, 113, IPTOS_LOWDELAY, EMU_IDENT }, /* identd protocol */ - { 0, 0, 0, 0 } -}; - -/* - * Return TOS according to the above table - */ -uint8_t tcp_tos(struct socket *so) -{ - int i = 0; - - while (tcptos[i].tos) { - if ((tcptos[i].fport && (ntohs(so->so_fport) == tcptos[i].fport)) || - (tcptos[i].lport && (ntohs(so->so_lport) == tcptos[i].lport))) { - if (so->slirp->enable_emu) - so->so_emu = tcptos[i].emu; - return tcptos[i].tos; - } - i++; - } - return 0; -} - -/* - * Emulate programs that try and connect to us - * This includes ftp (the data connection is - * initiated by the server) and IRC (DCC CHAT and - * DCC SEND) for now - * - * NOTE: It's possible to crash SLiRP by sending it - * unstandard strings to emulate... if this is a problem, - * more checks are needed here - * - * XXX Assumes the whole command came in one packet - * XXX If there is more than one command in the packet, the others may - * be truncated. - * XXX If the command is too long, it may be truncated. - * - * XXX Some ftp clients will have their TOS set to - * LOWDELAY and so Nagel will kick in. Because of this, - * we'll get the first letter, followed by the rest, so - * we simply scan for ORT instead of PORT... - * DCC doesn't have this problem because there's other stuff - * in the packet before the DCC command. - * - * Return 1 if the mbuf m is still valid and should be - * sbappend()ed - * - * NOTE: if you return 0 you MUST m_free() the mbuf! - */ -int tcp_emu(struct socket *so, struct mbuf *m) -{ - Slirp *slirp = so->slirp; - unsigned n1, n2, n3, n4, n5, n6; - char buff[257]; - uint32_t laddr; - unsigned lport; - char *bptr; - - DEBUG_CALL("tcp_emu"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - - switch (so->so_emu) { - int x, i; - - /* TODO: IPv6 */ - case EMU_IDENT: - /* - * Identification protocol as per rfc-1413 - */ - - { - struct socket *tmpso; - struct sockaddr_in addr; - socklen_t addrlen = sizeof(struct sockaddr_in); - char *eol = g_strstr_len(m->m_data, m->m_len, "\r\n"); - - if (!eol) { - return 1; - } - - *eol = '\0'; - if (sscanf(m->m_data, "%u%*[ ,]%u", &n1, &n2) == 2) { - HTONS(n1); - HTONS(n2); - /* n2 is the one on our host */ - for (tmpso = slirp->tcb.so_next; tmpso != &slirp->tcb; - tmpso = tmpso->so_next) { - if (tmpso->so_laddr.s_addr == so->so_laddr.s_addr && - tmpso->so_lport == n2 && - tmpso->so_faddr.s_addr == so->so_faddr.s_addr && - tmpso->so_fport == n1) { - if (getsockname(tmpso->s, (struct sockaddr *)&addr, - &addrlen) == 0) - n2 = addr.sin_port; - break; - } - } - NTOHS(n1); - NTOHS(n2); - m_inc(m, g_snprintf(NULL, 0, "%d,%d\r\n", n1, n2) + 1); - m->m_len = slirp_fmt(m->m_data, M_ROOM(m), "%d,%d\r\n", n1, n2); - } else { - *eol = '\r'; - } - - return 1; - } - - case EMU_FTP: /* ftp */ - m_inc(m, m->m_len + 1); - *(m->m_data + m->m_len) = 0; /* NUL terminate for strstr */ - if ((bptr = (char *)strstr(m->m_data, "ORT")) != NULL) { - /* - * Need to emulate the PORT command - */ - x = sscanf(bptr, "ORT %u,%u,%u,%u,%u,%u\r\n%256[^\177]", &n1, &n2, - &n3, &n4, &n5, &n6, buff); - if (x < 6) - return 1; - - laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4)); - lport = htons((n5 << 8) | (n6)); - - if ((so = tcp_listen(slirp, INADDR_ANY, 0, laddr, lport, - SS_FACCEPTONCE)) == NULL) { - return 1; - } - n6 = ntohs(so->so_fport); - - n5 = (n6 >> 8) & 0xff; - n6 &= 0xff; - - laddr = ntohl(so->so_faddr.s_addr); - - n1 = ((laddr >> 24) & 0xff); - n2 = ((laddr >> 16) & 0xff); - n3 = ((laddr >> 8) & 0xff); - n4 = (laddr & 0xff); - - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "ORT %d,%d,%d,%d,%d,%d\r\n%s", - n1, n2, n3, n4, n5, n6, x == 7 ? buff : ""); - return 1; - } else if ((bptr = (char *)strstr(m->m_data, "27 Entering")) != NULL) { - /* - * Need to emulate the PASV response - */ - x = sscanf( - bptr, - "27 Entering Passive Mode (%u,%u,%u,%u,%u,%u)\r\n%256[^\177]", - &n1, &n2, &n3, &n4, &n5, &n6, buff); - if (x < 6) - return 1; - - laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4)); - lport = htons((n5 << 8) | (n6)); - - if ((so = tcp_listen(slirp, INADDR_ANY, 0, laddr, lport, - SS_FACCEPTONCE)) == NULL) { - return 1; - } - n6 = ntohs(so->so_fport); - - n5 = (n6 >> 8) & 0xff; - n6 &= 0xff; - - laddr = ntohl(so->so_faddr.s_addr); - - n1 = ((laddr >> 24) & 0xff); - n2 = ((laddr >> 16) & 0xff); - n3 = ((laddr >> 8) & 0xff); - n4 = (laddr & 0xff); - - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "27 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n%s", - n1, n2, n3, n4, n5, n6, x == 7 ? buff : ""); - return 1; - } - - return 1; - - case EMU_KSH: - /* - * The kshell (Kerberos rsh) and shell services both pass - * a local port port number to carry signals to the server - * and stderr to the client. It is passed at the beginning - * of the connection as a NUL-terminated decimal ASCII string. - */ - so->so_emu = 0; - for (lport = 0, i = 0; i < m->m_len - 1; ++i) { - if (m->m_data[i] < '0' || m->m_data[i] > '9') - return 1; /* invalid number */ - lport *= 10; - lport += m->m_data[i] - '0'; - } - if (m->m_data[m->m_len - 1] == '\0' && lport != 0 && - (so = tcp_listen(slirp, INADDR_ANY, 0, so->so_laddr.s_addr, - htons(lport), SS_FACCEPTONCE)) != NULL) - m->m_len = slirp_fmt0(m->m_data, M_ROOM(m), - "%d", ntohs(so->so_fport)); - return 1; - - case EMU_IRC: - /* - * Need to emulate DCC CHAT, DCC SEND and DCC MOVE - */ - m_inc(m, m->m_len + 1); - *(m->m_data + m->m_len) = 0; /* NULL terminate the string for strstr */ - if ((bptr = (char *)strstr(m->m_data, "DCC")) == NULL) - return 1; - - /* The %256s is for the broken mIRC */ - if (sscanf(bptr, "DCC CHAT %256s %u %u", buff, &laddr, &lport) == 3) { - if ((so = tcp_listen(slirp, INADDR_ANY, 0, htonl(laddr), - htons(lport), SS_FACCEPTONCE)) == NULL) { - return 1; - } - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "DCC CHAT chat %lu %u%c\n", - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), 1); - } else if (sscanf(bptr, "DCC SEND %256s %u %u %u", buff, &laddr, &lport, - &n1) == 4) { - if ((so = tcp_listen(slirp, INADDR_ANY, 0, htonl(laddr), - htons(lport), SS_FACCEPTONCE)) == NULL) { - return 1; - } - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "DCC SEND %s %lu %u %u%c\n", buff, - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), n1, 1); - } else if (sscanf(bptr, "DCC MOVE %256s %u %u %u", buff, &laddr, &lport, - &n1) == 4) { - if ((so = tcp_listen(slirp, INADDR_ANY, 0, htonl(laddr), - htons(lport), SS_FACCEPTONCE)) == NULL) { - return 1; - } - m->m_len = bptr - m->m_data; /* Adjust length */ - m->m_len += slirp_fmt(bptr, M_FREEROOM(m), - "DCC MOVE %s %lu %u %u%c\n", buff, - (unsigned long)ntohl(so->so_faddr.s_addr), - ntohs(so->so_fport), n1, 1); - } - return 1; - - case EMU_REALAUDIO: - /* - * RealAudio emulation - JP. We must try to parse the incoming - * data and try to find the two characters that contain the - * port number. Then we redirect an udp port and replace the - * number with the real port we got. - * - * The 1.0 beta versions of the player are not supported - * any more. - * - * A typical packet for player version 1.0 (release version): - * - * 0000:50 4E 41 00 05 - * 0000:00 01 00 02 1B D7 00 00 67 E6 6C DC 63 00 12 50 ........g.l.c..P - * 0010:4E 43 4C 49 45 4E 54 20 31 30 31 20 41 4C 50 48 NCLIENT 101 ALPH - * 0020:41 6C 00 00 52 00 17 72 61 66 69 6C 65 73 2F 76 Al..R..rafiles/v - * 0030:6F 61 2F 65 6E 67 6C 69 73 68 5F 2E 72 61 79 42 oa/english_.rayB - * - * Now the port number 0x1BD7 is found at offset 0x04 of the - * Now the port number 0x1BD7 is found at offset 0x04 of the - * second packet. This time we received five bytes first and - * then the rest. You never know how many bytes you get. - * - * A typical packet for player version 2.0 (beta): - * - * 0000:50 4E 41 00 06 00 02 00 00 00 01 00 02 1B C1 00 PNA............. - * 0010:00 67 75 78 F5 63 00 0A 57 69 6E 32 2E 30 2E 30 .gux.c..Win2.0.0 - * 0020:2E 35 6C 00 00 52 00 1C 72 61 66 69 6C 65 73 2F .5l..R..rafiles/ - * 0030:77 65 62 73 69 74 65 2F 32 30 72 65 6C 65 61 73 website/20releas - * 0040:65 2E 72 61 79 53 00 00 06 36 42 e.rayS...6B - * - * Port number 0x1BC1 is found at offset 0x0d. - * - * This is just a horrible switch statement. Variable ra tells - * us where we're going. - */ - - bptr = m->m_data; - while (bptr < m->m_data + m->m_len) { - uint16_t p; - static int ra = 0; - char ra_tbl[4]; - - ra_tbl[0] = 0x50; - ra_tbl[1] = 0x4e; - ra_tbl[2] = 0x41; - ra_tbl[3] = 0; - - switch (ra) { - case 0: - case 2: - case 3: - if (*bptr++ != ra_tbl[ra]) { - ra = 0; - continue; - } - break; - - case 1: - /* - * We may get 0x50 several times, ignore them - */ - if (*bptr == 0x50) { - ra = 1; - bptr++; - continue; - } else if (*bptr++ != ra_tbl[ra]) { - ra = 0; - continue; - } - break; - - case 4: - /* - * skip version number - */ - bptr++; - break; - - case 5: - if (bptr == m->m_data + m->m_len - 1) - return 1; /* We need two bytes */ - - /* - * The difference between versions 1.0 and - * 2.0 is here. For future versions of - * the player this may need to be modified. - */ - if (*(bptr + 1) == 0x02) - bptr += 8; - else - bptr += 4; - break; - - case 6: - /* This is the field containing the port - * number that RA-player is listening to. - */ - - if (bptr == m->m_data + m->m_len - 1) - return 1; /* We need two bytes */ - - lport = (((uint8_t *)bptr)[0] << 8) + ((uint8_t *)bptr)[1]; - if (lport < 6970) - lport += 256; /* don't know why */ - if (lport < 6970 || lport > 7170) - return 1; /* failed */ - - /* try to get udp port between 6970 - 7170 */ - for (p = 6970; p < 7071; p++) { - if (udp_listen(slirp, INADDR_ANY, htons(p), - so->so_laddr.s_addr, htons(lport), - SS_FACCEPTONCE)) { - break; - } - } - if (p == 7071) - p = 0; - *(uint8_t *)bptr++ = (p >> 8) & 0xff; - *(uint8_t *)bptr = p & 0xff; - ra = 0; - return 1; /* port redirected, we're done */ - break; - - default: - ra = 0; - } - ra++; - } - return 1; - - default: - /* Ooops, not emulated, won't call tcp_emu again */ - so->so_emu = 0; - return 1; - } -} - -/* - * Do misc. config of SLiRP while its running. - * Return 0 if this connections is to be closed, 1 otherwise, - * return 2 if this is a command-line connection - */ -int tcp_ctl(struct socket *so) -{ - Slirp *slirp = so->slirp; - struct sbuf *sb = &so->so_snd; - struct gfwd_list *ex_ptr; - - DEBUG_CALL("tcp_ctl"); - DEBUG_ARG("so = %p", so); - - /* TODO: IPv6 */ - if (so->so_faddr.s_addr != slirp->vhost_addr.s_addr) { - /* Check if it's pty_exec */ - for (ex_ptr = slirp->guestfwd_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { - if (ex_ptr->ex_fport == so->so_fport && - so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { - if (ex_ptr->write_cb) { - so->s = -1; - so->guestfwd = ex_ptr; - return 1; - } - DEBUG_MISC(" executing %s", ex_ptr->ex_exec); - if (ex_ptr->ex_unix) - return open_unix(so, ex_ptr->ex_unix); - else - return fork_exec(so, ex_ptr->ex_exec); - } - } - } - sb->sb_cc = slirp_fmt(sb->sb_wptr, sb->sb_datalen - (sb->sb_wptr - sb->sb_data), - "Error: No application configured.\r\n"); - sb->sb_wptr += sb->sb_cc; - return 0; -} diff --git a/src/network/slirp/tcp_timer.c b/src/network/slirp/tcp_timer.c deleted file mode 100644 index bc4db2d15..000000000 --- a/src/network/slirp/tcp_timer.c +++ /dev/null @@ -1,286 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_timer.c 8.1 (Berkeley) 6/10/93 - * tcp_timer.c,v 1.2 1994/08/02 07:49:10 davidg Exp - */ - -#include "slirp.h" - -static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer); - -/* - * Fast timeout routine for processing delayed acks - */ -void tcp_fasttimo(Slirp *slirp) -{ - register struct socket *so; - register struct tcpcb *tp; - - DEBUG_CALL("tcp_fasttimo"); - - so = slirp->tcb.so_next; - if (so) - for (; so != &slirp->tcb; so = so->so_next) - if ((tp = (struct tcpcb *)so->so_tcpcb) && - (tp->t_flags & TF_DELACK)) { - tp->t_flags &= ~TF_DELACK; - tp->t_flags |= TF_ACKNOW; - tcp_output(tp); - } -} - -/* - * Tcp protocol timeout routine called every 500 ms. - * Updates the timers in all active tcb's and - * causes finite state machine actions if timers expire. - */ -void tcp_slowtimo(Slirp *slirp) -{ - register struct socket *ip, *ipnxt; - register struct tcpcb *tp; - register int i; - - DEBUG_CALL("tcp_slowtimo"); - - /* - * Search through tcb's and update active timers. - */ - ip = slirp->tcb.so_next; - if (ip == NULL) { - return; - } - for (; ip != &slirp->tcb; ip = ipnxt) { - ipnxt = ip->so_next; - tp = sototcpcb(ip); - if (tp == NULL) { - continue; - } - for (i = 0; i < TCPT_NTIMERS; i++) { - if (tp->t_timer[i] && --tp->t_timer[i] == 0) { - tcp_timers(tp, i); - if (ipnxt->so_prev != ip) - goto tpgone; - } - } - tp->t_idle++; - if (tp->t_rtt) - tp->t_rtt++; - tpgone:; - } - slirp->tcp_iss += TCP_ISSINCR / PR_SLOWHZ; /* increment iss */ - slirp->tcp_now++; /* for timestamps */ -} - -/* - * Cancel all timers for TCP tp. - */ -void tcp_canceltimers(struct tcpcb *tp) -{ - register int i; - - for (i = 0; i < TCPT_NTIMERS; i++) - tp->t_timer[i] = 0; -} - -const int tcp_backoff[TCP_MAXRXTSHIFT + 1] = { 1, 2, 4, 8, 16, 32, 64, - 64, 64, 64, 64, 64, 64 }; - -/* - * TCP timer processing. - */ -static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer) -{ - register int rexmt; - - DEBUG_CALL("tcp_timers"); - - switch (timer) { - /* - * 2 MSL timeout in shutdown went off. If we're closed but - * still waiting for peer to close and connection has been idle - * too long, or if 2MSL time is up from TIME_WAIT, delete connection - * control block. Otherwise, check again in a bit. - */ - case TCPT_2MSL: - if (tp->t_state != TCPS_TIME_WAIT && tp->t_idle <= TCP_MAXIDLE) - tp->t_timer[TCPT_2MSL] = TCPTV_KEEPINTVL; - else - tp = tcp_close(tp); - break; - - /* - * Retransmission timer went off. Message has not - * been acked within retransmit interval. Back off - * to a longer retransmit interval and retransmit one segment. - */ - case TCPT_REXMT: - - /* - * XXXXX If a packet has timed out, then remove all the queued - * packets for that session. - */ - - if (++tp->t_rxtshift > TCP_MAXRXTSHIFT) { - /* - * This is a hack to suit our terminal server here at the uni of - * canberra since they have trouble with zeroes... It usually lets - * them through unharmed, but under some conditions, it'll eat the - * zeros. If we keep retransmitting it, it'll keep eating the - * zeroes, so we keep retransmitting, and eventually the connection - * dies... (this only happens on incoming data) - * - * So, if we were gonna drop the connection from too many - * retransmits, don't... instead halve the t_maxseg, which might - * break up the NULLs and let them through - * - * *sigh* - */ - - tp->t_maxseg >>= 1; - if (tp->t_maxseg < 32) { - /* - * We tried our best, now the connection must die! - */ - tp->t_rxtshift = TCP_MAXRXTSHIFT; - tp = tcp_drop(tp, tp->t_softerror); - /* tp->t_softerror : ETIMEDOUT); */ /* XXX */ - return (tp); /* XXX */ - } - - /* - * Set rxtshift to 6, which is still at the maximum - * backoff time - */ - tp->t_rxtshift = 6; - } - rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift]; - TCPT_RANGESET(tp->t_rxtcur, rexmt, (short)tp->t_rttmin, - TCPTV_REXMTMAX); /* XXX */ - tp->t_timer[TCPT_REXMT] = tp->t_rxtcur; - /* - * If losing, let the lower level know and try for - * a better route. Also, if we backed off this far, - * our srtt estimate is probably bogus. Clobber it - * so we'll take the next rtt measurement as our srtt; - * move the current srtt into rttvar to keep the current - * retransmit times until then. - */ - if (tp->t_rxtshift > TCP_MAXRXTSHIFT / 4) { - tp->t_rttvar += (tp->t_srtt >> TCP_RTT_SHIFT); - tp->t_srtt = 0; - } - tp->snd_nxt = tp->snd_una; - /* - * If timing a segment in this window, stop the timer. - */ - tp->t_rtt = 0; - /* - * Close the congestion window down to one segment - * (we'll open it by one segment for each ack we get). - * Since we probably have a window's worth of unacked - * data accumulated, this "slow start" keeps us from - * dumping all that data as back-to-back packets (which - * might overwhelm an intermediate gateway). - * - * There are two phases to the opening: Initially we - * open by one mss on each ack. This makes the window - * size increase exponentially with time. If the - * window is larger than the path can handle, this - * exponential growth results in dropped packet(s) - * almost immediately. To get more time between - * drops but still "push" the network to take advantage - * of improving conditions, we switch from exponential - * to linear window opening at some threshold size. - * For a threshold, we use half the current window - * size, truncated to a multiple of the mss. - * - * (the minimum cwnd that will give us exponential - * growth is 2 mss. We don't allow the threshold - * to go below this.) - */ - { - unsigned win = MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg; - if (win < 2) - win = 2; - tp->snd_cwnd = tp->t_maxseg; - tp->snd_ssthresh = win * tp->t_maxseg; - tp->t_dupacks = 0; - } - tcp_output(tp); - break; - - /* - * Persistence timer into zero window. - * Force a byte to be output, if possible. - */ - case TCPT_PERSIST: - tcp_setpersist(tp); - tp->t_force = 1; - tcp_output(tp); - tp->t_force = 0; - break; - - /* - * Keep-alive timer went off; send something - * or drop connection if idle for too long. - */ - case TCPT_KEEP: - if (tp->t_state < TCPS_ESTABLISHED) - goto dropit; - - if (slirp_do_keepalive && tp->t_state <= TCPS_CLOSE_WAIT) { - if (tp->t_idle >= TCPTV_KEEP_IDLE + TCP_MAXIDLE) - goto dropit; - /* - * Send a packet designed to force a response - * if the peer is up and reachable: - * either an ACK if the connection is still alive, - * or an RST if the peer has closed the connection - * due to timeout or reboot. - * Using sequence number tp->snd_una-1 - * causes the transmitted zero-length segment - * to lie outside the receive window; - * by the protocol spec, this requires the - * correspondent TCP to respond. - */ - tcp_respond(tp, &tp->t_template, (struct mbuf *)NULL, tp->rcv_nxt, - tp->snd_una - 1, 0, tp->t_socket->so_ffamily); - tp->t_timer[TCPT_KEEP] = TCPTV_KEEPINTVL; - } else - tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_IDLE; - break; - - dropit: - tp = tcp_drop(tp, 0); - break; - } - - return (tp); -} diff --git a/src/network/slirp/tcp_timer.h b/src/network/slirp/tcp_timer.h deleted file mode 100644 index 584a5594e..000000000 --- a/src/network/slirp/tcp_timer.h +++ /dev/null @@ -1,130 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_timer.h 8.1 (Berkeley) 6/10/93 - * tcp_timer.h,v 1.4 1994/08/21 05:27:38 paul Exp - */ - -#ifndef TCP_TIMER_H -#define TCP_TIMER_H - -/* - * Definitions of the TCP timers. These timers are counted - * down PR_SLOWHZ times a second. - */ -#define TCPT_NTIMERS 4 - -#define TCPT_REXMT 0 /* retransmit */ -#define TCPT_PERSIST 1 /* retransmit persistence */ -#define TCPT_KEEP 2 /* keep alive */ -#define TCPT_2MSL 3 /* 2*msl quiet time timer */ - -/* - * The TCPT_REXMT timer is used to force retransmissions. - * The TCP has the TCPT_REXMT timer set whenever segments - * have been sent for which ACKs are expected but not yet - * received. If an ACK is received which advances tp->snd_una, - * then the retransmit timer is cleared (if there are no more - * outstanding segments) or reset to the base value (if there - * are more ACKs expected). Whenever the retransmit timer goes off, - * we retransmit one unacknowledged segment, and do a backoff - * on the retransmit timer. - * - * The TCPT_PERSIST timer is used to keep window size information - * flowing even if the window goes shut. If all previous transmissions - * have been acknowledged (so that there are no retransmissions in progress), - * and the window is too small to bother sending anything, then we start - * the TCPT_PERSIST timer. When it expires, if the window is nonzero, - * we go to transmit state. Otherwise, at intervals send a single byte - * into the peer's window to force him to update our window information. - * We do this at most as often as TCPT_PERSMIN time intervals, - * but no more frequently than the current estimate of round-trip - * packet time. The TCPT_PERSIST timer is cleared whenever we receive - * a window update from the peer. - * - * The TCPT_KEEP timer is used to keep connections alive. If an - * connection is idle (no segments received) for TCPTV_KEEP_INIT amount of time, - * but not yet established, then we drop the connection. Once the connection - * is established, if the connection is idle for TCPTV_KEEP_IDLE time - * (and keepalives have been enabled on the socket), we begin to probe - * the connection. We force the peer to send us a segment by sending: - * - * This segment is (deliberately) outside the window, and should elicit - * an ack segment in response from the peer. If, despite the TCPT_KEEP - * initiated segments we cannot elicit a response from a peer in TCPT_MAXIDLE - * amount of time probing, then we drop the connection. - */ - -/* - * Time constants. - */ -#define TCPTV_MSL (5 * PR_SLOWHZ) /* max seg lifetime (hah!) */ - -#define TCPTV_SRTTBASE \ - 0 /* base roundtrip time; \ - if 0, no idea yet */ -#define TCPTV_SRTTDFLT (3 * PR_SLOWHZ) /* assumed RTT if no info */ - -#define TCPTV_PERSMIN (5 * PR_SLOWHZ) /* retransmit persistence */ -#define TCPTV_PERSMAX (60 * PR_SLOWHZ) /* maximum persist interval */ - -#define TCPTV_KEEP_INIT (75 * PR_SLOWHZ) /* initial connect keep alive */ -#define TCPTV_KEEP_IDLE (120 * 60 * PR_SLOWHZ) /* dflt time before probing */ -#define TCPTV_KEEPINTVL (75 * PR_SLOWHZ) /* default probe interval */ -#define TCPTV_KEEPCNT 8 /* max probes before drop */ - -#define TCPTV_MIN (1 * PR_SLOWHZ) /* minimum allowable value */ -#define TCPTV_REXMTMAX (12 * PR_SLOWHZ) /* max allowable REXMT value */ - -#define TCP_LINGERTIME 120 /* linger at most 2 minutes */ - -#define TCP_MAXRXTSHIFT 12 /* maximum retransmits */ - - -/* - * Force a time value to be in a certain range. - */ -#define TCPT_RANGESET(tv, value, tvmin, tvmax) \ - { \ - (tv) = (value); \ - if ((tv) < (tvmin)) \ - (tv) = (tvmin); \ - else if ((tv) > (tvmax)) \ - (tv) = (tvmax); \ - } - -extern const int tcp_backoff[]; - -struct tcpcb; - -void tcp_fasttimo(Slirp *); -void tcp_slowtimo(Slirp *); -void tcp_canceltimers(struct tcpcb *); - -#endif diff --git a/src/network/slirp/tcp_var.h b/src/network/slirp/tcp_var.h deleted file mode 100644 index c8da8cbd1..000000000 --- a/src/network/slirp/tcp_var.h +++ /dev/null @@ -1,161 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcp_var.h 8.3 (Berkeley) 4/10/94 - * tcp_var.h,v 1.3 1994/08/21 05:27:39 paul Exp - */ - -#ifndef TCP_VAR_H -#define TCP_VAR_H - -#include "tcpip.h" -#include "tcp_timer.h" - -/* - * Tcp control block, one per tcp; fields: - */ -struct tcpcb { - struct tcpiphdr *seg_next; /* sequencing queue */ - struct tcpiphdr *seg_prev; - short t_state; /* state of this connection */ - short t_timer[TCPT_NTIMERS]; /* tcp timers */ - short t_rxtshift; /* log(2) of rexmt exp. backoff */ - short t_rxtcur; /* current retransmit value */ - short t_dupacks; /* consecutive dup acks recd */ - uint16_t t_maxseg; /* maximum segment size */ - uint8_t t_force; /* 1 if forcing out a byte */ - uint16_t t_flags; -#define TF_ACKNOW 0x0001 /* ack peer immediately */ -#define TF_DELACK 0x0002 /* ack, but try to delay it */ -#define TF_NODELAY 0x0004 /* don't delay packets to coalesce */ -#define TF_NOOPT 0x0008 /* don't use tcp options */ -#define TF_SENTFIN 0x0010 /* have sent FIN */ -#define TF_REQ_SCALE 0x0020 /* have/will request window scaling */ -#define TF_RCVD_SCALE 0x0040 /* other side has requested scaling */ -#define TF_REQ_TSTMP 0x0080 /* have/will request timestamps */ -#define TF_RCVD_TSTMP 0x0100 /* a timestamp was received in SYN */ -#define TF_SACK_PERMIT 0x0200 /* other side said I could SACK */ - - struct tcpiphdr t_template; /* static skeletal packet for xmit */ - - struct socket *t_socket; /* back pointer to socket */ - /* - * The following fields are used as in the protocol specification. - * See RFC783, Dec. 1981, page 21. - */ - /* send sequence variables */ - tcp_seq snd_una; /* send unacknowledged */ - tcp_seq snd_nxt; /* send next */ - tcp_seq snd_up; /* send urgent pointer */ - tcp_seq snd_wl1; /* window update seg seq number */ - tcp_seq snd_wl2; /* window update seg ack number */ - tcp_seq iss; /* initial send sequence number */ - uint32_t snd_wnd; /* send window */ - /* receive sequence variables */ - uint32_t rcv_wnd; /* receive window */ - tcp_seq rcv_nxt; /* receive next */ - tcp_seq rcv_up; /* receive urgent pointer */ - tcp_seq irs; /* initial receive sequence number */ - /* - * Additional variables for this implementation. - */ - /* receive variables */ - tcp_seq rcv_adv; /* advertised window */ - /* retransmit variables */ - tcp_seq snd_max; /* highest sequence number sent; - * used to recognize retransmits - */ - /* congestion control (for slow start, source quench, retransmit after loss) - */ - uint32_t snd_cwnd; /* congestion-controlled window */ - uint32_t snd_ssthresh; /* snd_cwnd size threshold for - * for slow start exponential to - * linear switch - */ - /* - * transmit timing stuff. See below for scale of srtt and rttvar. - * "Variance" is actually smoothed difference. - */ - short t_idle; /* inactivity time */ - short t_rtt; /* round trip time */ - tcp_seq t_rtseq; /* sequence number being timed */ - short t_srtt; /* smoothed round-trip time */ - short t_rttvar; /* variance in round-trip time */ - uint16_t t_rttmin; /* minimum rtt allowed */ - uint32_t max_sndwnd; /* largest window peer has offered */ - - /* out-of-band data */ - uint8_t t_oobflags; /* have some */ - uint8_t t_iobc; /* input character */ -#define TCPOOB_HAVEDATA 0x01 -#define TCPOOB_HADDATA 0x02 - short t_softerror; /* possible error not yet reported */ - - /* RFC 1323 variables */ - uint8_t snd_scale; /* window scaling for send window */ - uint8_t rcv_scale; /* window scaling for recv window */ - uint8_t request_r_scale; /* pending window scaling */ - uint8_t requested_s_scale; - uint32_t ts_recent; /* timestamp echo data */ - uint32_t ts_recent_age; /* when last updated */ - tcp_seq last_ack_sent; -}; - -#define sototcpcb(so) ((so)->so_tcpcb) - -/* - * The smoothed round-trip time and estimated variance - * are stored as fixed point numbers scaled by the values below. - * For convenience, these scales are also used in smoothing the average - * (smoothed = (1/scale)sample + ((scale-1)/scale)smoothed). - * With these scales, srtt has 3 bits to the right of the binary point, - * and thus an "ALPHA" of 0.875. rttvar has 2 bits to the right of the - * binary point, and is smoothed with an ALPHA of 0.75. - */ -#define TCP_RTT_SCALE 8 /* multiplier for srtt; 3 bits frac. */ -#define TCP_RTT_SHIFT 3 /* shift for srtt; 3 bits frac. */ -#define TCP_RTTVAR_SCALE 4 /* multiplier for rttvar; 2 bits */ -#define TCP_RTTVAR_SHIFT 2 /* multiplier for rttvar; 2 bits */ - -/* - * The initial retransmission should happen at rtt + 4 * rttvar. - * Because of the way we do the smoothing, srtt and rttvar - * will each average +1/2 tick of bias. When we compute - * the retransmit timer, we want 1/2 tick of rounding and - * 1 extra tick because of +-1/2 tick uncertainty in the - * firing of the timer. The bias will give us exactly the - * 1.5 tick we need. But, because the bias is - * statistical, we have to test that we don't drop below - * the minimum feasible timer (which is 2 ticks). - * This macro assumes that the value of TCP_RTTVAR_SCALE - * is the same as the multiplier for rttvar. - */ -#define TCP_REXMTVAL(tp) (((tp)->t_srtt >> TCP_RTT_SHIFT) + (tp)->t_rttvar) - -#endif diff --git a/src/network/slirp/tcpip.h b/src/network/slirp/tcpip.h deleted file mode 100644 index a0fb2282f..000000000 --- a/src/network/slirp/tcpip.h +++ /dev/null @@ -1,104 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tcpip.h 8.1 (Berkeley) 6/10/93 - * tcpip.h,v 1.3 1994/08/21 05:27:40 paul Exp - */ - -#ifndef TCPIP_H -#define TCPIP_H - -/* - * Tcp+ip header, after ip options removed. - */ -struct tcpiphdr { - struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */ - union { - struct { - struct in_addr ih_src; /* source internet address */ - struct in_addr ih_dst; /* destination internet address */ - uint8_t ih_x1; /* (unused) */ - uint8_t ih_pr; /* protocol */ - } ti_i4; - struct { - struct in6_addr ih_src; - struct in6_addr ih_dst; - uint8_t ih_x1; - uint8_t ih_nh; - } ti_i6; - } ti; - uint16_t ti_x0; - uint16_t ti_len; /* protocol length */ - struct tcphdr ti_t; /* tcp header */ -}; -#define ti_mbuf ih_mbuf.mptr -#define ti_pr ti.ti_i4.ih_pr -#define ti_src ti.ti_i4.ih_src -#define ti_dst ti.ti_i4.ih_dst -#define ti_src6 ti.ti_i6.ih_src -#define ti_dst6 ti.ti_i6.ih_dst -#define ti_nh6 ti.ti_i6.ih_nh -#define ti_sport ti_t.th_sport -#define ti_dport ti_t.th_dport -#define ti_seq ti_t.th_seq -#define ti_ack ti_t.th_ack -#define ti_x2 ti_t.th_x2 -#define ti_off ti_t.th_off -#define ti_flags ti_t.th_flags -#define ti_win ti_t.th_win -#define ti_sum ti_t.th_sum -#define ti_urp ti_t.th_urp - -#define tcpiphdr2qlink(T) \ - ((struct qlink *)(((char *)(T)) - sizeof(struct qlink))) -#define qlink2tcpiphdr(Q) \ - ((struct tcpiphdr *)(((char *)(Q)) + sizeof(struct qlink))) -#define tcpiphdr_next(T) qlink2tcpiphdr(tcpiphdr2qlink(T)->next) -#define tcpiphdr_prev(T) qlink2tcpiphdr(tcpiphdr2qlink(T)->prev) -#define tcpfrag_list_first(T) qlink2tcpiphdr((T)->seg_next) -#define tcpfrag_list_end(F, T) (tcpiphdr2qlink(F) == (struct qlink *)(T)) -#define tcpfrag_list_empty(T) ((T)->seg_next == (struct tcpiphdr *)(T)) - -/* This is the difference between the size of a tcpiphdr structure, and the - * size of actual ip+tcp headers, rounded up since we need to align data. */ -#define TCPIPHDR_DELTA \ - (MAX(0, ((int) sizeof(struct tcpiphdr) - (int) sizeof(struct ip) - \ - (int) sizeof(struct tcphdr) + 3) & \ - ~3)) - -/* - * Just a clean way to get to the first byte - * of the packet - */ -struct tcpiphdr_2 { - struct tcpiphdr dummy; - char first_char; -}; - -#endif diff --git a/src/network/slirp/tftp.c b/src/network/slirp/tftp.c deleted file mode 100644 index a19c889d3..000000000 --- a/src/network/slirp/tftp.c +++ /dev/null @@ -1,470 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * tftp.c - a simple, read-only tftp server for qemu - * - * Copyright (c) 2004 Magnus Damm - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "slirp.h" - -#include -#include -#include - -static inline int tftp_session_in_use(struct tftp_session *spt) -{ - return (spt->slirp != NULL); -} - -static inline void tftp_session_update(struct tftp_session *spt) -{ - spt->timestamp = curtime; -} - -static void tftp_session_terminate(struct tftp_session *spt) -{ - if (spt->fd >= 0) { - close(spt->fd); - spt->fd = -1; - } - g_free(spt->filename); - spt->slirp = NULL; -} - -static int tftp_session_allocate(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftphdr *hdr) -{ - struct tftp_session *spt; - int k; - - for (k = 0; k < TFTP_SESSIONS_MAX; k++) { - spt = &slirp->tftp_sessions[k]; - - if (!tftp_session_in_use(spt)) - goto found; - - /* sessions time out after 5 inactive seconds */ - if ((int)(curtime - spt->timestamp) > 5000) { - tftp_session_terminate(spt); - goto found; - } - } - - return -1; - -found: - memset(spt, 0, sizeof(*spt)); - memcpy(&spt->client_addr, srcsas, sockaddr_size(srcsas)); - spt->fd = -1; - spt->block_size = 512; - spt->client_port = hdr->udp.uh_sport; - spt->slirp = slirp; - - tftp_session_update(spt); - - return k; -} - -static int tftp_session_find(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftphdr *hdr) -{ - struct tftp_session *spt; - int k; - - for (k = 0; k < TFTP_SESSIONS_MAX; k++) { - spt = &slirp->tftp_sessions[k]; - - if (tftp_session_in_use(spt)) { - if (sockaddr_equal(&spt->client_addr, srcsas)) { - if (spt->client_port == hdr->udp.uh_sport) { - return k; - } - } - } - } - - return -1; -} - -static int tftp_read_data(struct tftp_session *spt, uint32_t block_nr, - uint8_t *buf, int len) -{ - int bytes_read = 0; - - if (spt->fd < 0) { - spt->fd = open(spt->filename, O_RDONLY | O_BINARY); - } - - if (spt->fd < 0) { - return -1; - } - - if (len) { - if (lseek(spt->fd, block_nr * spt->block_size, SEEK_SET) == (off_t)-1) { - return -1; - } - - bytes_read = read(spt->fd, buf, len); - } - - return bytes_read; -} - -static struct tftp_t *tftp_prep_mbuf_data(struct tftp_session *spt, - struct mbuf *m) -{ - struct tftp_t *tp; - - memset(m->m_data, 0, m->m_size); - - m->m_data += IF_MAXLINKHDR; - if (spt->client_addr.ss_family == AF_INET6) { - m->m_data += sizeof(struct ip6); - } else { - m->m_data += sizeof(struct ip); - } - tp = (void *)m->m_data; - m->m_data += sizeof(struct udphdr); - - return tp; -} - -static void tftp_udp_output(struct tftp_session *spt, struct mbuf *m, - struct tftphdr *hdr) -{ - if (spt->client_addr.ss_family == AF_INET6) { - struct sockaddr_in6 sa6, da6; - - sa6.sin6_addr = spt->slirp->vhost_addr6; - sa6.sin6_port = hdr->udp.uh_dport; - da6.sin6_addr = ((struct sockaddr_in6 *)&spt->client_addr)->sin6_addr; - da6.sin6_port = spt->client_port; - - udp6_output(NULL, m, &sa6, &da6); - } else { - struct sockaddr_in sa4, da4; - - sa4.sin_addr = spt->slirp->vhost_addr; - sa4.sin_port = hdr->udp.uh_dport; - da4.sin_addr = ((struct sockaddr_in *)&spt->client_addr)->sin_addr; - da4.sin_port = spt->client_port; - - udp_output(NULL, m, &sa4, &da4, IPTOS_LOWDELAY); - } -} - -static int tftp_send_oack(struct tftp_session *spt, const char *keys[], - uint32_t values[], int nb, struct tftp_t *recv_tp) -{ - struct mbuf *m; - struct tftp_t *tp; - int i, n = 0; - - m = m_get(spt->slirp); - - if (!m) - return -1; - - tp = tftp_prep_mbuf_data(spt, m); - - tp->hdr.tp_op = htons(TFTP_OACK); - for (i = 0; i < nb; i++) { - n += slirp_fmt0(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s", keys[i]); - n += slirp_fmt0(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u", values[i]); - } - - m->m_len = G_SIZEOF_MEMBER(struct tftp_t, hdr.tp_op) + n; - tftp_udp_output(spt, m, &recv_tp->hdr); - - return 0; -} - -static void tftp_send_error(struct tftp_session *spt, uint16_t errorcode, - const char *msg, struct tftp_t *recv_tp) -{ - struct mbuf *m; - struct tftp_t *tp; - - DEBUG_TFTP("tftp error msg: %s", msg); - - m = m_get(spt->slirp); - - if (!m) { - goto out; - } - - tp = tftp_prep_mbuf_data(spt, m); - - tp->hdr.tp_op = htons(TFTP_ERROR); - tp->x.tp_error.tp_error_code = htons(errorcode); - slirp_pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), - msg); - - m->m_len = sizeof(struct tftp_t) - (TFTP_BLOCKSIZE_MAX + 2) + 3 + - strlen(msg) - sizeof(struct udphdr); - tftp_udp_output(spt, m, &recv_tp->hdr); - -out: - tftp_session_terminate(spt); -} - -static void tftp_send_next_block(struct tftp_session *spt, - struct tftphdr *hdr) -{ - struct mbuf *m; - struct tftp_t *tp; - int nobytes; - - m = m_get(spt->slirp); - - if (!m) { - return; - } - - tp = tftp_prep_mbuf_data(spt, m); - - tp->hdr.tp_op = htons(TFTP_DATA); - tp->x.tp_data.tp_block_nr = htons((spt->block_nr + 1) & 0xffff); - - nobytes = tftp_read_data(spt, spt->block_nr, tp->x.tp_data.tp_buf, - spt->block_size); - - if (nobytes < 0) { - m_free(m); - - /* send "file not found" error back */ - - tftp_send_error(spt, 1, "File not found", tp); - - return; - } - - m->m_len = sizeof(struct tftp_t) - (TFTP_BLOCKSIZE_MAX - nobytes) - - sizeof(struct udphdr); - tftp_udp_output(spt, m, hdr); - - if (nobytes == spt->block_size) { - tftp_session_update(spt); - } else { - tftp_session_terminate(spt); - } - - spt->block_nr++; -} - -static void tftp_handle_rrq(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftp_t *tp, int pktlen) -{ - struct tftp_session *spt; - int s, k; - size_t prefix_len; - char *req_fname; - const char *option_name[2]; - uint32_t option_value[2]; - int nb_options = 0; - - /* check if a session already exists and if so terminate it */ - s = tftp_session_find(slirp, srcsas, &tp->hdr); - if (s >= 0) { - tftp_session_terminate(&slirp->tftp_sessions[s]); - } - - s = tftp_session_allocate(slirp, srcsas, &tp->hdr); - - if (s < 0) { - return; - } - - spt = &slirp->tftp_sessions[s]; - - /* unspecified prefix means service disabled */ - if (!slirp->tftp_prefix) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - /* skip header fields */ - k = 0; - pktlen -= offsetof(struct tftp_t, x.tp_buf); - - /* prepend tftp_prefix */ - prefix_len = strlen(slirp->tftp_prefix); - spt->filename = g_malloc(prefix_len + TFTP_FILENAME_MAX + 2); - memcpy(spt->filename, slirp->tftp_prefix, prefix_len); - spt->filename[prefix_len] = '/'; - - /* get name */ - req_fname = spt->filename + prefix_len + 1; - - while (1) { - if (k >= TFTP_FILENAME_MAX || k >= pktlen) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - req_fname[k] = tp->x.tp_buf[k]; - if (req_fname[k++] == '\0') { - break; - } - } - - DEBUG_TFTP("tftp rrq file: %s", req_fname); - - /* check mode */ - if ((pktlen - k) < 6) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - if (strcasecmp(&tp->x.tp_buf[k], "octet") != 0) { - tftp_send_error(spt, 4, "Unsupported transfer mode", tp); - return; - } - - k += 6; /* skipping octet */ - - /* do sanity checks on the filename */ - if ( -#ifdef G_OS_WIN32 - strstr(req_fname, "..\\") || - req_fname[strlen(req_fname) - 1] == '\\' || -#endif - strstr(req_fname, "../") || - req_fname[strlen(req_fname) - 1] == '/') { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - /* check if the file exists */ - if (tftp_read_data(spt, 0, NULL, 0) < 0) { - tftp_send_error(spt, 1, "File not found", tp); - return; - } - - if (tp->x.tp_buf[pktlen - 1] != 0) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - while (k < pktlen && nb_options < G_N_ELEMENTS(option_name)) { - const char *key, *value; - - key = &tp->x.tp_buf[k]; - k += strlen(key) + 1; - - if (k >= pktlen) { - tftp_send_error(spt, 2, "Access violation", tp); - return; - } - - value = &tp->x.tp_buf[k]; - k += strlen(value) + 1; - - if (strcasecmp(key, "tsize") == 0) { - int tsize = atoi(value); - struct stat stat_p; - - if (tsize == 0) { - if (stat(spt->filename, &stat_p) == 0) - tsize = stat_p.st_size; - else { - tftp_send_error(spt, 1, "File not found", tp); - return; - } - } - - option_name[nb_options] = "tsize"; - option_value[nb_options] = tsize; - nb_options++; - } else if (strcasecmp(key, "blksize") == 0) { - int blksize = atoi(value); - - /* Accept blksize up to our maximum size */ - if (blksize > 0) { - spt->block_size = MIN(blksize, TFTP_BLOCKSIZE_MAX); - option_name[nb_options] = "blksize"; - option_value[nb_options] = spt->block_size; - nb_options++; - } - } - } - - if (nb_options > 0) { - assert(nb_options <= G_N_ELEMENTS(option_name)); - tftp_send_oack(spt, option_name, option_value, nb_options, tp); - return; - } - - spt->block_nr = 0; - tftp_send_next_block(spt, &tp->hdr); -} - -static void tftp_handle_ack(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftphdr *hdr) -{ - int s; - - s = tftp_session_find(slirp, srcsas, hdr); - - if (s < 0) { - return; - } - - tftp_send_next_block(&slirp->tftp_sessions[s], hdr); -} - -static void tftp_handle_error(Slirp *slirp, struct sockaddr_storage *srcsas, - struct tftphdr *hdr) -{ - int s; - - s = tftp_session_find(slirp, srcsas, hdr); - - if (s < 0) { - return; - } - - tftp_session_terminate(&slirp->tftp_sessions[s]); -} - -void tftp_input(struct sockaddr_storage *srcsas, struct mbuf *m) -{ - struct tftphdr *hdr = mtod_check(m, sizeof(struct tftphdr)); - - if (hdr == NULL) { - return; - } - - switch (ntohs(hdr->tp_op)) { - case TFTP_RRQ: - tftp_handle_rrq(m->slirp, srcsas, - mtod(m, struct tftp_t *), - m->m_len); - break; - - case TFTP_ACK: - tftp_handle_ack(m->slirp, srcsas, hdr); - break; - - case TFTP_ERROR: - tftp_handle_error(m->slirp, srcsas, hdr); - break; - } -} diff --git a/src/network/slirp/tftp.h b/src/network/slirp/tftp.h deleted file mode 100644 index a0784885c..000000000 --- a/src/network/slirp/tftp.h +++ /dev/null @@ -1,70 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* tftp defines */ - -#ifndef SLIRP_TFTP_H -#define SLIRP_TFTP_H - -#include "util.h" - -#define TFTP_SESSIONS_MAX 20 - -#define TFTP_SERVER 69 - -#define TFTP_RRQ 1 -#define TFTP_WRQ 2 -#define TFTP_DATA 3 -#define TFTP_ACK 4 -#define TFTP_ERROR 5 -#define TFTP_OACK 6 - -#define TFTP_FILENAME_MAX 512 -#define TFTP_BLOCKSIZE_MAX 1428 - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct tftphdr { - struct udphdr udp; - uint16_t tp_op; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(push, 1) -#endif -struct tftp_t { - struct tftphdr hdr; - union { - struct { - uint16_t tp_block_nr; - uint8_t tp_buf[TFTP_BLOCKSIZE_MAX]; - } tp_data; - struct { - uint16_t tp_error_code; - uint8_t tp_msg[TFTP_BLOCKSIZE_MAX]; - } tp_error; - char tp_buf[TFTP_BLOCKSIZE_MAX + 2]; - } x; -} SLIRP_PACKED; -#if defined(_MSC_VER) && !defined (__clang__) -#pragma pack(pop) -#endif - -struct tftp_session { - Slirp *slirp; - char *filename; - int fd; - uint16_t block_size; - - struct sockaddr_storage client_addr; - uint16_t client_port; - uint32_t block_nr; - - int timestamp; -}; - -void tftp_input(struct sockaddr_storage *srcsas, struct mbuf *m); - -#endif diff --git a/src/network/slirp/tinyglib.c b/src/network/slirp/tinyglib.c deleted file mode 100644 index 7b1e27bc5..000000000 --- a/src/network/slirp/tinyglib.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Minimal reimplementation of GLib for libslirp. - * - * - * - * Author: RichardG, - * - * Copyright 2020 RichardG. - */ -#include -#include -#include - -/* Must be a function, as libslirp redefines it as a macro. */ -gboolean -g_spawn_async_with_fds(const gchar *working_directory, gchar **argv, - gchar **envp, GSpawnFlags flags, - GSpawnChildSetupFunc child_setup, - gpointer user_data, GPid *child_pid, gint stdin_fd, - gint stdout_fd, gint stderr_fd, GError **error) -{ - return 0; -} - -/* Implementation borrowed from GLib itself. */ -gboolean -g_str_has_prefix (const gchar *str, - const gchar *prefix) -{ - g_return_val_if_fail (str != NULL, false); - g_return_val_if_fail (prefix != NULL, false); - - return strncmp (str, prefix, strlen (prefix)) == 0; -} - -/* Needs bounds checking, but not really used by libslirp. */ -GString * -g_string_new(gchar *base) -{ - char *ret = malloc(4096); - if (base) - strcpy(ret, base); - return ret; -} - -/* Unimplemented, as with anything related to GString. */ -gchar * -g_string_free(GString *string, gboolean free_segment) -{ - return (free_segment ? NULL : string); -} - -/* Implementation borrowed from GLib itself. */ -gchar * -g_strstr_len(const gchar *haystack, gssize haystack_len, const gchar *needle) -{ - if (haystack_len < 0) - return strstr(haystack, needle); - else { - const gchar *p = haystack; - gsize needle_len = strlen(needle); - gsize haystack_len_unsigned = haystack_len; - const gchar *end; - gsize i; - - if (needle_len == 0) - return (gchar *) haystack; - - if (haystack_len_unsigned < needle_len) - return NULL; - - end = haystack + haystack_len - needle_len; - - while (p <= end && *p) { - for (i = 0; i < needle_len; i++) - if (p[i] != needle[i]) - goto next; - - return (gchar *) p; - -next: - p++; - } - - return NULL; - } -} - -/* Implementation borrowed from GLib itself. */ -guint -g_strv_length(gchar **str_array) -{ - guint i = 0; - while (str_array[i] != NULL) - ++i; - return i; -} - -/* Implementation borrowed from GLib itself. */ -gsize -g_strlcpy(gchar *dest, - const gchar *src, - gsize dest_size) -{ - gchar *d = dest; - const gchar *s = src; - gsize n = dest_size; - - if (dest == NULL) - return 0; - if (src == NULL) - return 0; - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) - do { - gchar c = *s++; - - *d++ = c; - if (c == 0) - break; - } while (--n != 0); - - /* If not enough room in dest, add NUL and traverse rest of src */ - if (n == 0) { - if (dest_size != 0) - *d = 0; - while (*s++) - ; - } - - return s - src - 1; /* count does not include NUL */ -} diff --git a/src/network/slirp/udp.c b/src/network/slirp/udp.c deleted file mode 100644 index bd4dbebde..000000000 --- a/src/network/slirp/udp.c +++ /dev/null @@ -1,429 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1988, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)udp_usrreq.c 8.4 (Berkeley) 1/21/94 - * udp_usrreq.c,v 1.4 1994/10/02 17:48:45 phk Exp - */ - -/* - * Changes and additions relating to SLiRP - * Copyright (c) 1995 Danny Gasparovski. - * - * Please read the file COPYRIGHT for the - * terms and conditions of the copyright. - */ - -#include "slirp.h" -#include "ip_icmp.h" - -static uint8_t udp_tos(struct socket *so); - -void udp_init(Slirp *slirp) -{ - slirp->udb.so_next = slirp->udb.so_prev = &slirp->udb; - slirp->udp_last_so = &slirp->udb; -} - -void udp_cleanup(Slirp *slirp) -{ - struct socket *so, *so_next; - - for (so = slirp->udb.so_next; so != &slirp->udb; so = so_next) { - so_next = so->so_next; - udp_detach(slirp->udb.so_next); - } -} - -/* m->m_data points at ip packet header - * m->m_len length ip packet - * ip->ip_len length data (IPDU) - */ -void udp_input(register struct mbuf *m, int iphlen) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - register struct ip *ip; - register struct udphdr *uh; - int len; - struct ip save_ip; - struct socket *so; - struct sockaddr_storage lhost; - struct sockaddr_in *lhost4; - int ttl; - - DEBUG_CALL("udp_input"); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("iphlen = %d", iphlen); - - /* - * Strip IP options, if any; should skip this, - * make available to user, and use on returned packets, - * but we don't yet have a way to check the checksum - * with options still present. - */ - if (iphlen > sizeof(struct ip)) { - ip_stripoptions(m, (struct mbuf *)0); - iphlen = sizeof(struct ip); - } - - /* - * Get IP and UDP header together in first mbuf. - */ - ip = mtod_check(m, iphlen + sizeof(struct udphdr)); - if (ip == NULL) { - goto bad; - } - uh = (struct udphdr *)((char *)ip + iphlen); - - /* - * Make mbuf data length reflect UDP length. - * If not enough data to reflect UDP length, drop. - */ - len = ntohs((uint16_t)uh->uh_ulen); - - if (ip->ip_len != len) { - if (len > ip->ip_len) { - goto bad; - } - m_adj(m, len - ip->ip_len); - ip->ip_len = len; - } - - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip = *ip; - save_ip.ip_len += iphlen; /* tcp_input subtracts this */ - - /* - * Checksum extended UDP header and data. - */ - if (uh->uh_sum) { - memset(&((struct ipovly *)ip)->ih_mbuf, 0, sizeof(struct mbuf_ptr)); - ((struct ipovly *)ip)->ih_x1 = 0; - ((struct ipovly *)ip)->ih_len = uh->uh_ulen; - if (cksum(m, len + sizeof(struct ip))) { - goto bad; - } - } - - lhost.ss_family = AF_INET; - lhost4 = (struct sockaddr_in *)&lhost; - lhost4->sin_addr = ip->ip_src; - lhost4->sin_port = uh->uh_sport; - - /* - * handle DHCP/BOOTP - */ - if (ntohs(uh->uh_dport) == BOOTP_SERVER && - (ip->ip_dst.s_addr == slirp->vhost_addr.s_addr || - ip->ip_dst.s_addr == 0xffffffff)) { - bootp_input(m); - goto bad; - } - - /* - * handle TFTP - */ - if (ntohs(uh->uh_dport) == TFTP_SERVER && - ip->ip_dst.s_addr == slirp->vhost_addr.s_addr) { - m->m_data += iphlen; - m->m_len -= iphlen; - tftp_input(&lhost, m); - m->m_data -= iphlen; - m->m_len += iphlen; - goto bad; - } - - if (slirp->restricted) { - goto bad; - } - - /* - * Locate pcb for datagram. - */ - so = solookup(&slirp->udp_last_so, &slirp->udb, &lhost, NULL); - - if (so == NULL) { - /* - * If there's no socket for this packet, - * create one - */ - so = socreate(slirp, IPPROTO_UDP); - if (udp_attach(so, AF_INET) == -1) { - DEBUG_MISC(" udp_attach errno = %d-%s", errno, strerror(errno)); - sofree(so); - goto bad; - } - - /* - * Setup fields - */ - so->so_lfamily = AF_INET; - so->so_laddr = ip->ip_src; - so->so_lport = uh->uh_sport; - - if ((so->so_iptos = udp_tos(so)) == 0) - so->so_iptos = ip->ip_tos; - - /* - * XXXXX Here, check if it's in udpexec_list, - * and if it is, do the fork_exec() etc. - */ - } - - so->so_ffamily = AF_INET; - so->so_faddr = ip->ip_dst; /* XXX */ - so->so_fport = uh->uh_dport; /* XXX */ - - iphlen += sizeof(struct udphdr); - m->m_len -= iphlen; - m->m_data += iphlen; - - /* - * Check for TTL - */ - ttl = save_ip.ip_ttl-1; - if (ttl <= 0) { - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - DEBUG_MISC("udp ttl exceeded"); - icmp_send_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, NULL); - goto bad; - } - setsockopt(so->s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); - - /* - * Now we sendto() the packet. - */ - if (sosendto(so, m) == -1) { - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno)); - icmp_send_error(m, ICMP_UNREACH, ICMP_UNREACH_NET, 0, strerror(errno)); - goto bad; - } - - m_free(so->so_m); /* used for ICMP if error on sorecvfrom */ - - /* restore the orig mbuf packet */ - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - so->so_m = m; /* ICMP backup */ - - return; -bad: - m_free(m); -} - -int udp_output(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr, - struct sockaddr_in *daddr, int iptos) -{ - Slirp *slirp = m->slirp; -// char addr[INET_ADDRSTRLEN]; - - M_DUP_DEBUG(slirp, m, 0, sizeof(struct udpiphdr)); - - register struct udpiphdr *ui; - int error = 0; - -/* - DEBUG_CALL("udp_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - DEBUG_ARG("saddr = %s", inet_ntop(AF_INET, &saddr->sin_addr, addr, sizeof(addr))); - DEBUG_ARG("daddr = %s", inet_ntop(AF_INET, &daddr->sin_addr, addr, sizeof(addr))); -*/ - - /* - * Adjust for header - */ - m->m_data -= sizeof(struct udpiphdr); - m->m_len += sizeof(struct udpiphdr); - - /* - * Fill in mbuf with extended UDP header - * and addresses and length put into network format. - */ - ui = mtod(m, struct udpiphdr *); - memset(&ui->ui_i.ih_mbuf, 0, sizeof(struct mbuf_ptr)); - ui->ui_x1 = 0; - ui->ui_pr = IPPROTO_UDP; - ui->ui_len = htons(m->m_len - sizeof(struct ip)); - /* XXXXX Check for from-one-location sockets, or from-any-location sockets - */ - ui->ui_src = saddr->sin_addr; - ui->ui_dst = daddr->sin_addr; - ui->ui_sport = saddr->sin_port; - ui->ui_dport = daddr->sin_port; - ui->ui_ulen = ui->ui_len; - - /* - * Stuff checksum and output datagram. - */ - ui->ui_sum = 0; - if ((ui->ui_sum = cksum(m, m->m_len)) == 0) - ui->ui_sum = 0xffff; - ((struct ip *)ui)->ip_len = m->m_len; - - ((struct ip *)ui)->ip_ttl = IPDEFTTL; - ((struct ip *)ui)->ip_tos = iptos; - - error = ip_output(so, m); - - return (error); -} - -int udp_attach(struct socket *so, unsigned short af) -{ - so->s = slirp_socket(af, SOCK_DGRAM, 0); - if (so->s != -1) { - if (slirp_bind_outbound(so, af) != 0) { - // bind failed - close socket - closesocket(so->s); - so->s = -1; - return -1; - } - -#ifdef __linux__ - { - int opt = 1; - switch (af) { - case AF_INET: - setsockopt(so->s, IPPROTO_IP, IP_RECVERR, &opt, sizeof(opt)); - break; - case AF_INET6: - setsockopt(so->s, IPPROTO_IPV6, IPV6_RECVERR, &opt, sizeof(opt)); - break; - default: - g_assert_not_reached(); - } - } -#endif - - so->so_expire = curtime + SO_EXPIRE; - slirp_insque(so, &so->slirp->udb); - } - so->slirp->cb->register_poll_fd(so->s, so->slirp->opaque); - return (so->s); -} - -void udp_detach(struct socket *so) -{ - so->slirp->cb->unregister_poll_fd(so->s, so->slirp->opaque); - closesocket(so->s); - sofree(so); -} - -static const struct tos_t udptos[] = { { 0, 53, IPTOS_LOWDELAY, 0 }, /* DNS */ - { 0, 0, 0, 0 } }; - -static uint8_t udp_tos(struct socket *so) -{ - int i = 0; - - while (udptos[i].tos) { - if ((udptos[i].fport && ntohs(so->so_fport) == udptos[i].fport) || - (udptos[i].lport && ntohs(so->so_lport) == udptos[i].lport)) { - if (so->slirp->enable_emu) - so->so_emu = udptos[i].emu; - return udptos[i].tos; - } - i++; - } - - return 0; -} - -struct socket *udpx_listen(Slirp *slirp, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *laddr, socklen_t laddrlen, - int flags) -{ - struct socket *so; - socklen_t addrlen; - int save_errno; - - so = socreate(slirp, IPPROTO_UDP); - so->s = slirp_socket(haddr->sa_family, SOCK_DGRAM, 0); - if (so->s < 0) { - save_errno = errno; - sofree(so); - errno = save_errno; - return NULL; - } - if (haddr->sa_family == AF_INET6) - slirp_socket_set_v6only(so->s, (flags & SS_HOSTFWD_V6ONLY) != 0); - so->so_expire = curtime + SO_EXPIRE; - slirp_insque(so, &slirp->udb); - - if (bind(so->s, haddr, haddrlen) < 0) { - save_errno = errno; - udp_detach(so); - errno = save_errno; - return NULL; - } - slirp_socket_set_fast_reuse(so->s); - - addrlen = sizeof(so->fhost); - getsockname(so->s, &so->fhost.sa, &addrlen); - sotranslate_accept(so); - - sockaddr_copy(&so->lhost.sa, sizeof(so->lhost), laddr, laddrlen); - - if (flags != SS_FACCEPTONCE) - so->so_expire = 0; - so->so_state &= SS_PERSISTENT_MASK; - so->so_state |= SS_ISFCONNECTED | flags; - - return so; -} - -struct socket *udp_listen(Slirp *slirp, uint32_t haddr, unsigned hport, - uint32_t laddr, unsigned lport, int flags) -{ - struct sockaddr_in hsa, lsa; - - memset(&hsa, 0, sizeof(hsa)); - hsa.sin_family = AF_INET; - hsa.sin_addr.s_addr = haddr; - hsa.sin_port = hport; - - memset(&lsa, 0, sizeof(lsa)); - lsa.sin_family = AF_INET; - lsa.sin_addr.s_addr = laddr; - lsa.sin_port = lport; - - return udpx_listen(slirp, (const struct sockaddr *) &hsa, sizeof(hsa), (struct sockaddr *) &lsa, sizeof(lsa), flags); -} diff --git a/src/network/slirp/udp.h b/src/network/slirp/udp.h deleted file mode 100644 index 47f4ed34d..000000000 --- a/src/network/slirp/udp.h +++ /dev/null @@ -1,96 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 1982, 1986, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)udp.h 8.1 (Berkeley) 6/10/93 - * udp.h,v 1.3 1994/08/21 05:27:41 paul Exp - */ - -#ifndef UDP_H -#define UDP_H - -#include "socket.h" - -#define UDP_TTL 0x60 -#define UDP_UDPDATALEN 16192 - -/* - * Udp protocol header. - * Per RFC 768, September, 1981. - */ -struct udphdr { - uint16_t uh_sport; /* source port */ - uint16_t uh_dport; /* destination port */ - int16_t uh_ulen; /* udp length */ - uint16_t uh_sum; /* udp checksum */ -}; - -/* - * UDP kernel structures and variables. - */ -struct udpiphdr { - struct ipovly ui_i; /* overlaid ip structure */ - struct udphdr ui_u; /* udp header */ -}; -#define ui_mbuf ui_i.ih_mbuf.mptr -#define ui_x1 ui_i.ih_x1 -#define ui_pr ui_i.ih_pr -#define ui_len ui_i.ih_len -#define ui_src ui_i.ih_src -#define ui_dst ui_i.ih_dst -#define ui_sport ui_u.uh_sport -#define ui_dport ui_u.uh_dport -#define ui_ulen ui_u.uh_ulen -#define ui_sum ui_u.uh_sum - -/* - * Names for UDP sysctl objects - */ -#define UDPCTL_CHECKSUM 1 /* checksum UDP packets */ -#define UDPCTL_MAXID 2 - -struct mbuf; - -void udp_init(Slirp *); -void udp_cleanup(Slirp *); -void udp_input(register struct mbuf *, int); -int udp_attach(struct socket *, unsigned short af); -void udp_detach(struct socket *); -struct socket *udp_listen(Slirp *, uint32_t, unsigned, uint32_t, unsigned, int); -struct socket *udpx_listen(Slirp *, - const struct sockaddr *haddr, socklen_t haddrlen, - const struct sockaddr *laddr, socklen_t laddrlen, - int flags); -int udp_output(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr, - struct sockaddr_in *daddr, int iptos); - -void udp6_input(register struct mbuf *); -int udp6_output(struct socket *so, struct mbuf *m, struct sockaddr_in6 *saddr, - struct sockaddr_in6 *daddr); - -#endif diff --git a/src/network/slirp/udp6.c b/src/network/slirp/udp6.c deleted file mode 100644 index effdf77d0..000000000 --- a/src/network/slirp/udp6.c +++ /dev/null @@ -1,196 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright (c) 2013 - * Guillaume Subiron - */ - -#include "slirp.h" -#include "udp.h" -#include "dhcpv6.h" - -void udp6_input(struct mbuf *m) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, 0); - - struct ip6 *ip, save_ip; - struct udphdr *uh; - int iphlen = sizeof(struct ip6); - int len; - struct socket *so; - struct sockaddr_in6 lhost; - int hop_limit; - - DEBUG_CALL("udp6_input"); - DEBUG_ARG("m = %p", m); - - if (slirp->restricted) { - goto bad; - } - - ip = mtod(m, struct ip6 *); - m->m_len -= iphlen; - m->m_data += iphlen; - uh = mtod_check(m, sizeof(struct udphdr)); - if (uh == NULL) { - goto bad; - } - m->m_len += iphlen; - m->m_data -= iphlen; - - if (ip6_cksum(m)) { - goto bad; - } - - len = ntohs((uint16_t)uh->uh_ulen); - - /* - * Make mbuf data length reflect UDP length. - * If not enough data to reflect UDP length, drop. - */ - if (ntohs(ip->ip_pl) != len) { - if (len > ntohs(ip->ip_pl)) { - goto bad; - } - m_adj(m, len - ntohs(ip->ip_pl)); - ip->ip_pl = htons(len); - } - - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip = *ip; - - /* Locate pcb for datagram. */ - lhost.sin6_family = AF_INET6; - lhost.sin6_addr = ip->ip_src; - lhost.sin6_port = uh->uh_sport; - - /* handle DHCPv6 */ - if (ntohs(uh->uh_dport) == DHCPV6_SERVER_PORT && - (in6_equal(&ip->ip_dst, &slirp->vhost_addr6) || - in6_dhcp_multicast(&ip->ip_dst))) { - m->m_data += iphlen; - m->m_len -= iphlen; - dhcpv6_input(&lhost, m); - m->m_data -= iphlen; - m->m_len += iphlen; - goto bad; - } - - /* handle TFTP */ - if (ntohs(uh->uh_dport) == TFTP_SERVER && - !memcmp(ip->ip_dst.s6_addr, slirp->vhost_addr6.s6_addr, 16)) { - m->m_data += iphlen; - m->m_len -= iphlen; - tftp_input((struct sockaddr_storage *)&lhost, m); - m->m_data -= iphlen; - m->m_len += iphlen; - goto bad; - } - - so = solookup(&slirp->udp_last_so, &slirp->udb, - (struct sockaddr_storage *)&lhost, NULL); - - if (so == NULL) { - /* If there's no socket for this packet, create one. */ - so = socreate(slirp, IPPROTO_UDP); - if (udp_attach(so, AF_INET6) == -1) { - DEBUG_MISC(" udp6_attach errno = %d-%s", errno, strerror(errno)); - sofree(so); - goto bad; - } - - /* Setup fields */ - so->so_lfamily = AF_INET6; - so->so_laddr6 = ip->ip_src; - so->so_lport6 = uh->uh_sport; - } - - so->so_ffamily = AF_INET6; - so->so_faddr6 = ip->ip_dst; /* XXX */ - so->so_fport6 = uh->uh_dport; /* XXX */ - - iphlen += sizeof(struct udphdr); - m->m_len -= iphlen; - m->m_data += iphlen; - - /* - * Check for TTL - */ - hop_limit = save_ip.ip_hl-1; - if (hop_limit <= 0) { - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - DEBUG_MISC("udp ttl exceeded"); - icmp6_send_error(m, ICMP6_TIMXCEED, ICMP6_TIMXCEED_INTRANS); - goto bad; - } - setsockopt(so->s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &hop_limit, sizeof(hop_limit)); - - /* - * Now we sendto() the packet. - */ - if (sosendto(so, m) == -1) { - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - DEBUG_MISC("udp tx errno = %d-%s", errno, strerror(errno)); - icmp6_send_error(m, ICMP6_UNREACH, ICMP6_UNREACH_NO_ROUTE); - goto bad; - } - - m_free(so->so_m); /* used for ICMP if error on sorecvfrom */ - - /* restore the orig mbuf packet */ - m->m_len += iphlen; - m->m_data -= iphlen; - *ip = save_ip; - so->so_m = m; - - return; -bad: - m_free(m); -} - -int udp6_output(struct socket *so, struct mbuf *m, struct sockaddr_in6 *saddr, - struct sockaddr_in6 *daddr) -{ - Slirp *slirp = m->slirp; - M_DUP_DEBUG(slirp, m, 0, sizeof(struct ip6) + sizeof(struct udphdr)); - - struct ip6 *ip; - struct udphdr *uh; - - DEBUG_CALL("udp6_output"); - DEBUG_ARG("so = %p", so); - DEBUG_ARG("m = %p", m); - - /* adjust for header */ - m->m_data -= sizeof(struct udphdr); - m->m_len += sizeof(struct udphdr); - uh = mtod(m, struct udphdr *); - m->m_data -= sizeof(struct ip6); - m->m_len += sizeof(struct ip6); - ip = mtod(m, struct ip6 *); - - /* Build IP header */ - ip->ip_pl = htons(m->m_len - sizeof(struct ip6)); - ip->ip_nh = IPPROTO_UDP; - ip->ip_src = saddr->sin6_addr; - ip->ip_dst = daddr->sin6_addr; - - /* Build UDP header */ - uh->uh_sport = saddr->sin6_port; - uh->uh_dport = daddr->sin6_port; - uh->uh_ulen = ip->ip_pl; - uh->uh_sum = 0; - uh->uh_sum = ip6_cksum(m); - if (uh->uh_sum == 0) { - uh->uh_sum = 0xffff; - } - - return ip6_output(so, m, 0); -} diff --git a/src/network/slirp/util.c b/src/network/slirp/util.c deleted file mode 100644 index 7297e5022..000000000 --- a/src/network/slirp/util.c +++ /dev/null @@ -1,442 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * util.c (mostly based on QEMU os-win32.c) - * - * Copyright (c) 2003-2008 Fabrice Bellard - * Copyright (c) 2010-2016 Red Hat, Inc. - * - * QEMU library functions for win32 which are shared between QEMU and - * the QEMU tools. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#include "util.h" - -#include -#include -#include -#include - -#if defined(_WIN32) -int slirp_inet_aton(const char *cp, struct in_addr *ia) -{ - uint32_t addr = inet_addr(cp); - if (addr == 0xffffffff) { - return 0; - } - ia->s_addr = addr; - return 1; -} -#endif - -void slirp_set_nonblock(int fd) -{ -#ifndef _WIN32 - int f; - f = fcntl(fd, F_GETFL); - assert(f != -1); - f = fcntl(fd, F_SETFL, f | O_NONBLOCK); - assert(f != -1); -#else - unsigned long opt = 1; - ioctlsocket(fd, FIONBIO, &opt); -#endif -} - -static void slirp_set_cloexec(int fd) -{ -#ifndef _WIN32 - int f; - f = fcntl(fd, F_GETFD); - assert(f != -1); - f = fcntl(fd, F_SETFD, f | FD_CLOEXEC); - assert(f != -1); -#endif -} - -/* - * Opens a socket with FD_CLOEXEC set - * On failure errno contains the reason. - */ -int slirp_socket(int domain, int type, int protocol) -{ - int ret; - -#ifdef SOCK_CLOEXEC - ret = socket(domain, type | SOCK_CLOEXEC, protocol); - if (ret != -1 || errno != EINVAL) { - return ret; - } -#endif - ret = socket(domain, type, protocol); - if (ret >= 0) { - slirp_set_cloexec(ret); - } - - return ret; -} - -#ifdef _WIN32 -static int socket_error(void) -{ - switch (WSAGetLastError()) { - case 0: - return 0; - case WSAEINTR: - return EINTR; - case WSAEINVAL: - return EINVAL; - case WSA_INVALID_HANDLE: - return EBADF; - case WSA_NOT_ENOUGH_MEMORY: - return ENOMEM; - case WSA_INVALID_PARAMETER: - return EINVAL; - case WSAENAMETOOLONG: - return ENAMETOOLONG; - case WSAENOTEMPTY: - return ENOTEMPTY; - case WSAEWOULDBLOCK: - /* not using EWOULDBLOCK as we don't want code to have - * to check both EWOULDBLOCK and EAGAIN */ - return EAGAIN; - case WSAEINPROGRESS: - return EINPROGRESS; - case WSAEALREADY: - return EALREADY; - case WSAENOTSOCK: - return ENOTSOCK; - case WSAEDESTADDRREQ: - return EDESTADDRREQ; - case WSAEMSGSIZE: - return EMSGSIZE; - case WSAEPROTOTYPE: - return EPROTOTYPE; - case WSAENOPROTOOPT: - return ENOPROTOOPT; - case WSAEPROTONOSUPPORT: - return EPROTONOSUPPORT; - case WSAEOPNOTSUPP: - return EOPNOTSUPP; - case WSAEAFNOSUPPORT: - return EAFNOSUPPORT; - case WSAEADDRINUSE: - return EADDRINUSE; - case WSAEADDRNOTAVAIL: - return EADDRNOTAVAIL; - case WSAENETDOWN: - return ENETDOWN; - case WSAENETUNREACH: - return ENETUNREACH; - case WSAENETRESET: - return ENETRESET; - case WSAECONNABORTED: - return ECONNABORTED; - case WSAECONNRESET: - return ECONNRESET; - case WSAENOBUFS: - return ENOBUFS; - case WSAEISCONN: - return EISCONN; - case WSAENOTCONN: - return ENOTCONN; - case WSAETIMEDOUT: - return ETIMEDOUT; - case WSAECONNREFUSED: - return ECONNREFUSED; - case WSAELOOP: - return ELOOP; - case WSAEHOSTUNREACH: - return EHOSTUNREACH; - default: - return EIO; - } -} - -#undef ioctlsocket -int slirp_ioctlsocket_wrap(int fd, int req, void *val) -{ - int ret; - ret = ioctlsocket(fd, req, val); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef closesocket -int slirp_closesocket_wrap(int fd) -{ - int ret; - ret = closesocket(fd); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef connect -int slirp_connect_wrap(int sockfd, const struct sockaddr *addr, int addrlen) -{ - int ret; - ret = connect(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef listen -int slirp_listen_wrap(int sockfd, int backlog) -{ - int ret; - ret = listen(sockfd, backlog); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef bind -int slirp_bind_wrap(int sockfd, const struct sockaddr *addr, int addrlen) -{ - int ret; - ret = bind(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef socket -int slirp_socket_wrap(int domain, int type, int protocol) -{ - int ret; - ret = socket(domain, type, protocol); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef accept -int slirp_accept_wrap(int sockfd, struct sockaddr *addr, int *addrlen) -{ - int ret; - ret = accept(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef shutdown -int slirp_shutdown_wrap(int sockfd, int how) -{ - int ret; - ret = shutdown(sockfd, how); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef getsockopt -int slirp_getsockopt_wrap(int sockfd, int level, int optname, void *optval, - int *optlen) -{ - int ret; - ret = getsockopt(sockfd, level, optname, optval, optlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef setsockopt -int slirp_setsockopt_wrap(int sockfd, int level, int optname, - const void *optval, int optlen) -{ - int ret; - ret = setsockopt(sockfd, level, optname, optval, optlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef getpeername -int slirp_getpeername_wrap(int sockfd, struct sockaddr *addr, int *addrlen) -{ - int ret; - ret = getpeername(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef getsockname -int slirp_getsockname_wrap(int sockfd, struct sockaddr *addr, int *addrlen) -{ - int ret; - ret = getsockname(sockfd, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef send -ssize_t slirp_send_wrap(int sockfd, const void *buf, size_t len, int flags) -{ - int ret; - ret = send(sockfd, buf, len, flags); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef sendto -ssize_t slirp_sendto_wrap(int sockfd, const void *buf, size_t len, int flags, - const struct sockaddr *addr, int addrlen) -{ - int ret; - ret = sendto(sockfd, buf, len, flags, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef recv -ssize_t slirp_recv_wrap(int sockfd, void *buf, size_t len, int flags) -{ - int ret; - ret = recv(sockfd, buf, len, flags); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} - -#undef recvfrom -ssize_t slirp_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags, - struct sockaddr *addr, int *addrlen) -{ - int ret; - ret = recvfrom(sockfd, buf, len, flags, addr, addrlen); - if (ret < 0) { - errno = socket_error(); - } - return ret; -} -#endif /* WIN32 */ - -void slirp_pstrcpy(char *buf, int buf_size, const char *str) -{ - int c; - char *q = buf; - - if (buf_size <= 0) - return; - - for (;;) { - c = *str++; - if (c == 0 || q >= buf + buf_size - 1) - break; - *q++ = c; - } - *q = '\0'; -} - -G_GNUC_PRINTF(3, 0) -static int slirp_vsnprintf(char *str, size_t size, - const char *format, va_list args) -{ - int rv = g_vsnprintf(str, size, format, args); - - if (rv < 0) { - g_error("g_vsnprintf() failed: %s", g_strerror(errno)); - } - - return rv; -} - -/* - * A snprintf()-like function that: - * - returns the number of bytes written (excluding optional \0-ending) - * - dies on error - * - warn on truncation - */ -int slirp_fmt(char *str, size_t size, const char *format, ...) -{ - va_list args; - int rv; - - va_start(args, format); - rv = slirp_vsnprintf(str, size, format, args); - va_end(args); - - if (rv >= size) { - g_critical("slirp_fmt() truncation"); - } - - return MIN(rv, size); -} - -/* - * A snprintf()-like function that: - * - always \0-end (unless size == 0) - * - returns the number of bytes actually written, including \0 ending - * - dies on error - * - warn on truncation - */ -int slirp_fmt0(char *str, size_t size, const char *format, ...) -{ - va_list args; - int rv; - - va_start(args, format); - rv = slirp_vsnprintf(str, size, format, args); - va_end(args); - - if (rv >= size) { - g_critical("slirp_fmt0() truncation"); - if (size > 0) - str[size - 1] = '\0'; - rv = size; - } else { - rv += 1; /* include \0 */ - } - - return rv; -} - -const char *slirp_ether_ntoa(const uint8_t *addr, char *out_str, - size_t out_str_size) -{ - assert(out_str_size >= ETH_ADDRSTRLEN); - - slirp_fmt0(out_str, out_str_size, "%02x:%02x:%02x:%02x:%02x:%02x", - addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); - - return out_str; -} diff --git a/src/network/slirp/util.h b/src/network/slirp/util.h deleted file mode 100644 index 0f0123a34..000000000 --- a/src/network/slirp/util.h +++ /dev/null @@ -1,201 +0,0 @@ -/* SPDX-License-Identifier: MIT */ -/* - * Copyright (c) 2003-2008 Fabrice Bellard - * Copyright (c) 2010-2019 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -#ifndef UTIL_H_ -#define UTIL_H_ - -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#include -#include -#include -#else -#include -#include -#include -#include -#endif - -#if defined(_MSC_VER) && !defined(__clang__) -#define SLIRP_PACKED -#elif defined(_WIN32) && (defined(__x86_64__) || defined(__i386__)) && !defined(__clang__) -#define SLIRP_PACKED __attribute__((gcc_struct, packed)) -#else -#define SLIRP_PACKED __attribute__((packed)) -#endif - -#ifndef DIV_ROUND_UP -#define DIV_ROUND_UP(n, d) (((n) + (d)-1) / (d)) -#endif - -#ifndef container_of -#define container_of(ptr, type, member) \ - ((type *) (((char *)(ptr)) - offsetof(type, member))); -#endif - -#ifndef G_SIZEOF_MEMBER -#define G_SIZEOF_MEMBER(type, member) sizeof(((type *)0)->member) -#endif - -#if defined(_WIN32) /* CONFIG_IOVEC */ -#if !defined(IOV_MAX) /* XXX: to avoid duplicate with QEMU osdep.h */ -struct iovec { - void *iov_base; - size_t iov_len; -}; -#endif -#else -#include -#endif - -#define stringify(s) tostring(s) -#define tostring(s) #s - -#define SCALE_MS 1000000 - -#define ETH_ALEN 6 -#define ETH_ADDRSTRLEN 18 /* "xx:xx:xx:xx:xx:xx", with trailing NUL */ -#define ETH_HLEN 14 -#define ETH_P_IP (0x0800) /* Internet Protocol packet */ -#define ETH_P_ARP (0x0806) /* Address Resolution packet */ -#define ETH_P_IPV6 (0x86dd) -#define ETH_P_VLAN (0x8100) -#define ETH_P_DVLAN (0x88a8) -#define ETH_P_NCSI (0x88f8) -#define ETH_P_UNKNOWN (0xffff) - -/* FIXME: remove me when made standalone */ -#ifdef _WIN32 -#undef accept -#undef bind -#undef closesocket -#undef connect -#undef getpeername -#undef getsockname -#undef getsockopt -#undef ioctlsocket -#undef listen -#undef recv -#undef recvfrom -#undef send -#undef sendto -#undef setsockopt -#undef shutdown -#undef socket -#endif - -#ifdef _WIN32 -#define connect slirp_connect_wrap -int slirp_connect_wrap(int fd, const struct sockaddr *addr, int addrlen); -#define listen slirp_listen_wrap -int slirp_listen_wrap(int fd, int backlog); -#define bind slirp_bind_wrap -int slirp_bind_wrap(int fd, const struct sockaddr *addr, int addrlen); -#define socket slirp_socket_wrap -int slirp_socket_wrap(int domain, int type, int protocol); -#define accept slirp_accept_wrap -int slirp_accept_wrap(int fd, struct sockaddr *addr, int *addrlen); -#define shutdown slirp_shutdown_wrap -int slirp_shutdown_wrap(int fd, int how); -#define getpeername slirp_getpeername_wrap -int slirp_getpeername_wrap(int fd, struct sockaddr *addr, int *addrlen); -#define getsockname slirp_getsockname_wrap -int slirp_getsockname_wrap(int fd, struct sockaddr *addr, int *addrlen); -#define send slirp_send_wrap -ssize_t slirp_send_wrap(int fd, const void *buf, size_t len, int flags); -#define sendto slirp_sendto_wrap -ssize_t slirp_sendto_wrap(int fd, const void *buf, size_t len, int flags, - const struct sockaddr *dest_addr, int addrlen); -#define recv slirp_recv_wrap -ssize_t slirp_recv_wrap(int fd, void *buf, size_t len, int flags); -#define recvfrom slirp_recvfrom_wrap -ssize_t slirp_recvfrom_wrap(int fd, void *buf, size_t len, int flags, - struct sockaddr *src_addr, int *addrlen); -#define closesocket slirp_closesocket_wrap -int slirp_closesocket_wrap(int fd); -#define ioctlsocket slirp_ioctlsocket_wrap -int slirp_ioctlsocket_wrap(int fd, int req, void *val); -#define getsockopt slirp_getsockopt_wrap -int slirp_getsockopt_wrap(int sockfd, int level, int optname, void *optval, - int *optlen); -#define setsockopt slirp_setsockopt_wrap -int slirp_setsockopt_wrap(int sockfd, int level, int optname, - const void *optval, int optlen); -#define inet_aton slirp_inet_aton -int slirp_inet_aton(const char *cp, struct in_addr *ia); -#else -#define closesocket(s) close(s) -#define ioctlsocket(s, r, v) ioctl(s, r, v) -#endif - -int slirp_socket(int domain, int type, int protocol); -void slirp_set_nonblock(int fd); - -static inline int slirp_socket_set_v6only(int fd, int v) -{ - return setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v, sizeof(v)); -} - -static inline int slirp_socket_set_nodelay(int fd) -{ - int v = 1; - return setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v)); -} - -static inline int slirp_socket_set_fast_reuse(int fd) -{ -#ifndef _WIN32 - int v = 1; - return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v)); -#else - /* Enabling the reuse of an endpoint that was used by a socket still in - * TIME_WAIT state is usually performed by setting SO_REUSEADDR. On Windows - * fast reuse is the default and SO_REUSEADDR does strange things. So we - * don't have to do anything here. More info can be found at: - * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621.aspx */ - return 0; -#endif -} - -void slirp_pstrcpy(char *buf, int buf_size, const char *str); - -int slirp_fmt(char *str, size_t size, const char *format, ...) G_GNUC_PRINTF(3, 4); -int slirp_fmt0(char *str, size_t size, const char *format, ...) G_GNUC_PRINTF(3, 4); - -/* - * Pretty print a MAC address into out_str. - * As a convenience returns out_str. - */ -const char *slirp_ether_ntoa(const uint8_t *addr, char *out_str, - size_t out_str_len); - -#endif diff --git a/src/network/slirp/version.c b/src/network/slirp/version.c deleted file mode 100644 index 93e0be9c2..000000000 --- a/src/network/slirp/version.c +++ /dev/null @@ -1,8 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -#include "libslirp.h" - -const char * -slirp_version_string(void) -{ - return SLIRP_VERSION_STRING; -} diff --git a/src/network/slirp/vmstate.c b/src/network/slirp/vmstate.c deleted file mode 100644 index b9926ea41..000000000 --- a/src/network/slirp/vmstate.c +++ /dev/null @@ -1,444 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * VMState interpreter - * - * Copyright (c) 2009-2018 Red Hat Inc - * - * Authors: - * Juan Quintela - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include -#include - -#include "stream.h" -#include "vmstate.h" - -static int get_nullptr(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - if (slirp_istream_read_u8(f) == VMS_NULLPTR_MARKER) { - return 0; - } - g_warning("vmstate: get_nullptr expected VMS_NULLPTR_MARKER"); - return -EINVAL; -} - -static int put_nullptr(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) - -{ - if (pv == NULL) { - slirp_ostream_write_u8(f, VMS_NULLPTR_MARKER); - return 0; - } - g_warning("vmstate: put_nullptr must be called with pv == NULL"); - return -EINVAL; -} - -const VMStateInfo slirp_vmstate_info_nullptr = { - .name = "uint64", - .get = get_nullptr, - .put = put_nullptr, -}; - -/* 8 bit unsigned int */ - -static int get_uint8(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint8_t *v = pv; - *v = slirp_istream_read_u8(f); - return 0; -} - -static int put_uint8(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint8_t *v = pv; - slirp_ostream_write_u8(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_uint8 = { - .name = "uint8", - .get = get_uint8, - .put = put_uint8, -}; - -/* 16 bit unsigned int */ - -static int get_uint16(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint16_t *v = pv; - *v = slirp_istream_read_u16(f); - return 0; -} - -static int put_uint16(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint16_t *v = pv; - slirp_ostream_write_u16(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_uint16 = { - .name = "uint16", - .get = get_uint16, - .put = put_uint16, -}; - -/* 32 bit unsigned int */ - -static int get_uint32(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint32_t *v = pv; - *v = slirp_istream_read_u32(f); - return 0; -} - -static int put_uint32(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - uint32_t *v = pv; - slirp_ostream_write_u32(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_uint32 = { - .name = "uint32", - .get = get_uint32, - .put = put_uint32, -}; - -/* 16 bit int */ - -static int get_int16(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int16_t *v = pv; - *v = slirp_istream_read_i16(f); - return 0; -} - -static int put_int16(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int16_t *v = pv; - slirp_ostream_write_i16(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_int16 = { - .name = "int16", - .get = get_int16, - .put = put_int16, -}; - -/* 32 bit int */ - -static int get_int32(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int32_t *v = pv; - *v = slirp_istream_read_i32(f); - return 0; -} - -static int put_int32(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int32_t *v = pv; - slirp_ostream_write_i32(f, *v); - return 0; -} - -const VMStateInfo slirp_vmstate_info_int32 = { - .name = "int32", - .get = get_int32, - .put = put_int32, -}; - -/* vmstate_info_tmp, see VMSTATE_WITH_TMP, the idea is that we allocate - * a temporary buffer and the pre_load/pre_save methods in the child vmsd - * copy stuff from the parent into the child and do calculations to fill - * in fields that don't really exist in the parent but need to be in the - * stream. - */ -static int get_tmp(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - int ret; - const VMStateDescription *vmsd = field->vmsd; - int version_id = field->version_id; - void *tmp = g_malloc(size); - - /* Writes the parent field which is at the start of the tmp */ - *(void **)tmp = pv; - ret = slirp_vmstate_load_state(f, vmsd, tmp, version_id); - g_free(tmp); - return ret; -} - -static int put_tmp(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - const VMStateDescription *vmsd = field->vmsd; - void *tmp = g_malloc(size); - int ret; - - /* Writes the parent field which is at the start of the tmp */ - *(void **)tmp = pv; - ret = slirp_vmstate_save_state(f, vmsd, tmp); - g_free(tmp); - - return ret; -} - -const VMStateInfo slirp_vmstate_info_tmp = { - .name = "tmp", - .get = get_tmp, - .put = put_tmp, -}; - -/* uint8_t buffers */ - -static int get_buffer(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field) -{ - slirp_istream_read(f, pv, size); - return 0; -} - -static int put_buffer(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field) -{ - slirp_ostream_write(f, pv, size); - return 0; -} - -const VMStateInfo slirp_vmstate_info_buffer = { - .name = "buffer", - .get = get_buffer, - .put = put_buffer, -}; - -static int vmstate_n_elems(void *opaque, const VMStateField *field) -{ - int n_elems = 1; - - if (field->flags & VMS_ARRAY) { - n_elems = field->num; - } else if (field->flags & VMS_VARRAY_INT32) { - n_elems = *(int32_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT32) { - n_elems = *(uint32_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT16) { - n_elems = *(uint16_t *)(opaque + field->num_offset); - } else if (field->flags & VMS_VARRAY_UINT8) { - n_elems = *(uint8_t *)(opaque + field->num_offset); - } - - if (field->flags & VMS_MULTIPLY_ELEMENTS) { - n_elems *= field->num; - } - - return n_elems; -} - -static int vmstate_size(void *opaque, const VMStateField *field) -{ - int size = field->size; - - if (field->flags & VMS_VBUFFER) { - size = *(int32_t *)(opaque + field->size_offset); - if (field->flags & VMS_MULTIPLY) { - size *= field->size; - } - } - - return size; -} - -static int vmstate_save_state_v(SlirpOStream *f, const VMStateDescription *vmsd, - void *opaque, int version_id) -{ - int ret = 0; - const VMStateField *field = vmsd->fields; - - if (vmsd->pre_save) { - ret = vmsd->pre_save(opaque); - if (ret) { - g_warning("pre-save failed: %s", vmsd->name); - return ret; - } - } - - while (field->name) { - if ((field->field_exists && field->field_exists(opaque, version_id)) || - (!field->field_exists && field->version_id <= version_id)) { - void *first_elem = opaque + field->offset; - int i, n_elems = vmstate_n_elems(opaque, field); - int size = vmstate_size(opaque, field); - - if (field->flags & VMS_POINTER) { - first_elem = *(void **)first_elem; - assert(first_elem || !n_elems || !size); - } - for (i = 0; i < n_elems; i++) { - void *curr_elem = first_elem + size * i; - - if (field->flags & VMS_ARRAY_OF_POINTER) { - assert(curr_elem); - curr_elem = *(void **)curr_elem; - } - if (!curr_elem && size) { - /* if null pointer write placeholder and do not follow */ - assert(field->flags & VMS_ARRAY_OF_POINTER); - ret = slirp_vmstate_info_nullptr.put(f, curr_elem, size, - NULL); - } else if (field->flags & VMS_STRUCT) { - ret = slirp_vmstate_save_state(f, field->vmsd, curr_elem); - } else if (field->flags & VMS_VSTRUCT) { - ret = vmstate_save_state_v(f, field->vmsd, curr_elem, - field->struct_version_id); - } else { - ret = field->info->put(f, curr_elem, size, field); - } - if (ret) { - g_warning("Save of field %s/%s failed", vmsd->name, - field->name); - return ret; - } - } - } else { - if (field->flags & VMS_MUST_EXIST) { - g_warning("Output state validation failed: %s/%s", vmsd->name, - field->name); - assert(!(field->flags & VMS_MUST_EXIST)); - } - } - field++; - } - - return 0; -} - -int slirp_vmstate_save_state(SlirpOStream *f, const VMStateDescription *vmsd, - void *opaque) -{ - return vmstate_save_state_v(f, vmsd, opaque, vmsd->version_id); -} - -static void vmstate_handle_alloc(void *ptr, VMStateField *field, void *opaque) -{ - if (field->flags & VMS_POINTER && field->flags & VMS_ALLOC) { - size_t size = vmstate_size(opaque, field); - size *= vmstate_n_elems(opaque, field); - if (size) { - *(void **)ptr = g_malloc(size); - } - } -} - -int slirp_vmstate_load_state(SlirpIStream *f, const VMStateDescription *vmsd, - void *opaque, int version_id) -{ - VMStateField *field = vmsd->fields; - int ret = 0; - - if (version_id > vmsd->version_id) { - g_warning("%s: incoming version_id %d is too new " - "for local version_id %d", - vmsd->name, version_id, vmsd->version_id); - return -EINVAL; - } - if (vmsd->pre_load) { - int ret = vmsd->pre_load(opaque); - if (ret) { - return ret; - } - } - while (field->name) { - if ((field->field_exists && field->field_exists(opaque, version_id)) || - (!field->field_exists && field->version_id <= version_id)) { - void *first_elem = opaque + field->offset; - int i, n_elems = vmstate_n_elems(opaque, field); - int size = vmstate_size(opaque, field); - - vmstate_handle_alloc(first_elem, field, opaque); - if (field->flags & VMS_POINTER) { - first_elem = *(void **)first_elem; - assert(first_elem || !n_elems || !size); - } - for (i = 0; i < n_elems; i++) { - void *curr_elem = first_elem + size * i; - - if (field->flags & VMS_ARRAY_OF_POINTER) { - curr_elem = *(void **)curr_elem; - } - if (!curr_elem && size) { - /* if null pointer check placeholder and do not follow */ - assert(field->flags & VMS_ARRAY_OF_POINTER); - ret = slirp_vmstate_info_nullptr.get(f, curr_elem, size, - NULL); - } else if (field->flags & VMS_STRUCT) { - ret = slirp_vmstate_load_state(f, field->vmsd, curr_elem, - field->vmsd->version_id); - } else if (field->flags & VMS_VSTRUCT) { - ret = slirp_vmstate_load_state(f, field->vmsd, curr_elem, - field->struct_version_id); - } else { - ret = field->info->get(f, curr_elem, size, field); - } - if (ret < 0) { - g_warning("Failed to load %s:%s", vmsd->name, field->name); - return ret; - } - } - } else if (field->flags & VMS_MUST_EXIST) { - g_warning("Input validation failed: %s/%s", vmsd->name, - field->name); - return -1; - } - field++; - } - if (vmsd->post_load) { - ret = vmsd->post_load(opaque, version_id); - } - return ret; -} diff --git a/src/network/slirp/vmstate.h b/src/network/slirp/vmstate.h deleted file mode 100644 index b1d40e892..000000000 --- a/src/network/slirp/vmstate.h +++ /dev/null @@ -1,404 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * QEMU migration/snapshot declarations - * - * Copyright (c) 2009-2011 Red Hat, Inc. - * - * Original author: Juan Quintela - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the following - * disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef VMSTATE_H_ -#define VMSTATE_H_ - -#ifndef _WIN32 -#include -#endif -#include -#include -#include "slirp.h" -#include "stream.h" - -#define stringify(s) tostring(s) -#define tostring(s) #s - -typedef struct VMStateInfo VMStateInfo; -typedef struct VMStateDescription VMStateDescription; -typedef struct VMStateField VMStateField; - -int slirp_vmstate_save_state(SlirpOStream *f, const VMStateDescription *vmsd, - void *opaque); -int slirp_vmstate_load_state(SlirpIStream *f, const VMStateDescription *vmsd, - void *opaque, int version_id); - -/* VMStateInfo allows customized migration of objects that don't fit in - * any category in VMStateFlags. Additional information is always passed - * into get and put in terms of field and vmdesc parameters. However - * these two parameters should only be used in cases when customized - * handling is needed, such as QTAILQ. For primitive data types such as - * integer, field and vmdesc parameters should be ignored inside get/put. - */ -struct VMStateInfo { - const char *name; - int (*get)(SlirpIStream *f, void *pv, size_t size, - const VMStateField *field); - int (*put)(SlirpOStream *f, void *pv, size_t size, - const VMStateField *field); -}; - -enum VMStateFlags { - /* Ignored */ - VMS_SINGLE = 0x001, - - /* The struct member at opaque + VMStateField.offset is a pointer - * to the actual field (e.g. struct a { uint8_t *b; - * }). Dereference the pointer before using it as basis for - * further pointer arithmetic (see e.g. VMS_ARRAY). Does not - * affect the meaning of VMStateField.num_offset or - * VMStateField.size_offset; see VMS_VARRAY* and VMS_VBUFFER for - * those. */ - VMS_POINTER = 0x002, - - /* The field is an array of fixed size. VMStateField.num contains - * the number of entries in the array. The size of each entry is - * given by VMStateField.size and / or opaque + - * VMStateField.size_offset; see VMS_VBUFFER and - * VMS_MULTIPLY. Each array entry will be processed individually - * (VMStateField.info.get()/put() if VMS_STRUCT is not set, - * recursion into VMStateField.vmsd if VMS_STRUCT is set). May not - * be combined with VMS_VARRAY*. */ - VMS_ARRAY = 0x004, - - /* The field is itself a struct, containing one or more - * fields. Recurse into VMStateField.vmsd. Most useful in - * combination with VMS_ARRAY / VMS_VARRAY*, recursing into each - * array entry. */ - VMS_STRUCT = 0x008, - - /* The field is an array of variable size. The int32_t at opaque + - * VMStateField.num_offset contains the number of entries in the - * array. See the VMS_ARRAY description regarding array handling - * in general. May not be combined with VMS_ARRAY or any other - * VMS_VARRAY*. */ - VMS_VARRAY_INT32 = 0x010, - - /* Ignored */ - VMS_BUFFER = 0x020, - - /* The field is a (fixed-size or variable-size) array of pointers - * (e.g. struct a { uint8_t *b[]; }). Dereference each array entry - * before using it. Note: Does not imply any one of VMS_ARRAY / - * VMS_VARRAY*; these need to be set explicitly. */ - VMS_ARRAY_OF_POINTER = 0x040, - - /* The field is an array of variable size. The uint16_t at opaque - * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT16 = 0x080, - - /* The size of the individual entries (a single array entry if - * VMS_ARRAY or any of VMS_VARRAY* are set, or the field itself if - * neither is set) is variable (i.e. not known at compile-time), - * but the same for all entries. Use the int32_t at opaque + - * VMStateField.size_offset (subject to VMS_MULTIPLY) to determine - * the size of each (and every) entry. */ - VMS_VBUFFER = 0x100, - - /* Multiply the entry size given by the int32_t at opaque + - * VMStateField.size_offset (see VMS_VBUFFER description) with - * VMStateField.size to determine the number of bytes to be - * allocated. Only valid in combination with VMS_VBUFFER. */ - VMS_MULTIPLY = 0x200, - - /* The field is an array of variable size. The uint8_t at opaque + - * VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT8 = 0x400, - - /* The field is an array of variable size. The uint32_t at opaque - * + VMStateField.num_offset (subject to VMS_MULTIPLY_ELEMENTS) - * contains the number of entries in the array. See the VMS_ARRAY - * description regarding array handling in general. May not be - * combined with VMS_ARRAY or any other VMS_VARRAY*. */ - VMS_VARRAY_UINT32 = 0x800, - - /* Fail loading the serialised VM state if this field is missing - * from the input. */ - VMS_MUST_EXIST = 0x1000, - - /* When loading serialised VM state, allocate memory for the - * (entire) field. Only valid in combination with - * VMS_POINTER. Note: Not all combinations with other flags are - * currently supported, e.g. VMS_ALLOC|VMS_ARRAY_OF_POINTER won't - * cause the individual entries to be allocated. */ - VMS_ALLOC = 0x2000, - - /* Multiply the number of entries given by the integer at opaque + - * VMStateField.num_offset (see VMS_VARRAY*) with VMStateField.num - * to determine the number of entries in the array. Only valid in - * combination with one of VMS_VARRAY*. */ - VMS_MULTIPLY_ELEMENTS = 0x4000, - - /* A structure field that is like VMS_STRUCT, but uses - * VMStateField.struct_version_id to tell which version of the - * structure we are referencing to use. */ - VMS_VSTRUCT = 0x8000, - - /* Marker for end of list */ - VMS_END = 0x10000 -}; - -struct VMStateField { - const char *name; - size_t offset; - size_t size; - size_t start; - int num; - size_t num_offset; - size_t size_offset; - const VMStateInfo *info; - enum VMStateFlags flags; - const VMStateDescription *vmsd; - int version_id; - int struct_version_id; - bool (*field_exists)(void *opaque, int version_id); -}; - -struct VMStateDescription { - const char *name; - int version_id; - int (*pre_load)(void *opaque); - int (*post_load)(void *opaque, int version_id); - int (*pre_save)(void *opaque); - VMStateField *fields; -}; - - -extern const VMStateInfo slirp_vmstate_info_int16; -extern const VMStateInfo slirp_vmstate_info_int32; -extern const VMStateInfo slirp_vmstate_info_uint8; -extern const VMStateInfo slirp_vmstate_info_uint16; -extern const VMStateInfo slirp_vmstate_info_uint32; - -/** Put this in the stream when migrating a null pointer.*/ -#define VMS_NULLPTR_MARKER (0x30U) /* '0' */ -extern const VMStateInfo slirp_vmstate_info_nullptr; - -extern const VMStateInfo slirp_vmstate_info_buffer; -extern const VMStateInfo slirp_vmstate_info_tmp; - -#ifdef __GNUC__ -#define type_check_array(t1, t2, n) ((t1(*)[n])0 - (t2 *)0) -#define type_check_pointer(t1, t2) ((t1 **)0 - (t2 *)0) -#define typeof_field(type, field) typeof(((type *)0)->field) -#define type_check(t1, t2) ((t1 *)0 - (t2 *)0) -#else -#define type_check_array(t1, t2, n) 0 -#define type_check_pointer(t1, t2) 0 -#define typeof_field(type, field) (((type *)0)->field) -#define type_check(t1, t2) 0 -#endif - -#define vmstate_offset_value(_state, _field, _type) \ - (offsetof(_state, _field) + type_check(_type, typeof_field(_state, _field))) - -#define vmstate_offset_pointer(_state, _field, _type) \ - (offsetof(_state, _field) + \ - type_check_pointer(_type, typeof_field(_state, _field))) - -#define vmstate_offset_array(_state, _field, _type, _num) \ - (offsetof(_state, _field) + \ - type_check_array(_type, typeof_field(_state, _field), _num)) - -#define vmstate_offset_buffer(_state, _field) \ - vmstate_offset_array(_state, _field, uint8_t, \ - sizeof(typeof_field(_state, _field))) - -/* In the macros below, if there is a _version, that means the macro's - * field will be processed only if the version being received is >= - * the _version specified. In general, if you add a new field, you - * would increment the structure's version and put that version - * number into the new field so it would only be processed with the - * new version. - * - * In particular, for VMSTATE_STRUCT() and friends the _version does - * *NOT* pick the version of the sub-structure. It works just as - * specified above. The version of the top-level structure received - * is passed down to all sub-structures. This means that the - * sub-structures must have version that are compatible with all the - * structures that use them. - * - * If you want to specify the version of the sub-structure, use - * VMSTATE_VSTRUCT(), which allows the specific sub-structure version - * to be directly specified. - */ - -#define VMSTATE_SINGLE_TEST(_field, _state, _test, _version, _info, _type) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .field_exists = (_test), .size = sizeof(_type), .info = &(_info), \ - .flags = VMS_SINGLE, \ - .offset = vmstate_offset_value(_state, _field, _type), \ - } - -#define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) \ - { \ - .name = (stringify(_field)), .version_id = (_version), .num = (_num), \ - .info = &(_info), .size = sizeof(_type), .flags = VMS_ARRAY, \ - .offset = vmstate_offset_array(_state, _field, _type, _num), \ - } - -#define VMSTATE_STRUCT_TEST(_field, _state, _test, _version, _vmsd, _type) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .field_exists = (_test), .vmsd = &(_vmsd), .size = sizeof(_type), \ - .flags = VMS_STRUCT, \ - .offset = vmstate_offset_value(_state, _field, _type), \ - } - -#define VMSTATE_STRUCT_POINTER_V(_field, _state, _version, _vmsd, _type) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .vmsd = &(_vmsd), .size = sizeof(_type *), \ - .flags = VMS_STRUCT | VMS_POINTER, \ - .offset = vmstate_offset_pointer(_state, _field, _type), \ - } - -#define VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, _test, _version, \ - _vmsd, _type) \ - { \ - .name = (stringify(_field)), .num = (_num), .field_exists = (_test), \ - .version_id = (_version), .vmsd = &(_vmsd), .size = sizeof(_type), \ - .flags = VMS_STRUCT | VMS_ARRAY, \ - .offset = vmstate_offset_array(_state, _field, _type, _num), \ - } - -#define VMSTATE_STATIC_BUFFER(_field, _state, _version, _test, _start, _size) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .field_exists = (_test), .size = (_size - _start), \ - .info = &slirp_vmstate_info_buffer, .flags = VMS_BUFFER, \ - .offset = vmstate_offset_buffer(_state, _field) + _start, \ - } - -#define VMSTATE_VBUFFER_UINT32(_field, _state, _version, _test, _field_size) \ - { \ - .name = (stringify(_field)), .version_id = (_version), \ - .field_exists = (_test), \ - .size_offset = vmstate_offset_value(_state, _field_size, uint32_t), \ - .info = &slirp_vmstate_info_buffer, \ - .flags = VMS_VBUFFER | VMS_POINTER, \ - .offset = offsetof(_state, _field), \ - } - -#define QEMU_BUILD_BUG_ON_STRUCT(x) \ - struct { \ - int : (x) ? -1 : 1; \ - } - -#define QEMU_BUILD_BUG_ON_ZERO(x) \ - (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - sizeof(QEMU_BUILD_BUG_ON_STRUCT(x))) - -/* Allocate a temporary of type 'tmp_type', set tmp->parent to _state - * and execute the vmsd on the temporary. Note that we're working with - * the whole of _state here, not a field within it. - * We compile time check that: - * That _tmp_type contains a 'parent' member that's a pointer to the - * '_state' type - * That the pointer is right at the start of _tmp_type. - */ -#define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) \ - { \ - .name = "tmp", \ - .size = sizeof(_tmp_type) + \ - QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != 0) + \ - type_check_pointer(_state, typeof_field(_tmp_type, parent)), \ - .vmsd = &(_vmsd), .info = &slirp_vmstate_info_tmp, \ - } - -#define VMSTATE_SINGLE(_field, _state, _version, _info, _type) \ - VMSTATE_SINGLE_TEST(_field, _state, NULL, _version, _info, _type) - -#define VMSTATE_STRUCT(_field, _state, _version, _vmsd, _type) \ - VMSTATE_STRUCT_TEST(_field, _state, NULL, _version, _vmsd, _type) - -#define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) \ - VMSTATE_STRUCT_POINTER_V(_field, _state, 0, _vmsd, _type) - -#define VMSTATE_STRUCT_ARRAY(_field, _state, _num, _version, _vmsd, _type) \ - VMSTATE_STRUCT_ARRAY_TEST(_field, _state, _num, NULL, _version, _vmsd, \ - _type) - -#define VMSTATE_INT16_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_int16, int16_t) -#define VMSTATE_INT32_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_int32, int32_t) - -#define VMSTATE_UINT8_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_uint8, uint8_t) -#define VMSTATE_UINT16_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_uint16, uint16_t) -#define VMSTATE_UINT32_V(_f, _s, _v) \ - VMSTATE_SINGLE(_f, _s, _v, slirp_vmstate_info_uint32, uint32_t) - -#define VMSTATE_INT16(_f, _s) VMSTATE_INT16_V(_f, _s, 0) -#define VMSTATE_INT32(_f, _s) VMSTATE_INT32_V(_f, _s, 0) - -#define VMSTATE_UINT8(_f, _s) VMSTATE_UINT8_V(_f, _s, 0) -#define VMSTATE_UINT16(_f, _s) VMSTATE_UINT16_V(_f, _s, 0) -#define VMSTATE_UINT32(_f, _s) VMSTATE_UINT32_V(_f, _s, 0) - -#define VMSTATE_UINT16_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, slirp_vmstate_info_uint16, uint16_t) - -#define VMSTATE_UINT32_TEST(_f, _s, _t) \ - VMSTATE_SINGLE_TEST(_f, _s, _t, 0, slirp_vmstate_info_uint32, uint32_t) - -#define VMSTATE_INT16_ARRAY_V(_f, _s, _n, _v) \ - VMSTATE_ARRAY(_f, _s, _n, _v, slirp_vmstate_info_int16, int16_t) - -#define VMSTATE_INT16_ARRAY(_f, _s, _n) VMSTATE_INT16_ARRAY_V(_f, _s, _n, 0) - -#define VMSTATE_BUFFER_V(_f, _s, _v) \ - VMSTATE_STATIC_BUFFER(_f, _s, _v, NULL, 0, sizeof(typeof_field(_s, _f))) - -#define VMSTATE_BUFFER(_f, _s) VMSTATE_BUFFER_V(_f, _s, 0) - -#define VMSTATE_END_OF_LIST() \ - { \ - .flags = VMS_END, \ - } - -#endif /* VMSTATE_H_ */ diff --git a/src/nvr.c b/src/nvr.c index aefee99a8..f403984e4 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -224,9 +224,9 @@ nvr_path(char *str) int nvr_load(void) { - char *path; - FILE *fp; - uint8_t regs[NVR_MAXSIZE] = { 0 }; + const char *path; + FILE *fp; + uint8_t regs[NVR_MAXSIZE] = { 0 }; /* Make sure we have been initialized. */ if (saved_nvr == NULL) diff --git a/src/nvr_at.c b/src/nvr_at.c index 2e5a2a5ba..62598c4be 100644 --- a/src/nvr_at.c +++ b/src/nvr_at.c @@ -332,7 +332,7 @@ static uint8_t nvr_at_inited = 0; static void time_get(nvr_t *nvr, struct tm *tm) { - local_t *local = (local_t *) nvr->data; + const local_t *local = (local_t *) nvr->data; int8_t temp; if (nvr->regs[RTC_REGB] & REGB_DM) { @@ -370,7 +370,7 @@ time_get(nvr_t *nvr, struct tm *tm) static void time_set(nvr_t *nvr, struct tm *tm) { - local_t *local = (local_t *) nvr->data; + const local_t *local = (local_t *) nvr->data; int year = (tm->tm_year + 1900); if (nvr->regs[RTC_REGB] & REGB_DM) { @@ -429,7 +429,7 @@ check_alarm(nvr_t *nvr, int8_t addr) static int8_t check_alarm_via(nvr_t *nvr, int8_t addr, int8_t addr_2) { - local_t *local = (local_t *) nvr->data; + const local_t *local = (local_t *) nvr->data; if (local->cent == RTC_CENTURY_VIA) { return ((nvr->regs[addr_2] == nvr->regs[addr]) || ((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE)); @@ -521,8 +521,8 @@ timer_load_count(nvr_t *nvr) static void timer_intr(void *priv) { - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; + nvr_t *nvr = (nvr_t *) priv; + const local_t *local = (local_t *) nvr->data; if (local->state == 1) { timer_load_count(nvr); @@ -683,12 +683,12 @@ nvr_write(uint16_t addr, uint8_t val, void *priv) static uint8_t nvr_read(uint16_t addr, void *priv) { - nvr_t *nvr = (nvr_t *) priv; - local_t *local = (local_t *) nvr->data; - uint8_t ret; - uint8_t addr_id = (addr & 0x0e) >> 1; - uint16_t i; - uint16_t checksum = 0x0000; + nvr_t *nvr = (nvr_t *) priv; + const local_t *local = (local_t *) nvr->data; + uint8_t ret; + uint8_t addr_id = (addr & 0x0e) >> 1; + uint16_t i; + uint16_t checksum = 0x0000; cycles -= ISA_CYCLES(8); @@ -835,9 +835,11 @@ nvr_sec_read(uint16_t addr, void *priv) static void nvr_reset(nvr_t *nvr) { - local_t *local = (local_t *) nvr->data; + const local_t *local = (local_t *) nvr->data; - /* memset(nvr->regs, local->def, RTC_REGS); */ +#if 0 + memset(nvr->regs, local->def, RTC_REGS); +#endif memset(nvr->regs, local->def, nvr->size); nvr->regs[RTC_DOM] = 1; nvr->regs[RTC_MONTH] = 1; @@ -852,8 +854,8 @@ nvr_reset(nvr_t *nvr) static void nvr_start(nvr_t *nvr) { - int fdd; - local_t *local = (local_t *) nvr->data; + int fdd; + const local_t *local = (local_t *) nvr->data; struct tm tm; int default_found = 0; diff --git a/src/nvr_ps2.c b/src/nvr_ps2.c index a06ffb7bb..b13312545 100644 --- a/src/nvr_ps2.c +++ b/src/nvr_ps2.c @@ -61,8 +61,8 @@ typedef struct ps2_nvr_t { static uint8_t ps2_nvr_read(uint16_t port, void *priv) { - ps2_nvr_t *nvr = (ps2_nvr_t *) priv; - uint8_t ret = 0xff; + const ps2_nvr_t *nvr = (ps2_nvr_t *) priv; + uint8_t ret = 0xff; switch (port) { case 0x74: diff --git a/src/pci.c b/src/pci.c index 5b4282c5a..c86006a1a 100644 --- a/src/pci.c +++ b/src/pci.c @@ -979,6 +979,7 @@ static void pci_slots_clear(void) { uint8_t i; + last_pci_card = last_normal_pci_card = 0; last_pci_bus = 1; @@ -1194,8 +1195,8 @@ pci_register_bus_slot(int bus, int card, int type, int inta, int intb, int intc, uint8_t pci_find_slot(uint8_t add_type, uint8_t ignore_slot) { - pci_card_t *dev; - uint8_t ret = 0xff; + const pci_card_t *dev; + uint8_t ret = 0xff; for (uint8_t i = 0; i < last_pci_card; i++) { dev = &pci_cards[i]; diff --git a/src/pci_dummy.c b/src/pci_dummy.c index 3d437247d..8ed6f9f30 100644 --- a/src/pci_dummy.c +++ b/src/pci_dummy.c @@ -9,6 +9,7 @@ #include <86box/io.h> #include <86box/pci.h> #include <86box/pci_dummy.h> +#include <86box/plat_fallthrough.h> #include <86box/plat_unused.h> typedef struct pci_dummy_t { @@ -126,8 +127,8 @@ pci_dummy_io_set(pci_dummy_t *dev) static uint8_t pci_dummy_pci_read(int func, int addr, void *priv) { - pci_dummy_t *dev = (pci_dummy_t *) priv; - uint8_t ret = 0xff; + const pci_dummy_t *dev = (pci_dummy_t *) priv; + uint8_t ret = 0xff; if (func == 0x00) switch (addr) { @@ -210,7 +211,9 @@ pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv) case 0x10: /* PCI_BAR */ val &= 0xe0; /* 0xe0 acc to RTL DS */ - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x11: /* PCI_BAR */ /* Remove old I/O. */ diff --git a/src/pic.c b/src/pic.c index 8a57d15b9..6173291b4 100644 --- a/src/pic.c +++ b/src/pic.c @@ -143,7 +143,7 @@ pic_elcr_write(uint16_t port, uint8_t val, void *priv) uint8_t pic_elcr_read(UNUSED(uint16_t port), void *priv) { - pic_t *dev = (pic_t *) priv; + const pic_t *dev = (pic_t *) priv; pic_log("ELCR%i: READ %02X\n", port & 1, dev->elcr); diff --git a/src/pit.c b/src/pit.c index 3fe959c7f..648e0018b 100644 --- a/src/pit.c +++ b/src/pit.c @@ -396,8 +396,8 @@ ctr_latch_count(ctr_t *ctr) uint16_t pit_ctr_get_count(void *data, int counter_id) { - pit_t *pit = (pit_t *) data; - ctr_t *ctr = &pit->counters[counter_id]; + const pit_t *pit = (pit_t *) data; + const ctr_t *ctr = &pit->counters[counter_id]; return (uint16_t) ctr->l; } diff --git a/src/pit_fast.c b/src/pit_fast.c index 1bd75f2aa..80e359eee 100644 --- a/src/pit_fast.c +++ b/src/pit_fast.c @@ -91,8 +91,9 @@ pitf_ctr_set_load_func(void *data, int counter_id, void (*func)(uint8_t new_m, i static uint16_t pitf_ctr_get_count(void *data, int counter_id) { - pitf_t *pit = (pitf_t *) data; - ctrf_t *ctr = &pit->counters[counter_id]; + const pitf_t *pit = (pitf_t *) data; + const ctrf_t *ctr = &pit->counters[counter_id]; + return (uint16_t) ctr->l; } diff --git a/src/port_6x.c b/src/port_6x.c index 323d8e0c8..340d6df2b 100644 --- a/src/port_6x.c +++ b/src/port_6x.c @@ -48,7 +48,7 @@ static void port_6x_write(uint16_t port, uint8_t val, void *priv) { - port_6x_t *dev = (port_6x_t *) priv; + const port_6x_t *dev = (port_6x_t *) priv; port &= 3; @@ -89,8 +89,8 @@ port_61_read_simple(UNUSED(uint16_t port), UNUSED(void *priv)) static uint8_t port_61_read(UNUSED(uint16_t port), void *priv) { - port_6x_t *dev = (port_6x_t *) priv; - uint8_t ret = 0xff; + const port_6x_t *dev = (port_6x_t *) priv; + uint8_t ret = 0xff; if (dev->flags & PORT_6X_EXT_REF) { ret = ppi.pb & 0x0f; diff --git a/src/port_92.c b/src/port_92.c index 80afe9e58..1307ecba9 100644 --- a/src/port_92.c +++ b/src/port_92.c @@ -40,8 +40,8 @@ static uint8_t port_92_readb(uint16_t port, void *priv) { - uint8_t ret = 0x00; - port_92_t *dev = (port_92_t *) priv; + uint8_t ret = 0x00; + const port_92_t *dev = (port_92_t *) priv; if (port == 0x92) { /* Return bit 1 directly from mem_a20_alt, so the @@ -61,8 +61,8 @@ port_92_readb(uint16_t port, void *priv) static uint16_t port_92_readw(uint16_t port, void *priv) { - uint16_t ret = 0xffff; - port_92_t *dev = (port_92_t *) priv; + uint16_t ret = 0xffff; + const port_92_t *dev = (port_92_t *) priv; if (!(dev->flags & PORT_92_PCI)) ret = port_92_readb(port, priv); @@ -113,7 +113,7 @@ port_92_writeb(uint16_t port, uint8_t val, void *priv) static void port_92_writew(uint16_t port, uint16_t val, void *priv) { - port_92_t *dev = (port_92_t *) priv; + const port_92_t *dev = (port_92_t *) priv; if (!(dev->flags & PORT_92_PCI)) port_92_writeb(port, val & 0xff, priv); diff --git a/src/printer/png.c b/src/printer/png.c index 2134f3343..c7443252b 100644 --- a/src/printer/png.c +++ b/src/printer/png.c @@ -196,7 +196,6 @@ png_write_rgb(char *fn, uint8_t *pix, int16_t w, int16_t h, uint16_t pitch, PALE png_bytep *rows; png_color palette[256]; FILE *fp; - int i; /* Create the image file. */ fp = plat_fopen(fn, "wb"); @@ -248,7 +247,7 @@ error: PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); - for (i = 0; i < 256; i++) { + for (uint16_t i = 0; i < 256; i++) { palette[i].red = palcol[i].r; palette[i].green = palcol[i].g; palette[i].blue = palcol[i].b; @@ -259,7 +258,7 @@ error: /* Create a buffer for scanlines of pixels. */ rows = (png_bytep *) malloc(sizeof(png_bytep) * h); - for (i = 0; i < h; i++) { + for (int16_t i = 0; i < h; i++) { /* Create a buffer for this scanline. */ rows[i] = (pix + (i * pitch)); } diff --git a/src/printer/prt_cpmap.c b/src/printer/prt_cpmap.c index f2916eef8..153008f35 100644 --- a/src/printer/prt_cpmap.c +++ b/src/printer/prt_cpmap.c @@ -585,6 +585,6 @@ select_codepage(uint16_t code, uint16_t *curmap) i++; } - for (i = 0; i < 256; i++) - curmap[i] = map_to_use[i]; + for (uint16_t j = 0; j < 256; j++) + curmap[j] = map_to_use[j]; } diff --git a/src/printer/prt_escp.c b/src/printer/prt_escp.c index b4099bc63..612a07cac 100644 --- a/src/printer/prt_escp.c +++ b/src/printer/prt_escp.c @@ -494,11 +494,11 @@ init_codepage(escp_t *dev, uint16_t num) static void update_font(escp_t *dev) { - char path[1024]; - char *fn; - FT_Matrix matrix; - double hpoints = 10.5; - double vpoints = 10.5; + char path[1024]; + const char *fn; + FT_Matrix matrix; + double hpoints = 10.5; + double vpoints = 10.5; /* We need the FreeType library. */ if (ft_lib == NULL) @@ -1462,7 +1462,9 @@ process_char(escp_t *dev, uint8_t ch) dev->curr_x = dev->left_margin; if (!dev->autofeed) return 1; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x0a: /* Line feed */ if (dev->font_style & STYLE_DOUBLEWIDTHONELINE) { @@ -1649,9 +1651,9 @@ handle_char(escp_t *dev, uint8_t ch) static void blit_glyph(escp_t *dev, unsigned destx, unsigned desty, int8_t add) { - FT_Bitmap *bitmap = &dev->fontface->glyph->bitmap; - uint8_t src; - uint8_t *dst; + const FT_Bitmap *bitmap = &dev->fontface->glyph->bitmap; + uint8_t src; + uint8_t *dst; /* check if freetype is available */ if (ft_lib == NULL) @@ -1918,7 +1920,7 @@ write_ctrl(uint8_t val, void *priv) static uint8_t read_data(void *priv) { - escp_t *dev = (escp_t *) priv; + const escp_t *dev = (escp_t *) priv; return dev->data; } @@ -1926,7 +1928,7 @@ read_data(void *priv) static uint8_t read_ctrl(void *priv) { - escp_t *dev = (escp_t *) priv; + const escp_t *dev = (escp_t *) priv; return 0xe0 | (dev->autofeed ? 0x02 : 0x00) | (dev->ctrl & 0xfd); } @@ -1934,7 +1936,7 @@ read_ctrl(void *priv) static uint8_t read_status(void *priv) { - escp_t *dev = (escp_t *) priv; + const escp_t *dev = (escp_t *) priv; uint8_t ret = 0x1f; ret |= 0x80; @@ -1953,7 +1955,7 @@ escp_init(void *lpt) /* Initialize FreeType. */ if (ft_lib == NULL) { if (FT_Init_FreeType(&ft_lib)) { - ui_msgbox_header(MBX_ERROR, (wchar_t *) IDS_2111, (wchar_t *) IDS_2132); + pclog("ESC/P: FT_Init_FreeType failed\n"); ft_lib = NULL; return (NULL); } diff --git a/src/printer/prt_ps.c b/src/printer/prt_ps.c index caa166a10..c0e3958b2 100644 --- a/src/printer/prt_ps.c +++ b/src/printer/prt_ps.c @@ -58,8 +58,7 @@ #define POSTSCRIPT_BUFFER_LENGTH 65536 -typedef struct -{ +typedef struct ps_t { const char *name; void *lpt; @@ -321,8 +320,8 @@ ps_write_ctrl(uint8_t val, void *priv) static uint8_t ps_read_status(void *priv) { - ps_t *dev = (ps_t *) priv; - uint8_t ret = 0x9f; + const ps_t *dev = (ps_t *) priv; + uint8_t ret = 0x9f; if (!dev->ack) ret |= 0x40; diff --git a/src/printer/prt_text.c b/src/printer/prt_text.c index 6fe0f531a..e1183f0c0 100644 --- a/src/printer/prt_text.c +++ b/src/printer/prt_text.c @@ -283,7 +283,9 @@ process_char(prnt_t *dev, uint8_t ch) dev->curr_x = 0; if (!dev->autofeed) return 1; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x0a: /* Line feed */ dev->curr_x = 0; @@ -407,8 +409,8 @@ write_ctrl(uint8_t val, void *priv) static uint8_t read_status(void *priv) { - prnt_t *dev = (prnt_t *) priv; - uint8_t ret = 0x1f; + const prnt_t *dev = (prnt_t *) priv; + uint8_t ret = 0x1f; ret |= 0x80; diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 23e2c748e..7ef93b4c0 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -340,7 +340,6 @@ if (APPLE AND CMAKE_MACOSX_BUNDLE) # Install libraries that are loaded at runtime and not linked install_bundle_library("${GHOSTSCRIPT_LIB}" "libgs.dylib" RUNTIME_PLUGINS ${INSTALL_LIB_DIR}) - install_bundle_library("${FLUIDSYNTH_LIB}" "libfluidsynth.dylib" RUNTIME_PLUGINS ${INSTALL_LIB_DIR}) install_bundle_library("${VDE_LIB}" "libvdeplug.dylib" RUNTIME_PLUGINS ${INSTALL_LIB_DIR}) install_bundle_library("${MOLTENVK_LIB}" "libVulkan.dylib" RUNTIME_PLUGINS ${INSTALL_LIB_DIR}) diff --git a/src/qt/languages/cs-CZ.po b/src/qt/languages/cs-CZ.po index 422a00947..7c82b6f4d 100644 --- a/src/qt/languages/cs-CZ.po +++ b/src/qt/languages/cs-CZ.po @@ -724,9 +724,6 @@ msgstr "Stiskněte F8+F12 pro uvolnění myši" msgid "Press F8+F12 or middle button to release mouse" msgstr "Stiskněte F8+F12 nebo prostřední tlačítko pro uvolnění myši" -msgid "Unable to initialize FluidSynth" -msgstr "Nastala chyba při inicializaci knihovny FluidSynth." - msgid "Bus" msgstr "Sběrnice" @@ -811,9 +808,6 @@ msgstr "Rozšířené sektorové obrazy" msgid "Flux images" msgstr "Obrazy magnetického toku" -msgid "Unable to initialize FreeType" -msgstr "Nastala chyba při inicializaci knihovny FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Nastala chyba při inicializaci knihovny SDL, je potřeba SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Ujistěte se, že je nainstalován libpcap a používáte síťové při msgid "Invalid configuration" msgstr "Neplatná konfigurace" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " je potřeba pro emulaci ESC/P tiskáren." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " je potřeba pro automatický převod PostScript dokumentů do PDF.\n\nJakékoliv dokumenty vytisknuté přes obecnou PostScriptovou tiskárnu budou uloženy jako PostScript (.ps) soubory." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " je potřeba pro MIDI výstup přes knihovnu FluidSynth." - msgid "Entering fullscreen mode" msgstr "Vstup do režimu celé obrazovky" diff --git a/src/qt/languages/de-DE.po b/src/qt/languages/de-DE.po index 568599449..0caf925b5 100644 --- a/src/qt/languages/de-DE.po +++ b/src/qt/languages/de-DE.po @@ -724,9 +724,6 @@ msgstr "Bitte F8+F12 zur Mausfreigabe drücken" msgid "Press F8+F12 or middle button to release mouse" msgstr "Bitte F8+F12 oder die mittlere Maustaste zur Mausfreigabe drücken" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynth konnte nicht initialisiert werden" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Fortgeschrittene Sektorimages" msgid "Flux images" msgstr "Fluximages" -msgid "Unable to initialize FreeType" -msgstr "FreeType konnte nicht initialisiert werden" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDL konnte nicht initialisiert werden, die Datei SDL2.dll wird benötigt" @@ -877,15 +871,6 @@ msgstr "Bitte stellen Sie sicher, dass libpcap installiert ist und sie eine libp msgid "Invalid configuration" msgstr "Ungültige Konfiguration" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " wird für die ESC/P-Druckeremulation benötigt." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " wird zur automatischen Konversion von PostScript-Dateien in das PDF-Format benötigt.\n\nSämtliche an den generischen PostScript-Drucker gesendete Dateien werden als PostScript (.ps)-Dateien gesichert." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " wird für die FluidSynth-MIDI-Ausgabe benötigt." - msgid "Entering fullscreen mode" msgstr "Vollbildmodus wird aktiviert" diff --git a/src/qt/languages/en-GB.po b/src/qt/languages/en-GB.po index ddf6e7ef0..6a33f9bed 100644 --- a/src/qt/languages/en-GB.po +++ b/src/qt/languages/en-GB.po @@ -724,9 +724,6 @@ msgstr "Press F8+F12 to release mouse" msgid "Press F8+F12 or middle button to release mouse" msgstr "Press F8+F12 or middle button to release mouse" -msgid "Unable to initialize FluidSynth" -msgstr "Unable to initialize FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Advanced sector images" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "Unable to initialize FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Unable to initialize SDL, SDL2.dll is required" @@ -877,15 +871,6 @@ msgstr "Make sure libpcap is installed and that you are on a libpcap-compatible msgid "Invalid configuration" msgstr "Invalid configuration" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " is required for ESC/P printer emulation." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " is required for FluidSynth MIDI output." - msgid "Entering fullscreen mode" msgstr "Entering fullscreen mode" diff --git a/src/qt/languages/en-US.po b/src/qt/languages/en-US.po index 09adcdb76..5e3afdc27 100644 --- a/src/qt/languages/en-US.po +++ b/src/qt/languages/en-US.po @@ -724,9 +724,6 @@ msgstr "Press F8+F12 to release mouse" msgid "Press F8+F12 or middle button to release mouse" msgstr "Press F8+F12 or middle button to release mouse" -msgid "Unable to initialize FluidSynth" -msgstr "Unable to initialize FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Advanced sector images" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "Unable to initialize FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Unable to initialize SDL, SDL2.dll is required" @@ -877,15 +871,6 @@ msgstr "Make sure libpcap is installed and that you are on a libpcap-compatible msgid "Invalid configuration" msgstr "Invalid configuration" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " is required for ESC/P printer emulation." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " is required for FluidSynth MIDI output." - msgid "Entering fullscreen mode" msgstr "Entering fullscreen mode" diff --git a/src/qt/languages/es-ES.po b/src/qt/languages/es-ES.po index 8fbc442b9..f864dce0d 100644 --- a/src/qt/languages/es-ES.po +++ b/src/qt/languages/es-ES.po @@ -724,9 +724,6 @@ msgstr "Pulsa F8+F12 para liberar el ratón" msgid "Press F8+F12 or middle button to release mouse" msgstr "Pulsa F8+F12 o el botón central para liberar el ratón" -msgid "Unable to initialize FluidSynth" -msgstr "Incapaz de inicializar FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Advanced sector images" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "Incapaz de inicializar FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Incapaz de inicializar SDL, se requiere SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Asegúrate de que libpcap está instalado y de que estás en una conexi msgid "Invalid configuration" msgstr "Configuración inválida" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " es necesaria para emulación de impresión ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " es necesaria para la conversión automática de archivos PostScript a PDF.\n\nCualquier documento enviado a la impresora genérica postScript se guardará como archivo PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " es necesario para salida MIDI FluidSynth." - msgid "Entering fullscreen mode" msgstr "Entrando en modo pantalla completa" diff --git a/src/qt/languages/fi-FI.po b/src/qt/languages/fi-FI.po index d1c524558..97ecf79d5 100644 --- a/src/qt/languages/fi-FI.po +++ b/src/qt/languages/fi-FI.po @@ -724,9 +724,6 @@ msgstr "Paina F8+F12 vapauttaaksesi hiiren" msgid "Press F8+F12 or middle button to release mouse" msgstr "Paina F8+F12 tai keskipainiketta vapauttaaksesi hiiren" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynthin alustus epäonnistui" - msgid "Bus" msgstr "Väylä" @@ -811,9 +808,6 @@ msgstr "Kehittyneet sektorilevykuvat" msgid "Flux images" msgstr "Flux-levykuvat" -msgid "Unable to initialize FreeType" -msgstr "FreeType:n alustus epäonnistui" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDL:n alustus epäonnistui. Tarvitaan SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Varmista, että libpcap on asennettu ja että verkkoyhteytesi on libpcap msgid "Invalid configuration" msgstr "Virheelliset määritykset" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " vaaditaan ESC/P-tulostimen emuloimiseksi." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " vaaditaan PostScript-tiedostojen automaattiseen muuntamiseen PDF-tiedostoiksi.\n\nKaikki geneeriselle PostScript-tulostimelle lähetetyt asiakirjat tallennetaan PostScript (.ps) -tiedostoina." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " vaaditaan FluidSynth MIDI-ulostuloa varten." - msgid "Entering fullscreen mode" msgstr "Siirrytään koko näytön tilaan" @@ -1225,4 +1201,3 @@ msgstr "Failed to initialize network driver" msgid "The network configuration will be switched to the null driver" msgstr "The network configuration will be switched to the null driver" - diff --git a/src/qt/languages/fr-FR.po b/src/qt/languages/fr-FR.po index f83c8f5fd..1fbff4001 100644 --- a/src/qt/languages/fr-FR.po +++ b/src/qt/languages/fr-FR.po @@ -724,9 +724,6 @@ msgstr "Appuyer sur F8+F12 pour libérer la souris" msgid "Press F8+F12 or middle button to release mouse" msgstr "Appuyer sur F8+F12 ou le bouton central pour libérer la souris" -msgid "Unable to initialize FluidSynth" -msgstr "Impossible d'initialiser FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Images du secteur avancés" msgid "Flux images" msgstr "Images du flux" -msgid "Unable to initialize FreeType" -msgstr "Impossible d'initialiser FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Impossible d'initialiser SDL, SDL2.dll est nécessaire" @@ -877,15 +871,6 @@ msgstr "Assurez-vous que libpcap est installé et que vou utilisez une connexion msgid "Invalid configuration" msgstr "Configuration non valide" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " est nécessaire pour l'émulation de l'imprimante ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " est nécessair pour la conversion automatique des fichiers PostScript dans PDF.\n\nTous les documents envoyés à l'imprimante générique PostScript seront sauvés comme des fichiers PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " est nécessaire pour la sortie MIDI FluidSynth." - msgid "Entering fullscreen mode" msgstr "Entrer en mode plein écran" diff --git a/src/qt/languages/hr-HR.po b/src/qt/languages/hr-HR.po index 76973f796..43f01d5de 100644 --- a/src/qt/languages/hr-HR.po +++ b/src/qt/languages/hr-HR.po @@ -724,9 +724,6 @@ msgstr "Pritisnite F8+F12 za otpustanje miša" msgid "Press F8+F12 or middle button to release mouse" msgstr "Pritisnite F8+F12 ili srednji gumb miša za otpuštanje miša" -msgid "Unable to initialize FluidSynth" -msgstr "Nije moguće inicijalizirati FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Napredne sektorske slike" msgid "Flux images" msgstr "Flux slike" -msgid "Unable to initialize FreeType" -msgstr "Nije moguće inicijalizirati FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Nije moguće inicijalizirati SDL, SDL2.dll je potrebno" @@ -877,15 +871,6 @@ msgstr "Provjerite je li libpcap instaliran i jeste li na mreži, kompadibilnoj msgid "Invalid configuration" msgstr "Nevažeća konfiguracija" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " je potrebno za emuliranje ESC/P pisača." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " je potrebno za automatsku konverziju PostScript datoteke u PDF datoteke.\n\nSvi dokumenti poslani na generički PostScript pisač bit će spremljeni kao PostScript (.ps) datoteke." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " je potrebno za FluidSynth MIDI izlaz." - msgid "Entering fullscreen mode" msgstr "Ulazim u cijelozaslonski način" diff --git a/src/qt/languages/hu-HU.po b/src/qt/languages/hu-HU.po index 2f812ba2e..bf4796ebb 100644 --- a/src/qt/languages/hu-HU.po +++ b/src/qt/languages/hu-HU.po @@ -724,9 +724,6 @@ msgstr "Nyomja meg az F8+F12-t az egér elengédéséhez" msgid "Press F8+F12 or middle button to release mouse" msgstr "Nyomja meg az F8+F12-t vagy a középső gombot az egér elengédéséhez" -msgid "Unable to initialize FluidSynth" -msgstr "Nem sikerült a FluidSynth inicializálása" - msgid "Bus" msgstr "Busz" @@ -811,9 +808,6 @@ msgstr "Továbbfejlesztett szektor képek" msgid "Flux images" msgstr "Flux képekfájlok" -msgid "Unable to initialize FreeType" -msgstr "A FreeType inicializálása nem lehetséges" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Az SDL inicializálása nem lehetséges, az SDL2.dll fájl szükséges" @@ -877,15 +871,6 @@ msgstr "Győződjön meg hogy a(z) libpcap telepítve van és jelenleg a libpcap msgid "Invalid configuration" msgstr "Érvénytelen konfiguráció" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " szükséges az ESC/P nyomtató emulációhoz." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " szükséges a PostScript fájlok PDF formátumba való automatikus konvertálásához.\n\nAz általános PostScript nyomtatóra küldött dokumentumok PostScript (.ps) fájlként kerülnek mentésre." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " szükséges a FluidSynth MIDI kimenethez." - msgid "Entering fullscreen mode" msgstr "Teljes képernyős módra váltás" diff --git a/src/qt/languages/it-IT.po b/src/qt/languages/it-IT.po index a9b3b7ce3..6c6d5f65f 100644 --- a/src/qt/languages/it-IT.po +++ b/src/qt/languages/it-IT.po @@ -724,9 +724,6 @@ msgstr "Premi F8+F12 per rilasciare il mouse" msgid "Press F8+F12 or middle button to release mouse" msgstr "Premi F8+F12 o pulsante centrale per rilasciare il mouse" -msgid "Unable to initialize FluidSynth" -msgstr "Impossibile inizializzare FluidSynth" - msgid "Bus" msgstr "Bus" @@ -811,9 +808,6 @@ msgstr "Immagini da settori avanzati" msgid "Flux images" msgstr "Immagini flusso" -msgid "Unable to initialize FreeType" -msgstr "Impossibile inizializzare FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Impossibile inizializzare SDL, SDL2.dll è necessario" @@ -877,15 +871,6 @@ msgstr "Controlla se libpcap è installato e che tu sia connesso ad una connessi msgid "Invalid configuration" msgstr "Configurazione invalida" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " è richesto per l'emuazione di stampanti ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " è richiesto per la conversione automatica di file PostScript a file PDF.\n\nQualsiasi documento mandato alla stampante generica PostScript sarà salvato come file PostScript. (.ps)" -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " è richiesto per l'output FluidSynth MIDI." - msgid "Entering fullscreen mode" msgstr "Entrando nella modalità schermo intero" diff --git a/src/qt/languages/ja-JP.po b/src/qt/languages/ja-JP.po index eb4e5241e..b35fa429e 100644 --- a/src/qt/languages/ja-JP.po +++ b/src/qt/languages/ja-JP.po @@ -724,9 +724,6 @@ msgstr "F8+F12キーでマウスを解放します" msgid "Press F8+F12 or middle button to release mouse" msgstr "F8+F12キーまたは中ボタンでマウスを解放します" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynthが初期化できません" - msgid "Bus" msgstr "バス" @@ -811,9 +808,6 @@ msgstr "アドバンスドセクターイメージ" msgid "Flux images" msgstr "フラックスイメージ" -msgid "Unable to initialize FreeType" -msgstr "FreeTypeが初期化できません" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDLが初期化できません。SDL2.dllが必要です" @@ -877,15 +871,6 @@ msgstr "がインストールされてるか、libpcapに対応したネット msgid "Invalid configuration" msgstr "不正な設定です" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "ESC/Pプリンタのエミュレーションにはlibfreetypeが必要です。" - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr "PostScriptファイルをPDFに自動変換するにはlibgsが必要です。\n\n汎用PostScriptプリンターに送信されたドキュメントは、PostScript(.ps)ファイルとして保存されます。" -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "FluidSynthのMIDI出力にはlibfluidsynthが必要です。" - msgid "Entering fullscreen mode" msgstr "フルスクリーンに切り替えています" diff --git a/src/qt/languages/ko-KR.po b/src/qt/languages/ko-KR.po index 112506fe5..bf9325675 100644 --- a/src/qt/languages/ko-KR.po +++ b/src/qt/languages/ko-KR.po @@ -724,9 +724,6 @@ msgstr "F12+F8키를 누르면 마우스를 해제합니다" msgid "Press F8+F12 or middle button to release mouse" msgstr "F12+F8키 또는 가운데 버튼을 클릭하면 마우스를 해제합니다" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynth를 초기화할 수 없습니다" - msgid "Bus" msgstr "버스" @@ -811,9 +808,6 @@ msgstr "어드밴스드 섹터 이미지" msgid "Flux images" msgstr "플럭스 이미지" -msgid "Unable to initialize FreeType" -msgstr "FreeType을 초기화할 수 없습니다" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDL을 초기화할 수 없습니다. SDL2.dll이 필요합니다" @@ -877,15 +871,6 @@ msgstr "이 설치되었는지 libpcap에 대응하는 네트워크에 접속되 msgid "Invalid configuration" msgstr "올바르지 않은 설정입니다" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "ESC/P 프린터 에뮬레이션에 libfreetype이(가) 필요합니다." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr "은(는) PostScript 파일을 PDF로 자동변환하는 데에 필요합니다.\n\n표준 PostScript 프린터로 보내신 임의의 문서는 PostScript (.ps) 파일로 저장됩니다." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "FluidSynth의 MIDI 출력에 libfluidsynth이(가) 필요합니다." - msgid "Entering fullscreen mode" msgstr "전체 화면으로 전환" diff --git a/src/qt/languages/pl-PL.po b/src/qt/languages/pl-PL.po index 7809cd263..6b017dfb5 100644 --- a/src/qt/languages/pl-PL.po +++ b/src/qt/languages/pl-PL.po @@ -724,9 +724,6 @@ msgstr "Naciśnij klawisze F8+F12 w celu uwolnienia myszy" msgid "Press F8+F12 or middle button to release mouse" msgstr "Naciśnij klawisze F8+F12 lub środkowy przycisk w celu uwolnienia myszy" -msgid "Unable to initialize FluidSynth" -msgstr "Nie można zainicjować FluidSynth" - msgid "Bus" msgstr "Magistrala" @@ -811,9 +808,6 @@ msgstr "Zaawansowane obrazy sektorów" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "Nie można zainicjować FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Nie można zainicjować SDL, wymagany SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Sprawdź, czy libpcap jest zainstalowany i czy posiadasz połączenie si msgid "Invalid configuration" msgstr "Nieprawidłowa konfiguracja" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " jest wymagany do emulacji drukarki ESC-P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " jest wymagany do automatycznej konwersji plików PostScript do PDF.\n\nDokumenty wysłane do ogólnej drukarki PostScript zostaną zapisane jako pliki PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " jest wymagany dla wyjścia FluidSynth MIDI." - msgid "Entering fullscreen mode" msgstr "Przechodzenie do trybu pełnoekranowego" diff --git a/src/qt/languages/pt-BR.po b/src/qt/languages/pt-BR.po index b6c2e2b70..1771c1f4a 100644 --- a/src/qt/languages/pt-BR.po +++ b/src/qt/languages/pt-BR.po @@ -724,9 +724,6 @@ msgstr "Aperte F8+F12 para liberar o mouse" msgid "Press F8+F12 or middle button to release mouse" msgstr "Aperte F8+F12 ou botão do meio para liberar o mouse" -msgid "Unable to initialize FluidSynth" -msgstr "Não foi possível inicializar o FluidSynth" - msgid "Bus" msgstr "Barramento" @@ -811,9 +808,6 @@ msgstr "Imagens de setor avançado" msgid "Flux images" msgstr "Imagens de fluxo" -msgid "Unable to initialize FreeType" -msgstr "Não foi possível inicializar o FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Não é possível inicializar o SDL, é necessário o SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Certifique-se de que libpcap esteja instalado e que você tenha uma cone msgid "Invalid configuration" msgstr "Configuração inválida" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " é necessário para emulação de impressora ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " é necessário para a conversão automática de arquivos PostScript para PDF.\n\nQualquer documento enviado para a impressora genérica PostScript será salvo como arquivos PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " é necessário para a saída MIDI FluidSynth." - msgid "Entering fullscreen mode" msgstr "Entrando no modo de tela cheia" @@ -1220,8 +1196,8 @@ msgid "(System Default)" msgstr "(Padrão do sistema)" msgid "Failed to initialize network driver" -msgstr "Failed to initialize network driver" +msgstr "Falha ao inicializar o driver de rede" msgid "The network configuration will be switched to the null driver" -msgstr "The network configuration will be switched to the null driver" +msgstr "A configuração de rede será alterada para o driver nulo" diff --git a/src/qt/languages/pt-PT.po b/src/qt/languages/pt-PT.po index 7e4fc9053..a45aa78c5 100644 --- a/src/qt/languages/pt-PT.po +++ b/src/qt/languages/pt-PT.po @@ -724,9 +724,6 @@ msgstr "Pressione F8+F12 para soltar o rato" msgid "Press F8+F12 or middle button to release mouse" msgstr "Pressione F8+F12 ou tecla média para soltar o rato" -msgid "Unable to initialize FluidSynth" -msgstr "Não foi possível inicializar o FluidSynth" - msgid "Bus" msgstr "Barramento" @@ -811,9 +808,6 @@ msgstr "Imagens avançadas de sector" msgid "Flux images" msgstr "Imagens de fluxo" -msgid "Unable to initialize FreeType" -msgstr "Não foi possível inicializar o FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Não foi possível inicializar o SDL. O ficheiro SDL2.dll é necessário!" @@ -877,15 +871,6 @@ msgstr "Certifique-se de que a biblioteca libpcap está instalada e de que está msgid "Invalid configuration" msgstr "Configuração inválida" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " é requerida para a emulação de impressora ESC/P." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " é requerido para a conversão automática de ficheiros PostScript para ficheiros PDF.\n\nQualquer documento enviado para a impressora PostScript genérica será gravado como um ficheiro PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " é necessário para a saída MIDI FluidSynth MIDI." - msgid "Entering fullscreen mode" msgstr "A entrar no modo de ecrã cheio" diff --git a/src/qt/languages/ru-RU.po b/src/qt/languages/ru-RU.po index 78794cd35..cb14c193d 100644 --- a/src/qt/languages/ru-RU.po +++ b/src/qt/languages/ru-RU.po @@ -724,9 +724,6 @@ msgstr "Нажмите F8+F12 чтобы освободить курсор" msgid "Press F8+F12 or middle button to release mouse" msgstr "Нажмите F8+F12 или среднюю кнопку мыши чтобы освободить курсор" -msgid "Unable to initialize FluidSynth" -msgstr "Невозможно инициализировать FluidSynth" - msgid "Bus" msgstr "Шина" @@ -811,9 +808,6 @@ msgstr "Расширенные образы секторов" msgid "Flux images" msgstr "Образы Flux" -msgid "Unable to initialize FreeType" -msgstr "Невозможно инициализировать FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Невозможно инициализировать SDL, требуется SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Убедитесь, что libpcap установлен и ваше се msgid "Invalid configuration" msgstr "Недопустимая конфигурация" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "Для эмуляции принтера ESC/P требуется libfreetype." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " требуется для автоматического преобразования файлов PostScript в PDF.\n\nВсе документы, отправленные на общий принтер PostScript, будут сохранены в виде файлов PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "Для FluidSynth MIDI-вывода требуется libfluidsynth." - msgid "Entering fullscreen mode" msgstr "Вход в полноэкранный режим" diff --git a/src/qt/languages/sl-SI.po b/src/qt/languages/sl-SI.po index 5f32a6b03..83b0d6774 100644 --- a/src/qt/languages/sl-SI.po +++ b/src/qt/languages/sl-SI.po @@ -724,9 +724,6 @@ msgstr "Pritisnite F8+F12 za izpust miške" msgid "Press F8+F12 or middle button to release mouse" msgstr "Pritisnite F8+F12 ali srednji gumb za izpust miške" -msgid "Unable to initialize FluidSynth" -msgstr "Ne morem inicializirati FluidSynth" - msgid "Bus" msgstr "Vodilo" @@ -811,9 +808,6 @@ msgstr "Napredne sektorske slike" msgid "Flux images" msgstr "Tokovne slike" -msgid "Unable to initialize FreeType" -msgstr "Ne morem inicializirati FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Ne morem inicializirati SDL, potrebna je knjižica SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Prepičajte se, da je nameščen libpcap in da ste na omrežni povezavi, msgid "Invalid configuration" msgstr "Neveljavna konfiguracija" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " je potreben za emuliranje ESC/P tiskalnika." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " je potreben za samodejno pretvorbo PostScript datotek v PDF.\n\nVsi dokumenti, poslani generičnemu PostScript tiskalniku bodo shranjeni kot PostScript (.ps) datoteke." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " je potreben za FluidSynth MIDI izhod." - msgid "Entering fullscreen mode" msgstr "Preklapljam v celozaslonski način" diff --git a/src/qt/languages/tr-TR.po b/src/qt/languages/tr-TR.po index 72ad49bf8..551764016 100644 --- a/src/qt/languages/tr-TR.po +++ b/src/qt/languages/tr-TR.po @@ -724,9 +724,6 @@ msgstr "Farenin bırakılması için F8+F12 tuşlarına basın" msgid "Press F8+F12 or middle button to release mouse" msgstr "Farenin bırakılması için F8+F12 veya farenin orta tuşuna basın" -msgid "Unable to initialize FluidSynth" -msgstr "FluidSynth başlatılamadı" - msgid "Bus" msgstr "Veri yolu" @@ -811,9 +808,6 @@ msgstr "Gelişmiş sektör imajları" msgid "Flux images" msgstr "Flux images" -msgid "Unable to initialize FreeType" -msgstr "FreeType başlatılamadı" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "SDL başlatılamadı, SDL2.dll gerekmektedir" @@ -877,15 +871,6 @@ msgstr "libpcap kurulu olduğundan ve libpcap-uyumlu bir internet ağında bulun msgid "Invalid configuration" msgstr "Geçersiz konfigürasyon" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr " ESC/P yazıcı emülasyonu için gereklidir." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " PostScript dosyalarının otomatik olarak PDF dosyalarına çevirilmesi için gereklidir.\n\nGenel PostScript yazıcısına gönderilen tüm dökümanlar PostScript (.ps) dosyaları olarak kaydedilecektir." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr " FluidSynth MIDI çıkışı için gereklidir." - msgid "Entering fullscreen mode" msgstr "Tam ekran moduna geçiliyor" diff --git a/src/qt/languages/uk-UA.po b/src/qt/languages/uk-UA.po index 4d7708ef6..394a2905d 100644 --- a/src/qt/languages/uk-UA.po +++ b/src/qt/languages/uk-UA.po @@ -724,9 +724,6 @@ msgstr "Натисніть F8+F12, щоб звільнити курсор" msgid "Press F8+F12 or middle button to release mouse" msgstr "Натисніть F8+F12 або середню кнопку миші, щоб звільнити курсор" -msgid "Unable to initialize FluidSynth" -msgstr "Неможливо ініціалізувати FluidSynth" - msgid "Bus" msgstr "Шина" @@ -811,9 +808,6 @@ msgstr "Розширені образи секторів" msgid "Flux images" msgstr "Образи Flux" -msgid "Unable to initialize FreeType" -msgstr "Неможливо ініціалізувати FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "Неможливо ініціалізувати SDL, потрібно SDL2.dll" @@ -877,15 +871,6 @@ msgstr "Переконайтесь, що libpcap встановлений і в msgid "Invalid configuration" msgstr "Неприпустима конфігурація" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "Для емуляції принтера ESC/P потрібно libfreetype." - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " потрібно для автоматичного перетворення файлів PostScript в PDF.\n\nВсі документи, відправлені на загальний принтер PostScript, будуть збережені у вигляді файлів PostScript (.ps)." -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "Для FluidSynth MIDI-висновку потрібно libfluidsynth." - msgid "Entering fullscreen mode" msgstr "Вхід у повноекранний режим" diff --git a/src/qt/languages/zh-CN.po b/src/qt/languages/zh-CN.po index da37b4fb2..5858b5ec3 100644 --- a/src/qt/languages/zh-CN.po +++ b/src/qt/languages/zh-CN.po @@ -724,9 +724,6 @@ msgstr "按下 F8+F12 释放鼠标" msgid "Press F8+F12 or middle button to release mouse" msgstr "按下 F8+F12 或鼠标中键释放鼠标" -msgid "Unable to initialize FluidSynth" -msgstr "无法初始化 FluidSynth" - msgid "Bus" msgstr "总线" @@ -811,9 +808,6 @@ msgstr "高级扇区镜像" msgid "Flux images" msgstr "Flux 镜像" -msgid "Unable to initialize FreeType" -msgstr "无法初始化 FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "无法初始化 SDL,需要 SDL2.dll" @@ -877,15 +871,6 @@ msgstr "请确认 libpcap 已安装且使用兼容 libpcap 的网络连接。" msgid "Invalid configuration" msgstr "无效配置" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "ESC/P 打印机模拟需要" - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " 是将 PostScript 文件转换为 PDF 所需要的库。\n\n使用通用 PostScript 打印机打印的文档将被保存为 PostScript (.ps) 文件。" -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "FluidSynth MIDI 输出需要" - msgid "Entering fullscreen mode" msgstr "正在进入全屏模式" diff --git a/src/qt/languages/zh-TW.po b/src/qt/languages/zh-TW.po index f1bbfffd9..94b0a7553 100644 --- a/src/qt/languages/zh-TW.po +++ b/src/qt/languages/zh-TW.po @@ -182,7 +182,7 @@ msgid "Take s&creenshot\tCtrl+F11" msgstr "擷圖(&C)\tCtrl+F11" msgid "&Preferences..." -msgstr "首選項(&P)..." +msgstr "偏好設定(&P)..." msgid "Enable &Discord integration" msgstr "啟用 Discord 整合(&D)" @@ -278,7 +278,7 @@ msgid "&Remove shader" msgstr "移除著色器(&R)" msgid "Preferences" -msgstr "首選項" +msgstr "偏好設定" msgid "Sound Gain" msgstr "音量增益" @@ -407,16 +407,16 @@ msgid "Joystick 4..." msgstr "搖桿 4..." msgid "Sound card 1:" -msgstr "音訊卡 1:" +msgstr "音效卡 1:" msgid "Sound card 2:" -msgstr "音訊卡 2:" +msgstr "音效卡 2:" msgid "Sound card 3:" -msgstr "音訊卡 3:" +msgstr "音效卡 3:" msgid "Sound card 4:" -msgstr "音訊卡 4:" +msgstr "音效卡 4:" msgid "MIDI Out Device:" msgstr "MIDI 輸出裝置:" @@ -557,7 +557,7 @@ msgid "Heads:" msgstr "磁頭(H):" msgid "Cylinders:" -msgstr "柱面(C):" +msgstr "磁柱(C):" msgid "Size (MB):" msgstr "大小 (MB):" @@ -724,9 +724,6 @@ msgstr "按下 F8+F12 釋放滑鼠" msgid "Press F8+F12 or middle button to release mouse" msgstr "按下 F8+F12 或滑鼠中鍵釋放滑鼠" -msgid "Unable to initialize FluidSynth" -msgstr "無法初始化 FluidSynth" - msgid "Bus" msgstr "匯流排" @@ -811,9 +808,6 @@ msgstr "進階磁區映像" msgid "Flux images" msgstr "Flux 映像" -msgid "Unable to initialize FreeType" -msgstr "無法初始化 FreeType" - msgid "Unable to initialize SDL, SDL2.dll is required" msgstr "無法初始化 SDL,需要 SDL2.dll" @@ -877,15 +871,6 @@ msgstr "請確認 libpcap 已安裝且使用相容 libpcap 的網路連線。" msgid "Invalid configuration" msgstr "無效設定" -msgid "freetype.dll" -msgstr "freetype.dll" - -msgid "libfreetype" -msgstr "libfreetype" - -msgid " is required for ESC/P printer emulation." -msgstr "ESC/P 印表機模擬需要" - msgid "gsdll32.dll" msgstr "gsdll32.dll" @@ -895,15 +880,6 @@ msgstr "libgs" msgid " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." msgstr " 是將 PostScript 檔案轉換為 PDF 所需要的庫。\n\n使用通用 PostScript 印表機列印的文件將被儲存為 PostScript (.ps) 檔案。" -msgid "libfluidsynth.dll" -msgstr "libfluidsynth.dll" - -msgid "libfluidsynth" -msgstr "libfluidsynth" - -msgid " is required for FluidSynth MIDI output." -msgstr "FluidSynth MIDI 輸出需要" - msgid "Entering fullscreen mode" msgstr "正在進入全螢幕模式" diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 04317800d..ef39765dd 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -70,6 +70,7 @@ extern int qt_nvr_save(void); #include #include #include +#include #include #include #include @@ -628,6 +629,8 @@ MainWindow::MainWindow(QWidget *parent) #endif setContextMenuPolicy(Qt::PreventContextMenu); + /* Remove default Shift+F10 handler, which unfocuses keyboard input even with no context menu. */ + connect(new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F10), this), &QShortcut::activated, this, [this](){}); connect(this, &MainWindow::initRendererMonitor, this, &MainWindow::initRendererMonitorSlot); connect(this, &MainWindow::initRendererMonitorForNonQtThread, this, &MainWindow::initRendererMonitorSlot, Qt::BlockingQueuedConnection); @@ -1249,11 +1252,7 @@ MainWindow::keyPressEvent(QKeyEvent *event) #endif } - if (!fs_off_signal && (video_fullscreen > 0) && keyboard_isfsexit()) - fs_off_signal = true; - - if (!fs_on_signal && (video_fullscreen == 0) && keyboard_isfsenter()) - fs_on_signal = true; + checkFullscreenHotkey(); if (keyboard_ismsexit()) plat_mouse_capture(0); @@ -1289,24 +1288,35 @@ MainWindow::keyReleaseEvent(QKeyEvent *event) } } - if (fs_off_signal && (video_fullscreen > 0) && keyboard_isfsexit()) { - ui->actionFullscreen->trigger(); - fs_off_signal = false; - } - - if (fs_on_signal && (video_fullscreen == 0) && keyboard_isfsenter()) { - ui->actionFullscreen->trigger(); - fs_on_signal = false; - } - - if (!send_keyboard_input || event->isAutoRepeat()) - return; - + if (send_keyboard_input && !event->isAutoRepeat()) { #ifdef Q_OS_MACOS - processMacKeyboardInput(false, event); + processMacKeyboardInput(false, event); #else - processKeyboardInput(false, event->nativeScanCode()); + processKeyboardInput(false, event->nativeScanCode()); #endif + } + + checkFullscreenHotkey(); +} + +void +MainWindow::checkFullscreenHotkey() +{ + if (!fs_off_signal && video_fullscreen && keyboard_isfsexit()) { + /* Signal "exit fullscreen mode". */ + fs_off_signal = 1; + } else if (fs_off_signal && video_fullscreen && keyboard_isfsexit_up()) { + ui->actionFullscreen->trigger(); + fs_off_signal = 0; + } + + if (!fs_on_signal && !video_fullscreen && keyboard_isfsenter()) { + /* Signal "enter fullscreen mode". */ + fs_on_signal = 1; + } else if (fs_on_signal && !video_fullscreen && keyboard_isfsenter_up()) { + ui->actionFullscreen->trigger(); + fs_on_signal = 0; + } } QSize @@ -1699,18 +1709,20 @@ void MainWindow::on_actionRemember_size_and_position_triggered() { window_remember ^= 1; - window_w = ui->stackedWidget->width(); - window_h = ui->stackedWidget->height(); - if (!QApplication::platformName().contains("wayland")) { - window_x = geometry().x(); - window_y = geometry().y(); - } - for (int i = 1; i < MONITORS_NUM; i++) { - if (window_remember && renderers[i]) { - monitor_settings[i].mon_window_w = renderers[i]->geometry().width(); - monitor_settings[i].mon_window_h = renderers[i]->geometry().height(); - monitor_settings[i].mon_window_x = renderers[i]->geometry().x(); - monitor_settings[i].mon_window_y = renderers[i]->geometry().y(); + if (!video_fullscreen) { + window_w = ui->stackedWidget->width(); + window_h = ui->stackedWidget->height(); + if (!QApplication::platformName().contains("wayland")) { + window_x = geometry().x(); + window_y = geometry().y(); + } + for (int i = 1; i < MONITORS_NUM; i++) { + if (window_remember && renderers[i]) { + monitor_settings[i].mon_window_w = renderers[i]->geometry().width(); + monitor_settings[i].mon_window_h = renderers[i]->geometry().height(); + monitor_settings[i].mon_window_x = renderers[i]->geometry().x(); + monitor_settings[i].mon_window_y = renderers[i]->geometry().y(); + } } } ui->actionRemember_size_and_position->setChecked(window_remember); diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 79b5d9dda..d5a6b1967 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -32,6 +32,7 @@ public: void blitToWidget(int x, int y, int w, int h, int monitor_index); QSize getRenderWidgetSize(); void setSendKeyboardInput(bool enabled); + void checkFullscreenHotkey(); std::array, 8> renderers; signals: diff --git a/src/qt/qt_platform.cpp b/src/qt/qt_platform.cpp index 9f4c5ca6e..0274bc44a 100644 --- a/src/qt/qt_platform.cpp +++ b/src/qt/qt_platform.cpp @@ -570,14 +570,10 @@ c16stombs(char dst[], const uint16_t src[], int len) #endif #ifdef _WIN32 -# define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" # define LIB_NAME_GS "gsdll32.dll" -# define LIB_NAME_FREETYPE "freetype.dll" # define MOUSE_CAPTURE_KEYSEQ "F8+F12" #else -# define LIB_NAME_FLUIDSYNTH "libfluidsynth" # define LIB_NAME_GS "libgs" -# define LIB_NAME_FREETYPE "libfreetype" # define MOUSE_CAPTURE_KEYSEQ "CTRL-END" #endif @@ -590,13 +586,11 @@ ProgSettings::reloadStrings() translatedstrings[IDS_2077] = QCoreApplication::translate("", "Click to capture mouse").toStdWString(); translatedstrings[IDS_2078] = QCoreApplication::translate("", "Press F8+F12 to release mouse").replace("F8+F12", MOUSE_CAPTURE_KEYSEQ).replace("CTRL-END", QLocale::system().name() == "de_DE" ? "Strg+Ende" : "CTRL-END").toStdWString(); translatedstrings[IDS_2079] = QCoreApplication::translate("", "Press F8+F12 or middle button to release mouse").replace("F8+F12", MOUSE_CAPTURE_KEYSEQ).replace("CTRL-END", QLocale::system().name() == "de_DE" ? "Strg+Ende" : "CTRL-END").toStdWString(); - translatedstrings[IDS_2080] = QCoreApplication::translate("", "Failed to initialize FluidSynth").toStdWString(); translatedstrings[IDS_2131] = QCoreApplication::translate("", "Invalid configuration").toStdWString(); translatedstrings[IDS_4099] = QCoreApplication::translate("", "MFM/RLL or ESDI CD-ROM drives never existed").toStdWString(); translatedstrings[IDS_2094] = QCoreApplication::translate("", "Failed to set up PCap").toStdWString(); translatedstrings[IDS_2095] = QCoreApplication::translate("", "No PCap devices found").toStdWString(); translatedstrings[IDS_2096] = QCoreApplication::translate("", "Invalid PCap device").toStdWString(); - translatedstrings[IDS_2111] = QCoreApplication::translate("", "Unable to initialize FreeType").toStdWString(); translatedstrings[IDS_2112] = QCoreApplication::translate("", "Unable to initialize SDL, libsdl2 is required").toStdWString(); translatedstrings[IDS_2130] = QCoreApplication::translate("", "Make sure libpcap is installed and that you are on a libpcap-compatible network connection.").toStdWString(); translatedstrings[IDS_2115] = QCoreApplication::translate("", "Unable to initialize Ghostscript").toStdWString(); @@ -610,24 +604,12 @@ ProgSettings::reloadStrings() translatedstrings[IDS_2167] = QCoreApplication::translate("", "Failed to initialize network driver").toStdWString(); translatedstrings[IDS_2168] = QCoreApplication::translate("", "The network configuration will be switched to the null driver").toStdWString(); - auto flsynthstr = QCoreApplication::translate("", " is required for FluidSynth MIDI output."); - if (flsynthstr.contains("libfluidsynth")) { - flsynthstr.replace("libfluidsynth", LIB_NAME_FLUIDSYNTH); + auto gsstr = QCoreApplication::translate("", " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files."); + if (gsstr.contains("libgs")) { + gsstr.replace("libgs", LIB_NAME_GS); } else - flsynthstr.prepend(LIB_NAME_FLUIDSYNTH); - translatedstrings[IDS_2134] = flsynthstr.toStdWString(); - auto gssynthstr = QCoreApplication::translate("", " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files."); - if (gssynthstr.contains("libgs")) { - gssynthstr.replace("libgs", LIB_NAME_GS); - } else - gssynthstr.prepend(LIB_NAME_GS); - translatedstrings[IDS_2133] = gssynthstr.toStdWString(); - auto ftsynthstr = QCoreApplication::translate("", " is required for ESC/P printer emulation."); - if (ftsynthstr.contains("libfreetype")) { - ftsynthstr.replace("libfreetype", LIB_NAME_FREETYPE); - } else - ftsynthstr.prepend(LIB_NAME_FREETYPE); - translatedstrings[IDS_2132] = ftsynthstr.toStdWString(); + gsstr.prepend(LIB_NAME_GS); + translatedstrings[IDS_2133] = gsstr.toStdWString(); } wchar_t * diff --git a/src/qt/qt_settingsnetwork.ui b/src/qt/qt_settingsnetwork.ui index d6f77a0a2..d6681a65e 100644 --- a/src/qt/qt_settingsnetwork.ui +++ b/src/qt/qt_settingsnetwork.ui @@ -36,6 +36,52 @@ Network Card #1 + + + + + 0 + 0 + + + + Mode + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Interface + + + + + + + + 0 + 0 + + + + @@ -75,62 +121,10 @@ - - - - - 0 - 0 - - + + - Interface - - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 0 - 0 - - - - Mode + VDE Socket @@ -141,21 +135,7 @@ - - - - VDE Socket - - - - - - - - Network Card #2 - - - + Qt::Vertical @@ -168,8 +148,28 @@ - - + + + + + Network Card #2 + + + + + + + 0 + 0 + + + + Mode + + + + + 0 @@ -178,13 +178,6 @@ - - - - Configure - - - @@ -198,6 +191,16 @@ + + + + + 0 + 0 + + + + @@ -224,26 +227,10 @@ - - - - - 0 - 0 - - + + - Mode - - - - - - - - 0 - 0 - + Configure @@ -255,20 +242,14 @@ - - - - - - - Network Card #3 - - - - + + + 127 + + - + Qt::Vertical @@ -280,8 +261,15 @@ - - + + + + + Network Card #3 + + + + 0 @@ -289,7 +277,7 @@ - Adapter + Mode @@ -326,6 +314,19 @@ + + + + + 0 + 0 + + + + Adapter + + + @@ -359,8 +360,35 @@ + + + + 127 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Network Card #4 + + - + 0 @@ -372,24 +400,14 @@ - - - - - Network Card #4 - - - - + + - + 0 0 - - Adapter - @@ -405,8 +423,18 @@ - - + + + + + 0 + 0 + + + + + + 0 @@ -414,7 +442,7 @@ - Mode + Adapter @@ -431,16 +459,6 @@ - - - - - 0 - 0 - - - - @@ -454,6 +472,20 @@ + + + + 127 + + + + + + + VDE Socket + + + @@ -467,26 +499,6 @@ - - - - - 0 - 0 - - - - - - - - - - - VDE Socket - - - diff --git a/src/qt/qt_winrawinputfilter.cpp b/src/qt/qt_winrawinputfilter.cpp index bac049391..73eea9ad8 100644 --- a/src/qt/qt_winrawinputfilter.cpp +++ b/src/qt/qt_winrawinputfilter.cpp @@ -246,6 +246,8 @@ WindowsRawInputFilter::keyboard_handle(PRAWINPUT raw) it's not an invalid scan code. */ if (scancode != 0xFFFF) keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode); + + window->checkFullscreenHotkey(); } } else { if (rawKB.MakeCode == 0x1D) { diff --git a/src/scsi/scsi_aha154x.c b/src/scsi/scsi_aha154x.c index de2d014c3..2a1c23566 100644 --- a/src/scsi/scsi_aha154x.c +++ b/src/scsi/scsi_aha154x.c @@ -71,7 +71,7 @@ uint16_t aha_ports[] = { static uint8_t *aha1542cp_pnp_rom = NULL; #pragma pack(push, 1) -typedef struct { +typedef struct aha_setup_t { uint8_t CustomerSignature[20]; uint8_t uAutoRetry; uint8_t uBoardSwitches; @@ -123,8 +123,8 @@ aha_mem_write(uint32_t addr, uint8_t val, void *priv) static uint8_t aha_mem_read(uint32_t addr, void *priv) { - x54x_t *dev = (x54x_t *) priv; - rom_t *rom = &dev->bios; + const x54x_t *dev = (x54x_t *) priv; + const rom_t *rom = &dev->bios; addr &= 0x3fff; @@ -163,7 +163,7 @@ aha_eeprom_save(x54x_t *dev) } static uint8_t -aha154x_eeprom(x54x_t *dev, uint8_t cmd, uint8_t arg, uint8_t len, uint8_t off, uint8_t *bufp) +aha154x_eeprom(x54x_t *dev, uint8_t cmd, UNUSED(uint8_t arg), uint8_t len, uint8_t off, uint8_t *bufp) { uint8_t r = 0xff; int c; @@ -217,39 +217,42 @@ aha154x_mmap(x54x_t *dev, uint8_t cmd) /* Enable the mapper, so, set ROM2 active. */ dev->bios.rom = dev->rom2; break; + + default: + break; } return 0; } static uint8_t -aha_get_host_id(void *p) +aha_get_host_id(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; return dev->nvr[0] & 0x07; } static uint8_t -aha_get_irq(void *p) +aha_get_irq(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; return (dev->nvr[1] & 0x07) + 9; } static uint8_t -aha_get_dma(void *p) +aha_get_dma(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; return (dev->nvr[1] >> 4) & 0x07; } static uint8_t -aha_cmd_is_fast(void *p) +aha_cmd_is_fast(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; if (dev->Command == CMD_BIOS_SCSI) return 1; @@ -258,9 +261,9 @@ aha_cmd_is_fast(void *p) } static uint8_t -aha_fast_cmds(void *p, uint8_t cmd) +aha_fast_cmds(void *priv, uint8_t cmd) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; if (cmd == CMD_BIOS_SCSI) { dev->BIOSMailboxReq++; @@ -271,9 +274,9 @@ aha_fast_cmds(void *p, uint8_t cmd) } static uint8_t -aha_param_len(void *p) +aha_param_len(void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; switch (dev->Command) { case CMD_BIOS_MBINIT: @@ -307,10 +310,10 @@ aha_param_len(void *p) } static uint8_t -aha_cmds(void *p) +aha_cmds(void *priv) { - x54x_t *dev = (x54x_t *) p; - MailboxInit_t *mbi; + x54x_t *dev = (x54x_t *) priv; + const MailboxInit_t *mbi; if (!dev->CmdParamLeft) { aha_log("Running Operation Code 0x%02X\n", dev->Command); @@ -351,7 +354,9 @@ aha_cmds(void *p) * and expects a 0x04 back in the INTR * register. --FvK */ - /* dev->Interrupt = aha154x_shram(dev,val); */ +#if 0 + dev->Interrupt = aha154x_shram(dev,val); +#endif dev->Interrupt = aha154x_shram(dev, dev->CmdBuf[0]); break; @@ -451,9 +456,9 @@ aha_cmds(void *p) } static void -aha_setup_data(void *p) +aha_setup_data(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; ReplyInquireSetupInformation *ReplyISI; aha_setup_t *aha_setup; @@ -486,9 +491,9 @@ aha_do_bios_mail(x54x_t *dev) } static void -aha_callback(void *p) +aha_callback(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; if (dev->BIOSMailboxInit && dev->BIOSMailboxReq) aha_do_bios_mail(dev); @@ -497,7 +502,7 @@ aha_callback(void *p) static uint8_t aha_mca_read(int port, void *priv) { - x54x_t *dev = (x54x_t *) priv; + const x54x_t *dev = (x54x_t *) priv; return (dev->pos_regs[port & 7]); } @@ -551,6 +556,9 @@ aha_mca_write(int port, uint8_t val, void *priv) case 0x10: /* [1]=xx01 0xxx */ dev->rom_addr = 0xC8000; break; + + default: + break; } else { /* Disabled. */ @@ -606,7 +614,7 @@ aha_mca_write(int port, uint8_t val, void *priv) static uint8_t aha_mca_feedb(void *priv) { - x54x_t *dev = (x54x_t *) priv; + const x54x_t *dev = (x54x_t *) priv; return (dev->pos_regs[2] & 0x01); } @@ -696,6 +704,8 @@ aha_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) break; #endif + default: + break; } } @@ -997,6 +1007,9 @@ aha_init(const device_t *info) case 0x0334: dev->bios_path = "roms/scsi/adaptec/aha1540b320_334.bin"; break; + + default: + break; } dev->fw_rev = "A005"; /* The 3.2 microcode says A012. */ /* This is configurable from the configuration for the 154xB, the rest of the controllers read it from the EEPROM. */ @@ -1082,6 +1095,9 @@ aha_init(const device_t *info) mca_add(aha_mca_read, aha_mca_write, aha_mca_feedb, NULL, dev); dev->ha_bps = 5000000.0; /* normal SCSI */ break; + + default: + break; } /* Initialize ROM BIOS if needed. */ @@ -1106,7 +1122,7 @@ aha_init(const device_t *info) } } - return (dev); + return dev; } // clang-format off diff --git a/src/scsi/scsi_buslogic.c b/src/scsi/scsi_buslogic.c index efc2a62ae..d38a967bd 100644 --- a/src/scsi/scsi_buslogic.c +++ b/src/scsi/scsi_buslogic.c @@ -53,20 +53,20 @@ * configuration parameters. */ #pragma pack(push, 1) -typedef struct { - uint8_t aInternalSignature[2]; - uint8_t cbInformation; - uint8_t aHostAdaptertype[6]; - uint8_t uReserved1; - uint8_t fFloppyEnabled : 1, - fFloppySecondary : 1, - fLevelSensitiveInterrupt : 1, - uReserved2 : 2, - uSystemRAMAreForBIOS : 3; - uint8_t uDMAChannel : 7, - fDMAAutoConfiguration : 1, - uIrqChannel : 7, - fIrqAutoConfiguration : 1; +typedef struct AutoSCSIRam_t { + uint8_t aInternalSignature[2]; + uint8_t cbInformation; + uint8_t aHostAdaptertype[6]; + uint8_t uReserved1; + uint8_t fFloppyEnabled : 1; + uint8_t fFloppySecondary : 1; + uint8_t fLevelSensitiveInterrupt : 1; + uint8_t uReserved2 : 2; + uint8_t uSystemRAMAreForBIOS : 3; + uint8_t uDMAChannel : 7; + uint8_t fDMAAutoConfiguration : 1; + uint8_t uIrqChannel : 7; + uint8_t fIrqAutoConfiguration : 1; uint8_t uDMATransferRate; uint8_t uSCSIId; uint8_t uSCSIConfiguration; @@ -142,46 +142,45 @@ typedef struct { /* Structure for the INQUIRE_EXTENDED_SETUP_INFORMATION. */ #pragma pack(push, 1) -typedef struct { +typedef struct ReplyInquireExtendedSetupInformation_t { uint8_t uBusType; uint8_t uBiosAddress; uint16_t u16ScatterGatherLimit; uint8_t cMailbox; uint32_t uMailboxAddressBase; - uint8_t uReserved1 : 2, - fFastEISA : 1, - uReserved2 : 3, - fLevelSensitiveInterrupt : 1, - uReserved3 : 1; + uint8_t uReserved1 : 2; + uint8_t fFastEISA : 1; + uint8_t uReserved2 : 3; + uint8_t fLevelSensitiveInterrupt : 1; + uint8_t uReserved3 : 1; uint8_t aFirmwareRevision[3]; - uint8_t fHostWideSCSI : 1, - fHostDifferentialSCSI : 1, - fHostSupportsSCAM : 1, - fHostUltraSCSI : 1, - fHostSmartTermination : 1, - uReserved4 : 3; + uint8_t fHostWideSCSI : 1; + uint8_t fHostDifferentialSCSI : 1; + uint8_t fHostSupportsSCAM : 1; + uint8_t fHostUltraSCSI : 1; + uint8_t fHostSmartTermination : 1; + uint8_t uReserved4 : 3; } ReplyInquireExtendedSetupInformation; #pragma pack(pop) /* Structure for the INQUIRE_PCI_HOST_ADAPTER_INFORMATION reply. */ #pragma pack(push, 1) -typedef struct { +typedef struct BuslogicPCIInformation_t { uint8_t IsaIOPort; uint8_t IRQ; - uint8_t LowByteTerminated : 1, - HighByteTerminated : 1, - uReserved : 2, /* Reserved. */ - JP1 : 1, /* Whatever that means. */ - JP2 : 1, /* Whatever that means. */ - JP3 : 1, /* Whatever that means. */ - InformationIsValid : 1; - uint8_t uReserved2; /* Reserved. */ + uint8_t LowByteTerminated : 1; + uint8_t HighByteTerminated : 1; + uint8_t uReserved : 2; /* Reserved. */ + uint8_t JP1 : 1; /* Whatever that means. */ + uint8_t JP2 : 1; /* Whatever that means. */ + uint8_t JP3 : 1; /* Whatever that means. */ + uint8_t InformationIsValid : 1; + uint8_t uReserved2; /* Reserved. */ } BuslogicPCIInformation_t; #pragma pack(pop) #pragma pack(push, 1) -typedef struct -{ +typedef struct ESCMD_t { /** Data length. */ uint32_t DataLength; /** Data pointer. */ @@ -204,14 +203,14 @@ typedef struct #pragma pack(pop) #pragma pack(push, 1) -typedef struct { +typedef struct MailboxInitExtended_t { uint8_t Count; uint32_t Address; } MailboxInitExtended_t; #pragma pack(pop) #pragma pack(push, 1) -typedef struct { +typedef struct buslogic_data_t { rom_t bios; int ExtendedLUNCCBFormat; int fAggressiveRoundRobinMode; @@ -220,11 +219,11 @@ typedef struct { int MMIOBase; int chip; int has_bios; - uint32_t bios_addr, - bios_size, - bios_mask; - uint8_t AutoSCSIROM[32768]; - uint8_t SCAMData[65536]; + uint32_t bios_addr; + uint32_t bios_size; + uint32_t bios_mask; + uint8_t AutoSCSIROM[32768]; + uint8_t SCAMData[65536]; } buslogic_data_t; #pragma pack(pop) @@ -325,6 +324,9 @@ BuslogicAutoSCSIRamSetDefaults(x54x_t *dev, uint8_t safe) case CHIP_BUSLOGIC_PCI_958D_1995_12_30: memcpy(&(HALR->structured.autoSCSIData.aHostAdaptertype[1]), "958D", 4); break; + + default: + break; } HALR->structured.autoSCSIData.fLevelSensitiveInterrupt = (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30) ? 1 : 0; @@ -407,17 +409,17 @@ BuslogicAutoSCSIRamSetDefaults(x54x_t *dev, uint8_t safe) static void BuslogicInitializeAutoSCSIRam(x54x_t *dev) { - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + const HALocalRAM *HALR = &bl->LocalRAM; - FILE *f; + FILE *fp; - f = nvr_fopen(BuslogicGetNVRFileName(bl), "rb"); - if (f) { - if (fread(&(bl->LocalRAM.structured.autoSCSIData), 1, 64, f) != 64) + fp = nvr_fopen(BuslogicGetNVRFileName(bl), "rb"); + if (fp) { + if (fread(&(bl->LocalRAM.structured.autoSCSIData), 1, 64, fp) != 64) fatal("BuslogicInitializeAutoSCSIRam(): Error reading data\n"); - fclose(f); - f = NULL; + fclose(fp); + fp = NULL; if (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30) { x54x_io_remove(dev, dev->Base, 4); switch (HALR->structured.autoSCSIData.uHostAdapterIoPortAddress) { @@ -439,9 +441,9 @@ BuslogicInitializeAutoSCSIRam(x54x_t *dev) } static void -buslogic_cmd_phase1(void *p) +buslogic_cmd_phase1(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; if ((dev->CmdParam == 2) && (dev->Command == 0x90)) { dev->CmdParamLeft = dev->CmdBuf[1]; @@ -463,12 +465,12 @@ buslogic_cmd_phase1(void *p) } static uint8_t -buslogic_get_host_id(void *p) +buslogic_get_host_id(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + const HALocalRAM *HALR = &bl->LocalRAM; if ((bl->chip == CHIP_BUSLOGIC_ISA_542B_1991_12_14) || (bl->chip == CHIP_BUSLOGIC_ISA_545S_1992_10_05) || (bl->chip == CHIP_BUSLOGIC_ISA_542BH_1993_05_23) || (bl->chip == CHIP_BUSLOGIC_VLB_445S_1993_11_16)) return dev->HostID; @@ -477,14 +479,14 @@ buslogic_get_host_id(void *p) } static uint8_t -buslogic_get_irq(void *p) +buslogic_get_irq(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; uint8_t bl_irq[7] = { 0, 9, 10, 11, 12, 14, 15 }; - HALocalRAM *HALR = &bl->LocalRAM; + const HALocalRAM *HALR = &bl->LocalRAM; if ((bl->chip == CHIP_BUSLOGIC_ISA_542B_1991_12_14) || (bl->chip == CHIP_BUSLOGIC_ISA_545S_1992_10_05) || (bl->chip == CHIP_BUSLOGIC_ISA_542BH_1993_05_23) || (bl->chip == CHIP_BUSLOGIC_VLB_445S_1993_11_16) || (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30)) return dev->Irq; @@ -493,14 +495,14 @@ buslogic_get_irq(void *p) } static uint8_t -buslogic_get_dma(void *p) +buslogic_get_dma(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; uint8_t bl_dma[4] = { 0, 5, 6, 7 }; - HALocalRAM *HALR = &bl->LocalRAM; + const HALocalRAM *HALR = &bl->LocalRAM; if (bl->chip == CHIP_BUSLOGIC_PCI_958D_1995_12_30) return (dev->Base ? 7 : 0); @@ -511,10 +513,10 @@ buslogic_get_dma(void *p) } static uint8_t -buslogic_param_len(void *p) +buslogic_param_len(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; switch (dev->Command) { case 0x21: @@ -577,10 +579,10 @@ BuslogicSCSIBIOSDMATransfer(x54x_t *dev, ESCMD *ESCSICmd, uint8_t TargetID, int if (dir && ((ESCSICmd->DataDirection == CCB_DATA_XFER_OUT) || (ESCSICmd->DataDirection == 0x00))) { buslogic_log("BusLogic BIOS DMA: Reading %i bytes from %08X\n", TransferLength, Address); - dma_bm_read(Address, (uint8_t *) sd->sc->temp_buffer, TransferLength, transfer_size); + dma_bm_read(Address, sd->sc->temp_buffer, TransferLength, transfer_size); } else if (!dir && ((ESCSICmd->DataDirection == CCB_DATA_XFER_IN) || (ESCSICmd->DataDirection == 0x00))) { buslogic_log("BusLogic BIOS DMA: Writing %i bytes at %08X\n", TransferLength, Address); - dma_bm_write(Address, (uint8_t *) sd->sc->temp_buffer, TransferLength, transfer_size); + dma_bm_write(Address, sd->sc->temp_buffer, TransferLength, transfer_size); } } } @@ -666,18 +668,18 @@ BuslogicSCSIBIOSRequestSetup(x54x_t *dev, uint8_t *CmdBuf, uint8_t *DataInBuf, u } static uint8_t -buslogic_cmds(void *p) +buslogic_cmds(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + const HALocalRAM *HALR = &bl->LocalRAM; FILE *f; uint16_t TargetsPresentMask = 0; uint32_t Offset; int i = 0; - MailboxInitExtended_t *MailboxInitE; + const MailboxInitExtended_t *MailboxInitE; ReplyInquireExtendedSetupInformation *ReplyIESI; BuslogicPCIInformation_t *ReplyPI; int cCharsToTransfer; @@ -827,6 +829,9 @@ buslogic_cmds(void *p) case CHIP_BUSLOGIC_PCI_958D_1995_12_30: ReplyIESI->uBusType = 'E'; /* PCI style */ break; + + default: + break; } ReplyIESI->uBiosAddress = 0xd8; ReplyIESI->u16ScatterGatherLimit = 8192; @@ -1012,13 +1017,13 @@ buslogic_cmds(void *p) } static void -buslogic_setup_data(void *p) +buslogic_setup_data(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; ReplyInquireSetupInformation *ReplyISI; buslogic_setup_t *bl_setup; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; - HALocalRAM *HALR = &bl->LocalRAM; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + const HALocalRAM *HALR = &bl->LocalRAM; ReplyISI = (ReplyInquireSetupInformation *) dev->DataBuf; bl_setup = (buslogic_setup_t *) ReplyISI->VendorSpecificData; @@ -1048,14 +1053,17 @@ buslogic_setup_data(void *p) case CHIP_BUSLOGIC_PCI_958D_1995_12_30: bl_setup->uHostBusType = 'F'; break; + + default: + break; } } static uint8_t -buslogic_is_aggressive_mode(void *p) +buslogic_is_aggressive_mode(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; buslogic_log("Buslogic: Aggressive mode = %d\n", bl->fAggressiveRoundRobinMode); @@ -1063,10 +1071,10 @@ buslogic_is_aggressive_mode(void *p) } static uint8_t -buslogic_interrupt_type(void *p) +buslogic_interrupt_type(void *priv) { - x54x_t *dev = (x54x_t *) p; - buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; + x54x_t *dev = (x54x_t *) priv; + const buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; if ((bl->chip == CHIP_BUSLOGIC_ISA_542B_1991_12_14) || (bl->chip == CHIP_BUSLOGIC_ISA_545S_1992_10_05) || (bl->chip == CHIP_BUSLOGIC_ISA_542BH_1993_05_23) || (bl->chip == CHIP_BUSLOGIC_VLB_445S_1993_11_16) || (bl->chip == CHIP_BUSLOGIC_MCA_640A_1993_05_23)) return 0; @@ -1075,9 +1083,9 @@ buslogic_interrupt_type(void *p) } static void -buslogic_reset(void *p) +buslogic_reset(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; bl->ExtendedLUNCCBFormat = 0; @@ -1108,9 +1116,9 @@ BuslogicBIOSUpdate(buslogic_data_t *bl) } static uint8_t -BuslogicPCIRead(int func, int addr, void *p) +BuslogicPCIRead(UNUSED(int func), int addr, void *priv) { - x54x_t *dev = (x54x_t *) p; + const x54x_t *dev = (x54x_t *) priv; #ifdef ENABLE_BUSLOGIC_LOG buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; #endif @@ -1175,28 +1183,28 @@ BuslogicPCIRead(int func, int addr, void *p) case 0x31: /* PCI_ROMBAR 15:11 */ buslogic_log("BT-958D: BIOS BAR 01 = %02X\n", (buslogic_pci_bar[2].addr_regs[1] & bl->bios_mask)); return buslogic_pci_bar[2].addr_regs[1]; - break; case 0x32: /* PCI_ROMBAR 23:16 */ buslogic_log("BT-958D: BIOS BAR 02 = %02X\n", buslogic_pci_bar[2].addr_regs[2]); return buslogic_pci_bar[2].addr_regs[2]; - break; case 0x33: /* PCI_ROMBAR 31:24 */ buslogic_log("BT-958D: BIOS BAR 03 = %02X\n", buslogic_pci_bar[2].addr_regs[3]); return buslogic_pci_bar[2].addr_regs[3]; - break; case 0x3C: return dev->Irq; case 0x3D: return PCI_INTA; + + default: + break; } return 0; } static void -BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) +BuslogicPCIWrite(UNUSED(int func), int addr, uint8_t val, void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; uint8_t valxor; @@ -1224,7 +1232,9 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) case 0x10: val &= 0xe0; val |= 1; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x11: case 0x12: @@ -1248,7 +1258,9 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) case 0x14: val &= 0xe0; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x15: case 0x16: @@ -1259,7 +1271,9 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) /* Then let's set the PCI regs. */ buslogic_pci_bar[1].addr_regs[addr & 3] = val; /* Then let's calculate the new I/O base. */ - // bl->MMIOBase = buslogic_pci_bar[1].addr & 0xffffffe0; +#if 0 + bl->MMIOBase = buslogic_pci_bar[1].addr & 0xffffffe0; +#endif /* Give it a 4 kB alignment as that's this emulator's granularity. */ buslogic_pci_bar[1].addr &= 0xffffc000; bl->MMIOBase = buslogic_pci_bar[1].addr & 0xffffc000; @@ -1292,6 +1306,9 @@ BuslogicPCIWrite(int func, int addr, uint8_t val, void *p) } else dev->Irq = 0; return; + + default: + break; } } @@ -1317,7 +1334,7 @@ BuslogicInitializeLocalRAM(buslogic_data_t *bl) static uint8_t buslogic_mca_read(int port, void *priv) { - x54x_t *dev = (x54x_t *) priv; + const x54x_t *dev = (x54x_t *) priv; return (dev->pos_regs[port & 7]); } @@ -1386,6 +1403,9 @@ buslogic_mca_write(int port, uint8_t val, void *priv) case 0x20: /* [0]=001x xxxx */ bl->bios_addr = 0xC4000; break; + + default: + break; } else { /* Disabled. */ @@ -1491,15 +1511,15 @@ buslogic_mca_write(int port, uint8_t val, void *priv) static uint8_t buslogic_mca_feedb(void *priv) { - x54x_t *dev = (x54x_t *) priv; + const x54x_t *dev = (x54x_t *) priv; return (dev->pos_regs[2] & 0x01); } void -BuslogicDeviceReset(void *p) +BuslogicDeviceReset(void *priv) { - x54x_t *dev = (x54x_t *) p; + x54x_t *dev = (x54x_t *) priv; buslogic_data_t *bl = (buslogic_data_t *) dev->ven_data; x54x_device_reset(dev); @@ -1513,14 +1533,14 @@ buslogic_init(const device_t *info) { x54x_t *dev; char *bios_rom_name; - uint16_t bios_rom_size; - uint16_t bios_rom_mask; + uint16_t bios_rom_size = 0; + uint16_t bios_rom_mask = 0; uint8_t has_autoscsi_rom; - char *autoscsi_rom_name; - uint16_t autoscsi_rom_size; + char *autoscsi_rom_name = NULL; + uint16_t autoscsi_rom_size = 0; uint8_t has_scam_rom; - char *scam_rom_name; - uint16_t scam_rom_size; + char *scam_rom_name = NULL; + uint16_t scam_rom_size = 0; FILE *f; buslogic_data_t *bl; uint32_t bios_rom_addr; @@ -1684,6 +1704,9 @@ buslogic_init(const device_t *info) dev->ha_bps = 20000000.0; /* ultra SCSI */ dev->max_id = 15; /* wide SCSI */ break; + + default: + break; } if ((dev->Base != 0) && !(dev->card_bus & DEVICE_MCA) && !(dev->card_bus & DEVICE_PCI)) { diff --git a/src/scsi/scsi_cdrom.c b/src/scsi/scsi_cdrom.c index d100902d2..d192aec53 100644 --- a/src/scsi/scsi_cdrom.c +++ b/src/scsi/scsi_cdrom.c @@ -42,8 +42,7 @@ #include <86box/version.h> #pragma pack(push, 1) -typedef struct -{ +typedef struct gesn_cdb_t { uint8_t opcode; uint8_t polled; uint8_t reserved2[2]; @@ -53,8 +52,7 @@ typedef struct uint8_t control; } gesn_cdb_t; -typedef struct -{ +typedef struct gesn_event_header_t { uint16_t len; uint8_t notification_class; uint8_t supported_events; @@ -565,6 +563,9 @@ scsi_cdrom_atapi_phase_to_scsi(scsi_cdrom_t *dev) return 1; case 3: return 7; + + default: + break; } } else { if ((dev->phase & 3) == 3) @@ -577,9 +578,9 @@ scsi_cdrom_atapi_phase_to_scsi(scsi_cdrom_t *dev) } static uint32_t -scsi_cdrom_get_channel(void *p, int channel) +scsi_cdrom_get_channel(void *priv, int channel) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) p; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; if (!dev) return channel + 1; @@ -591,9 +592,9 @@ scsi_cdrom_get_channel(void *p, int channel) } static uint32_t -scsi_cdrom_get_volume(void *p, int channel) +scsi_cdrom_get_volume(void *priv, int channel) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) p; + const scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; if (!dev) return 255; @@ -682,7 +683,7 @@ scsi_cdrom_drive_status_load(scsi_cdrom_t *dev) } static uint8_t -scsi_cdrom_drive_status_read(scsi_cdrom_t *dev, uint8_t page_control, uint8_t page, uint8_t pos) +scsi_cdrom_drive_status_read(scsi_cdrom_t *dev, UNUSED(uint8_t page_control), uint8_t page, uint8_t pos) { return dev->ms_drive_status_pages_saved.pages[page][pos]; } @@ -735,12 +736,12 @@ scsi_cdrom_mode_sense_read(scsi_cdrom_t *dev, uint8_t page_control, uint8_t page case 0: case 3: return dev->ms_pages_saved_sony.pages[page][pos]; - break; case 1: return scsi_cdrom_mode_sense_pages_changeable_sony.pages[page][pos]; - break; case 2: return scsi_cdrom_mode_sense_pages_default_sony_scsi.pages[page][pos]; + + default: break; } } else { @@ -748,16 +749,17 @@ scsi_cdrom_mode_sense_read(scsi_cdrom_t *dev, uint8_t page_control, uint8_t page case 0: case 3: return dev->ms_pages_saved.pages[page][pos]; - break; case 1: return scsi_cdrom_mode_sense_pages_changeable.pages[page][pos]; - break; case 2: if (dev->drv->bus_type == CDROM_BUS_SCSI) return scsi_cdrom_mode_sense_pages_default_scsi.pages[page][pos]; else return scsi_cdrom_mode_sense_pages_default.pages[page][pos]; + + default: break; + } } @@ -881,7 +883,9 @@ scsi_cdrom_update_request_length(scsi_cdrom_t *dev, int len, int block_len) break; } } - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif default: dev->packet_len = len; @@ -957,7 +961,9 @@ scsi_cdrom_command_common(scsi_cdrom_t *dev) scsi_cdrom_log("CD-ROM %i: Seek period: %" PRIu64 " us\n", dev->id, (uint64_t) period); dev->callback += period; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x25: case 0x42: case 0x43: @@ -1116,7 +1122,7 @@ scsi_cdrom_data_command_finish(scsi_cdrom_t *dev, int len, int block_len, int al } static void -scsi_cdrom_sense_clear(scsi_cdrom_t *dev, int command) +scsi_cdrom_sense_clear(scsi_cdrom_t *dev, UNUSED(int command)) { scsi_cdrom_sense_key = scsi_cdrom_asc = scsi_cdrom_ascq = 0; } @@ -1495,9 +1501,9 @@ scsi_cdrom_read_dvd_structure(scsi_cdrom_t *dev, int format, const uint8_t *pack } static void -scsi_cdrom_insert(void *p) +scsi_cdrom_insert(void *priv) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) p; + scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; if (!dev) return; @@ -1934,7 +1940,9 @@ begin: /* IMPORTANT: Convert the command to new read CD for pass through purposes. */ dev->current_cdb[0] = GPCMD_READ_CD; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_READ_6: case GPCMD_READ_10: @@ -2012,6 +2020,9 @@ begin: return; } break; + + default: + break; } if (!dev->sector_len) { @@ -2549,6 +2560,9 @@ begin: pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; len = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9]; break; + + default: + break; } if ((dev->drv->host_drive < 1) || (dev->drv->cd_status <= CD_STATUS_DATA_ONLY)) { @@ -2767,6 +2781,9 @@ begin: case 3: /* Load the disc (close tray). */ cdrom_reload(dev->id); break; + + default: + break; } scsi_cdrom_command_complete(dev); @@ -3105,6 +3122,9 @@ atapi_out: case GPCMD_SEEK_10: pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; break; + + default: + break; } dev->drv->seek_diff = ABS((int) (pos - dev->drv->seek_pos)); if (cdb[0] == GPCMD_SEEK_10) { @@ -3439,6 +3459,9 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) } } break; + + default: + break; } scsi_cdrom_command_stop((scsi_common_t *) dev); @@ -3446,9 +3469,9 @@ scsi_cdrom_phase_data_out(scsi_common_t *sc) } static void -scsi_cdrom_close(void *p) +scsi_cdrom_close(void *priv) { - scsi_cdrom_t *dev = (scsi_cdrom_t *) p; + scsi_cdrom_t *dev = (scsi_cdrom_t *) priv; if (dev) free(dev); @@ -3509,7 +3532,7 @@ scsi_cdrom_get_timings(int ide_has_dma, int type) static void scsi_cdrom_identify(ide_t *ide, int ide_has_dma) { - scsi_cdrom_t *dev; + const scsi_cdrom_t *dev; char device_identify[9] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', 0 }; dev = (scsi_cdrom_t *) ide->sc; diff --git a/src/scsi/scsi_device.c b/src/scsi/scsi_device.c index 42725c91b..4fce9f989 100644 --- a/src/scsi/scsi_device.c +++ b/src/scsi/scsi_device.c @@ -25,6 +25,7 @@ #include <86box/hdd.h> #include <86box/scsi.h> #include <86box/scsi_device.h> +#include <86box/plat_unused.h> scsi_device_t scsi_devices[SCSI_BUS_MAX][SCSI_ID_MAX]; @@ -97,7 +98,7 @@ scsi_device_valid(scsi_device_t *dev) } int -scsi_device_cdb_length(scsi_device_t *dev) +scsi_device_cdb_length(UNUSED(scsi_device_t *dev)) { /* Right now, it's 12 for all devices. */ return 12; diff --git a/src/scsi/scsi_disk.c b/src/scsi/scsi_disk.c index f504985ef..2bd61313b 100644 --- a/src/scsi/scsi_disk.c +++ b/src/scsi/scsi_disk.c @@ -182,9 +182,9 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, case 2: case 3: switch (pos) { + default: case 0: case 1: - default: return scsi_disk_mode_sense_pages_default.pages[page][pos]; case 2: case 6: @@ -201,6 +201,8 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, case 5: return dev->drv->hpc & 0xff; } + + default: break; } else if (page == GPMODE_FORMAT_DEVICE_PAGE) @@ -210,9 +212,9 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, case 2: case 3: switch (pos) { + default: case 0: case 1: - default: return scsi_disk_mode_sense_pages_default.pages[page][pos]; /* Actual sectors + the 1 "alternate sector" we report. */ case 10: @@ -220,6 +222,8 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, case 11: return (dev->drv->spt + 1) & 0xff; } + + default: break; } else @@ -229,6 +233,9 @@ scsi_disk_mode_sense_read(scsi_disk_t *dev, uint8_t page_control, uint8_t page, return dev->ms_pages_saved.pages[page][pos]; case 2: return scsi_disk_mode_sense_pages_default.pages[page][pos]; + + default: + break; } return 0; @@ -306,7 +313,7 @@ scsi_disk_command_write_dma(scsi_disk_t *dev) } static void -scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int alloc_len, int direction) +scsi_disk_data_command_finish(scsi_disk_t *dev, int len, UNUSED(int block_len), int alloc_len, int direction) { scsi_disk_log("SCSI HD %i: Finishing command (%02X): %i, %i, %i, %i, %i\n", dev->id, dev->current_cdb[0], len, block_len, alloc_len, direction, dev->request_length); @@ -325,7 +332,7 @@ scsi_disk_data_command_finish(scsi_disk_t *dev, int len, int block_len, int allo } static void -scsi_disk_sense_clear(scsi_disk_t *dev, int command) +scsi_disk_sense_clear(scsi_disk_t *dev, UNUSED(int command)) { scsi_disk_sense_key = scsi_disk_asc = scsi_disk_ascq = 0; } @@ -500,7 +507,7 @@ scsi_disk_request_sense_for_scsi(scsi_common_t *sc, uint8_t *buffer, uint8_t all } static void -scsi_disk_set_buf_len(scsi_disk_t *dev, int32_t *BufLen, int32_t *src_len) +scsi_disk_set_buf_len(UNUSED(scsi_disk_t *dev), int32_t *BufLen, int32_t *src_len) { if (*BufLen == -1) *BufLen = *src_len; @@ -590,7 +597,9 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) scsi_disk_invalid_field(dev); return; } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case GPCMD_SCSI_RESERVE: case GPCMD_SCSI_RELEASE: case GPCMD_TEST_UNIT_READY: @@ -661,6 +670,9 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; + + default: + break; } if ((dev->sector_pos > last_sector) /* || ((dev->sector_pos + dev->sector_len - 1) > last_sector)*/) { @@ -737,6 +749,9 @@ scsi_disk_command(scsi_common_t *sc, uint8_t *cdb) dev->sector_len = (((uint32_t) cdb[6]) << 24) | (((uint32_t) cdb[7]) << 16) | (((uint32_t) cdb[8]) << 8) | ((uint32_t) cdb[9]); dev->sector_pos = (((uint32_t) cdb[2]) << 24) | (((uint32_t) cdb[3]) << 16) | (((uint32_t) cdb[4]) << 8) | ((uint32_t) cdb[5]); break; + + default: + break; } if ((dev->sector_pos > last_sector) /* || @@ -1001,6 +1016,9 @@ atapi_out: case GPCMD_SEEK_10: pos = (cdb[2] << 24) | (cdb[3] << 16) | (cdb[4] << 8) | cdb[5]; break; + + default: + break; } scsi_disk_seek(dev, pos); @@ -1046,26 +1064,26 @@ scsi_disk_command_stop(scsi_common_t *sc) static uint8_t scsi_disk_phase_data_out(scsi_common_t *sc) { - scsi_disk_t *dev = (scsi_disk_t *) sc; - uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; - uint8_t scsi_id = dev->drv->scsi_id & 0x0f; - int i; - int32_t *BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; - uint32_t last_sector = hdd_image_get_last_sector(dev->id); - uint32_t c; - uint32_t h; - uint32_t s; - uint32_t last_to_write = 0; - uint16_t block_desc_len; - uint16_t pos; - uint16_t param_list_len; - uint8_t hdr_len; - uint8_t val; - uint8_t old_val; - uint8_t ch; - uint8_t error = 0; - uint8_t page; - uint8_t page_len; + scsi_disk_t *dev = (scsi_disk_t *) sc; + uint8_t scsi_bus = (dev->drv->scsi_id >> 4) & 0x0f; + uint8_t scsi_id = dev->drv->scsi_id & 0x0f; + int i; + const int32_t *BufLen = &scsi_devices[scsi_bus][scsi_id].buffer_length; + uint32_t last_sector = hdd_image_get_last_sector(dev->id); + uint32_t c; + uint32_t h; + uint32_t s; + uint32_t last_to_write = 0; + uint16_t block_desc_len; + uint16_t pos; + uint16_t param_list_len; + uint8_t hdr_len; + uint8_t val; + uint8_t old_val; + uint8_t ch; + uint8_t error = 0; + uint8_t page; + uint8_t page_len; if (!*BufLen) { scsi_disk_set_phase(dev, SCSI_PHASE_STATUS); diff --git a/src/scsi/scsi_ncr5380.c b/src/scsi/scsi_ncr5380.c index 2d21592c9..8b0ae3c0c 100644 --- a/src/scsi/scsi_ncr5380.c +++ b/src/scsi/scsi_ncr5380.c @@ -93,9 +93,15 @@ #define STATUS_BUFFER_NOT_READY 0x04 #define STATUS_53C80_ACCESSIBLE 0x80 -typedef struct { - uint8_t icr, mode, tcr, data_wait; - uint8_t isr, output_data, target_id, tx_data; +typedef struct ncr_t { + uint8_t icr; + uint8_t mode; + uint8_t tcr; + uint8_t data_wait; + uint8_t isr; + uint8_t output_data; + uint8_t target_id; + uint8_t tx_data; uint8_t msglun; uint8_t command[20]; @@ -103,12 +109,19 @@ typedef struct { int msgout_pos; int is_msgout; - int dma_mode, cur_bus, bus_in, new_phase; - int state, clear_req, wait_data, wait_complete; - int command_pos, data_pos; + int dma_mode; + int cur_bus; + int bus_in; + int new_phase; + int state; + int clear_req; + int wait_data; + int wait_complete; + int command_pos; + int data_pos; } ncr_t; -typedef struct { +typedef struct t128_t { uint8_t ctrl; uint8_t status; uint8_t buffer[512]; @@ -121,14 +134,15 @@ typedef struct { int bios_enabled; } t128_t; -typedef struct { +typedef struct ncr5380_t { ncr_t ncr; t128_t t128; const char *name; uint8_t buffer[128]; - uint8_t int_ram[0x40], ext_ram[0x600]; + uint8_t int_ram[0x40]; + uint8_t ext_ram[0x600]; uint32_t rom_addr; uint16_t base; @@ -314,9 +328,9 @@ get_bus_host(ncr_t *ncr) static void ncr_bus_read(ncr5380_t *ncr_dev) { - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev; - int phase; + ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev; + int phase; /*Wait processes to handle bus requests*/ if (ncr->clear_req) { @@ -440,7 +454,9 @@ ncr_bus_update(void *priv, int bus) if (ncr->command_pos == cmd_len[(ncr->command[0] >> 5) & 7]) { if (ncr->is_msgout) { ncr->is_msgout = 0; - // ncr->command[1] = (ncr->command[1] & 0x1f) | (ncr->msglun << 5); +#if 0 + ncr->command[1] = (ncr->command[1] & 0x1f) | (ncr->msglun << 5); +#endif } /*Reset data position to default*/ @@ -565,6 +581,9 @@ ncr_bus_update(void *priv, int bus) SET_BUS_STATE(ncr, SCSI_PHASE_COMMAND); } break; + + default: + break; } ncr->bus_in = bus; @@ -573,10 +592,10 @@ ncr_bus_update(void *priv, int bus) static void ncr_write(uint16_t port, uint8_t val, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; - int bus_host = 0; + ncr5380_t *ncr_dev = (ncr5380_t *) priv; + ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; + int bus_host = 0; ncr_log("NCR5380 write(%04x,%02x)\n", port & 7, val); @@ -823,17 +842,17 @@ ncr_read(uint16_t port, void *priv) ncr_log("NCR5380 read(%04x)=%02x\n", port & 7, ret); - return (ret); + return ret; } /* Memory-mapped I/O READ handler. */ static uint8_t memio_read(uint32_t addr, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; - uint8_t ret = 0xff; + ncr5380_t *ncr_dev = (ncr5380_t *) priv; + ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; + uint8_t ret = 0xff; addr &= 0x3fff; @@ -899,8 +918,14 @@ memio_read(uint32_t addr, void *priv) case 0x3983: ret = 0xff; break; + + default: + break; } break; + + default: + break; } #if ENABLE_NCR5380_LOG @@ -915,9 +940,9 @@ memio_read(uint32_t addr, void *priv) static void memio_write(uint32_t addr, uint8_t val, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; + ncr5380_t *ncr_dev = (ncr5380_t *) priv; + ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; addr &= 0x3fff; @@ -976,8 +1001,14 @@ memio_write(uint32_t addr, uint8_t val, void *priv) ncr_dev->status_ctrl &= ~STATUS_BUFFER_NOT_READY; } break; + + default: + break; } break; + + default: + break; } } @@ -985,8 +1016,8 @@ memio_write(uint32_t addr, uint8_t val, void *priv) static uint8_t t130b_read(uint32_t addr, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - uint8_t ret = 0xff; + const ncr5380_t *ncr_dev = (ncr5380_t *) priv; + uint8_t ret = 0xff; addr &= 0x3fff; if (addr < 0x1800) @@ -995,7 +1026,7 @@ t130b_read(uint32_t addr, void *priv) ret = ncr_dev->ext_ram[addr & 0x7f]; ncr_log("MEM: Reading %02X from %08X\n", ret, addr); - return (ret); + return ret; } /* Memory-mapped I/O WRITE handler for the Trantor T130B. */ @@ -1039,10 +1070,13 @@ t130b_in(uint16_t port, void *priv) case 0x0f: ret = ncr_read(port, ncr_dev); break; + + default: + break; } ncr_log("I/O: Reading %02X from %04X\n", ret, port); - return (ret); + return ret; } static void @@ -1075,6 +1109,9 @@ t130b_out(uint16_t port, uint8_t val, void *priv) case 0x0f: ncr_write(port, val, ncr_dev); break; + + default: + break; } } @@ -1325,6 +1362,9 @@ ncr_callback(void *priv) } ncr_dma_initiator_receive(ncr_dev, ncr, dev); break; + + default: + break; } ncr_bus_read(ncr_dev); @@ -1341,7 +1381,7 @@ static uint8_t t128_read(uint32_t addr, void *priv) { ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; + const ncr_t *ncr = &ncr_dev->ncr; scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; uint8_t ret = 0xff; @@ -1381,9 +1421,9 @@ t128_read(uint32_t addr, void *priv) static void t128_write(uint32_t addr, uint8_t val, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; - ncr_t *ncr = &ncr_dev->ncr; - scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; + ncr5380_t *ncr_dev = (ncr5380_t *) priv; + const ncr_t *ncr = &ncr_dev->ncr; + const scsi_device_t *dev = &scsi_devices[ncr_dev->bus][ncr->target_id]; addr &= 0x3fff; if (addr >= 0x1800 && addr < 0x1880) @@ -1417,7 +1457,7 @@ t128_write(uint32_t addr, uint8_t val, void *priv) static uint8_t rt1000b_mc_read(int port, void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; + const ncr5380_t *ncr_dev = (ncr5380_t *) priv; return (ncr_dev->pos_regs[port & 7]); } @@ -1457,6 +1497,9 @@ rt1000b_mc_write(int port, uint8_t val, void *priv) case 0xe0: ncr_dev->rom_addr = 0xd8000; break; + + default: + break; } mem_mapping_set_addr(&ncr_dev->bios_rom.mapping, ncr_dev->rom_addr, 0x4000); @@ -1467,7 +1510,7 @@ rt1000b_mc_write(int port, uint8_t val, void *priv) static uint8_t rt1000b_mc_feedb(void *priv) { - ncr5380_t *ncr_dev = (ncr5380_t *) priv; + const ncr5380_t *ncr_dev = (ncr5380_t *) priv; return ncr_dev->pos_regs[2] & 1; } @@ -1475,9 +1518,9 @@ rt1000b_mc_feedb(void *priv) static void * ncr_init(const device_t *info) { - char *fn = NULL; - char temp[128]; - ncr5380_t *ncr_dev; + const char *fn = NULL; + char temp[128]; + ncr5380_t *ncr_dev; ncr_dev = malloc(sizeof(ncr5380_t)); memset(ncr_dev, 0x00, sizeof(ncr5380_t)); @@ -1577,6 +1620,9 @@ ncr_init(const device_t *info) memio_write, NULL, NULL, ncr_dev->bios_rom.rom, MEM_MAPPING_EXTERNAL, ncr_dev); break; + + default: + break; } sprintf(temp, "%s: BIOS=%05X", ncr_dev->name, ncr_dev->rom_addr); diff --git a/src/scsi/scsi_ncr53c8xx.c b/src/scsi/scsi_ncr53c8xx.c index 482e098e3..897f37d1d 100644 --- a/src/scsi/scsi_ncr53c8xx.c +++ b/src/scsi/scsi_ncr53c8xx.c @@ -204,7 +204,7 @@ typedef enum { SCSI_STATE_WRITE_MESSAGE } scsi_state_t; -typedef struct { +typedef struct ncr53c8xx_t { char *nvr_path; uint8_t pci_slot; uint8_t chip, wide; @@ -291,9 +291,16 @@ typedef struct { uint32_t dbc; uint32_t dsp; uint32_t dsps; - uint32_t scratcha, scratchb, scratchc, scratchd; - uint32_t scratche, scratchf, scratchg, scratchh; - uint32_t scratchi, scratchj; + uint32_t scratcha; + uint32_t scratchb; + uint32_t scratchc; + uint32_t scratchd; + uint32_t scratche; + uint32_t scratchf; + uint32_t scratchg; + uint32_t scratchh; + uint32_t scratchi; + uint32_t scratchj; int last_level; void *hba_private; uint32_t buffer_pos; @@ -479,7 +486,7 @@ ncr53c8xx_write(ncr53c8xx_t *dev, uint32_t addr, uint8_t *buf, uint32_t len) } static __inline uint32_t -read_dword(ncr53c8xx_t *dev, uint32_t addr) +read_dword(UNUSED(ncr53c8xx_t *dev), uint32_t addr) { uint32_t buf; ncr53c8xx_log("Reading the next DWORD from memory (%08X)...\n", addr); @@ -578,7 +585,7 @@ ncr53c8xx_set_phase(ncr53c8xx_t *dev, int phase) } static void -ncr53c8xx_bad_phase(ncr53c8xx_t *dev, int out, int new_phase) +ncr53c8xx_bad_phase(ncr53c8xx_t *dev, UNUSED(int out), int new_phase) { /* Trigger a phase mismatch. */ ncr53c8xx_log("Phase mismatch interrupt\n"); @@ -603,7 +610,7 @@ ncr53c8xx_disconnect(ncr53c8xx_t *dev) } static void -ncr53c8xx_bad_selection(ncr53c8xx_t *dev, uint32_t id) +ncr53c8xx_bad_selection(ncr53c8xx_t *dev, UNUSED(uint32_t id)) { ncr53c8xx_log("Selected absent target %d\n", id); ncr53c8xx_script_scsi_interrupt(dev, 0, NCR_SIST1_STO); @@ -863,7 +870,7 @@ ncr53c8xx_skip_msgbytes(ncr53c8xx_t *dev, unsigned int n) } static void -ncr53c8xx_bad_message(ncr53c8xx_t *dev, uint8_t msg) +ncr53c8xx_bad_message(ncr53c8xx_t *dev, UNUSED(uint8_t msg)) { ncr53c8xx_log("Unimplemented message 0x%02x\n", msg); ncr53c8xx_set_phase(dev, PHASE_MI); @@ -1191,6 +1198,9 @@ again: if (insn & (1 << 10)) dev->carry = 0; break; + + default: + break; } } else { reg = ((insn >> 16) & 0x7f) | (insn & 0x80); @@ -1216,6 +1226,9 @@ again: else op1 = data8; break; + + default: + break; } switch (operator) { @@ -1252,6 +1265,9 @@ again: else dev->carry = op0 < op1; break; + + default: + break; } switch (opcode) { @@ -1262,6 +1278,9 @@ again: case 6: /* To SFBR */ dev->sfbr = op0; break; + + default: + break; } } break; @@ -1403,9 +1422,9 @@ ncr53c8xx_execute_script(ncr53c8xx_t *dev) } static void -ncr53c8xx_callback(void *p) +ncr53c8xx_callback(void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; if (!dev->sstop) { if (dev->waiting) @@ -1559,7 +1578,9 @@ ncr53c8xx_reg_writeb(ncr53c8xx_t *dev, uint32_t offset, uint8_t val) ncr53c8xx_log("Woken by SIGP\n"); dev->waiting = 0; dev->dsp = dev->dnad; - /* ncr53c8xx_execute_script(dev); */ +#if 0 + ncr53c8xx_execute_script(dev); +#endif } if ((val & NCR_ISTAT_SRST) && !(tmp & NCR_ISTAT_SRST)) { ncr53c8xx_soft_reset(dev); @@ -1978,6 +1999,9 @@ ncr53c8xx_reg_readb(ncr53c8xx_t *dev, uint32_t offset) CASE_GET_REG32_COND(scratchh, 0x74) CASE_GET_REG32_COND(scratchi, 0x78) CASE_GET_REG32_COND(scratchj, 0x7c) + + default: + break; } ncr53c8xx_log("readb 0x%x\n", offset); return 0; @@ -1987,16 +2011,17 @@ ncr53c8xx_reg_readb(ncr53c8xx_t *dev, uint32_t offset) } static uint8_t -ncr53c8xx_io_readb(uint16_t addr, void *p) +ncr53c8xx_io_readb(uint16_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; + return ncr53c8xx_reg_readb(dev, addr & 0xff); } static uint16_t -ncr53c8xx_io_readw(uint16_t addr, void *p) +ncr53c8xx_io_readw(uint16_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint16_t val; addr &= 0xff; @@ -2006,9 +2031,9 @@ ncr53c8xx_io_readw(uint16_t addr, void *p) } static uint32_t -ncr53c8xx_io_readl(uint16_t addr, void *p) +ncr53c8xx_io_readl(uint16_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint32_t val; addr &= 0xff; @@ -2020,25 +2045,28 @@ ncr53c8xx_io_readl(uint16_t addr, void *p) } static void -ncr53c8xx_io_writeb(uint16_t addr, uint8_t val, void *p) +ncr53c8xx_io_writeb(uint16_t addr, uint8_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; + ncr53c8xx_reg_writeb(dev, addr & 0xff, val); } static void -ncr53c8xx_io_writew(uint16_t addr, uint16_t val, void *p) +ncr53c8xx_io_writew(uint16_t addr, uint16_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; + addr &= 0xff; ncr53c8xx_reg_writeb(dev, addr, val & 0xff); ncr53c8xx_reg_writeb(dev, addr + 1, (val >> 8) & 0xff); } static void -ncr53c8xx_io_writel(uint16_t addr, uint32_t val, void *p) +ncr53c8xx_io_writel(uint16_t addr, uint32_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; + addr &= 0xff; ncr53c8xx_reg_writeb(dev, addr, val & 0xff); ncr53c8xx_reg_writeb(dev, addr + 1, (val >> 8) & 0xff); @@ -2047,17 +2075,17 @@ ncr53c8xx_io_writel(uint16_t addr, uint32_t val, void *p) } static void -ncr53c8xx_mmio_writeb(uint32_t addr, uint8_t val, void *p) +ncr53c8xx_mmio_writeb(uint32_t addr, uint8_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; ncr53c8xx_reg_writeb(dev, addr & 0xff, val); } static void -ncr53c8xx_mmio_writew(uint32_t addr, uint16_t val, void *p) +ncr53c8xx_mmio_writew(uint32_t addr, uint16_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; addr &= 0xff; ncr53c8xx_reg_writeb(dev, addr, val & 0xff); @@ -2065,9 +2093,9 @@ ncr53c8xx_mmio_writew(uint32_t addr, uint16_t val, void *p) } static void -ncr53c8xx_mmio_writel(uint32_t addr, uint32_t val, void *p) +ncr53c8xx_mmio_writel(uint32_t addr, uint32_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; addr &= 0xff; ncr53c8xx_reg_writeb(dev, addr, val & 0xff); @@ -2077,17 +2105,17 @@ ncr53c8xx_mmio_writel(uint32_t addr, uint32_t val, void *p) } static uint8_t -ncr53c8xx_mmio_readb(uint32_t addr, void *p) +ncr53c8xx_mmio_readb(uint32_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; return ncr53c8xx_reg_readb(dev, addr & 0xff); } static uint16_t -ncr53c8xx_mmio_readw(uint32_t addr, void *p) +ncr53c8xx_mmio_readw(uint32_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint16_t val; addr &= 0xff; @@ -2097,9 +2125,9 @@ ncr53c8xx_mmio_readw(uint32_t addr, void *p) } static uint32_t -ncr53c8xx_mmio_readl(uint32_t addr, void *p) +ncr53c8xx_mmio_readl(uint32_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint32_t val; addr &= 0xff; @@ -2112,57 +2140,57 @@ ncr53c8xx_mmio_readl(uint32_t addr, void *p) } static void -ncr53c8xx_ram_writeb(uint32_t addr, uint8_t val, void *p) +ncr53c8xx_ram_writeb(uint32_t addr, uint8_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; dev->ram[addr & 0x0fff] = val; } static void -ncr53c8xx_ram_writew(uint32_t addr, uint16_t val, void *p) +ncr53c8xx_ram_writew(uint32_t addr, uint16_t val, void *priv) { - ncr53c8xx_ram_writeb(addr, val & 0xff, p); - ncr53c8xx_ram_writeb(addr + 1, (val >> 8) & 0xff, p); + ncr53c8xx_ram_writeb(addr, val & 0xff, priv); + ncr53c8xx_ram_writeb(addr + 1, (val >> 8) & 0xff, priv); } static void -ncr53c8xx_ram_writel(uint32_t addr, uint32_t val, void *p) +ncr53c8xx_ram_writel(uint32_t addr, uint32_t val, void *priv) { - ncr53c8xx_ram_writeb(addr, val & 0xff, p); - ncr53c8xx_ram_writeb(addr + 1, (val >> 8) & 0xff, p); - ncr53c8xx_ram_writeb(addr + 2, (val >> 16) & 0xff, p); - ncr53c8xx_ram_writeb(addr + 3, (val >> 24) & 0xff, p); + ncr53c8xx_ram_writeb(addr, val & 0xff, priv); + ncr53c8xx_ram_writeb(addr + 1, (val >> 8) & 0xff, priv); + ncr53c8xx_ram_writeb(addr + 2, (val >> 16) & 0xff, priv); + ncr53c8xx_ram_writeb(addr + 3, (val >> 24) & 0xff, priv); } static uint8_t -ncr53c8xx_ram_readb(uint32_t addr, void *p) +ncr53c8xx_ram_readb(uint32_t addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + const ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; return dev->ram[addr & 0x0fff]; } static uint16_t -ncr53c8xx_ram_readw(uint32_t addr, void *p) +ncr53c8xx_ram_readw(uint32_t addr, void *priv) { uint16_t val; - val = ncr53c8xx_ram_readb(addr, p); - val |= ncr53c8xx_ram_readb(addr + 1, p) << 8; + val = ncr53c8xx_ram_readb(addr, priv); + val |= ncr53c8xx_ram_readb(addr + 1, priv) << 8; return val; } static uint32_t -ncr53c8xx_ram_readl(uint32_t addr, void *p) +ncr53c8xx_ram_readl(uint32_t addr, void *priv) { uint32_t val; - val = ncr53c8xx_ram_readb(addr, p); - val |= ncr53c8xx_ram_readb(addr + 1, p) << 8; - val |= ncr53c8xx_ram_readb(addr + 2, p) << 16; - val |= ncr53c8xx_ram_readb(addr + 3, p) << 24; + val = ncr53c8xx_ram_readb(addr, priv); + val |= ncr53c8xx_ram_readb(addr + 1, priv) << 8; + val |= ncr53c8xx_ram_readb(addr + 2, priv) << 16; + val |= ncr53c8xx_ram_readb(addr + 3, priv) << 24; return val; } @@ -2246,9 +2274,9 @@ uint8_t ncr53c8xx_pci_regs[256]; bar_t ncr53c8xx_pci_bar[4]; static uint8_t -ncr53c8xx_pci_read(int func, int addr, void *p) +ncr53c8xx_pci_read(UNUSED(int func), int addr, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; ncr53c8xx_log("NCR53c8xx: Reading register %02X\n", addr & 0xff); @@ -2341,15 +2369,18 @@ ncr53c8xx_pci_read(int func, int addr, void *p) return 0x11; case 0x3F: return 0x40; + + default: + break; } return 0; } static void -ncr53c8xx_pci_write(int func, int addr, uint8_t val, void *p) +ncr53c8xx_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - ncr53c8xx_t *dev = (ncr53c8xx_t *) p; + ncr53c8xx_t *dev = (ncr53c8xx_t *) priv; uint8_t valxor; ncr53c8xx_log("NCR53c8xx: Write value %02X to register %02X\n", val, addr & 0xff); @@ -2479,6 +2510,9 @@ ncr53c8xx_pci_write(int func, int addr, uint8_t val, void *p) ncr53c8xx_pci_regs[addr] = val; dev->irq = val; return; + + default: + break; } } diff --git a/src/scsi/scsi_pcscsi.c b/src/scsi/scsi_pcscsi.c index c0244ed4f..7fa359396 100644 --- a/src/scsi/scsi_pcscsi.c +++ b/src/scsi/scsi_pcscsi.c @@ -149,7 +149,7 @@ #define SBAC_STATUS (1 << 24) #define SBAC_PABTEN (1 << 25) -typedef struct { +typedef struct esp_t { mem_mapping_t mmio_mapping; mem_mapping_t ram_mapping; char *nvr_path; @@ -188,10 +188,10 @@ typedef struct { int mca; uint16_t Base; - uint8_t HostID, DmaChannel; + uint8_t HostID; + uint8_t DmaChannel; - struct - { + struct { uint8_t mode; uint8_t status; int pos; @@ -952,9 +952,9 @@ esp_write_response(esp_t *dev) } static void -esp_callback(void *p) +esp_callback(void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; if (dev->dma_enabled || dev->do_cmd || ((dev->rregs[ESP_CMD] & CMD_CMD) == CMD_PAD)) { if ((dev->rregs[ESP_CMD] & CMD_CMD) == CMD_TI) { @@ -1029,7 +1029,9 @@ esp_reg_write(esp_t *dev, uint32_t saddr, uint32_t val) switch (saddr) { case ESP_TCHI: dev->tchi_written = 1; - /* fall through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case ESP_TCLO: case ESP_TCMID: esp_log("Transfer count regs %02x = %i\n", saddr, val); @@ -1134,6 +1136,9 @@ esp_reg_write(esp_t *dev, uint32_t saddr, uint32_t val) esp_log("ESP Disable Selection\n"); esp_raise_irq(dev); break; + + default: + break; } break; case ESP_WBUSID: @@ -1259,6 +1264,9 @@ esp_pci_dma_write(esp_t *dev, uint16_t saddr, uint32_t val) dev->dma_regs[DMA_STAT] &= ~(val & mask); } break; + + default: + break; } } @@ -1361,44 +1369,49 @@ esp_io_pci_write(esp_t *dev, uint32_t addr, uint32_t val, unsigned int size) } static void -esp_pci_io_writeb(uint16_t addr, uint8_t val, void *p) +esp_pci_io_writeb(uint16_t addr, uint8_t val, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + esp_io_pci_write(dev, addr, val, 1); } static void -esp_pci_io_writew(uint16_t addr, uint16_t val, void *p) +esp_pci_io_writew(uint16_t addr, uint16_t val, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + esp_io_pci_write(dev, addr, val, 2); } static void -esp_pci_io_writel(uint16_t addr, uint32_t val, void *p) +esp_pci_io_writel(uint16_t addr, uint32_t val, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; esp_io_pci_write(dev, addr, val, 4); } static uint8_t -esp_pci_io_readb(uint16_t addr, void *p) +esp_pci_io_readb(uint16_t addr, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + return esp_io_pci_read(dev, addr, 1); } static uint16_t -esp_pci_io_readw(uint16_t addr, void *p) +esp_pci_io_readw(uint16_t addr, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + return esp_io_pci_read(dev, addr, 2); } static uint32_t -esp_pci_io_readl(uint16_t addr, void *p) +esp_pci_io_readl(uint16_t addr, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; + return esp_io_pci_read(dev, addr, 4); } @@ -1549,6 +1562,9 @@ dc390_write_eeprom(esp_t *dev, int ena, int clk, int dat) esp_log("EEPROM Write enable command\n"); eeprom->wp = 0; break; + + default: + break; } } else { esp_log("EEPROM Read, write or erase word\n"); @@ -1622,9 +1638,9 @@ uint8_t esp_pci_regs[256]; bar_t esp_pci_bar[2]; static uint8_t -esp_pci_read(int func, int addr, void *p) +esp_pci_read(UNUSED(int func), int addr, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; // esp_log("ESP PCI: Reading register %02X\n", addr & 0xff); @@ -1695,15 +1711,18 @@ esp_pci_read(int func, int addr, void *p) case 0x40 ... 0x4f: return esp_pci_regs[addr]; + + default: + break; } return 0; } static void -esp_pci_write(int func, int addr, uint8_t val, void *p) +esp_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - esp_t *dev = (esp_t *) p; + esp_t *dev = (esp_t *) priv; uint8_t valxor; int eesk; int eedi; @@ -1799,11 +1818,14 @@ esp_pci_write(int func, int addr, uint8_t val, void *p) case 0x40 ... 0x4f: esp_pci_regs[addr] = val; return; + + default: + break; } } static void * -dc390_init(const device_t *info) +dc390_init(UNUSED(const device_t *info)) { esp_t *dev; @@ -1872,6 +1894,9 @@ ncr53c90_in(uint16_t port, void *priv) case 0x0c: ret = dev->dma_86c01.status; break; + + default: + break; } } @@ -1926,7 +1951,7 @@ ncr53c90_outw(uint16_t port, uint16_t val, void *priv) static uint8_t ncr53c90_mca_read(int port, void *priv) { - esp_t *dev = (esp_t *) priv; + const esp_t *dev = (esp_t *) priv; return (dev->pos_regs[port & 7]); } @@ -1989,13 +2014,13 @@ ncr53c90_mca_write(int port, uint8_t val, void *priv) static uint8_t ncr53c90_mca_feedb(void *priv) { - esp_t *dev = (esp_t *) priv; + const esp_t *dev = (esp_t *) priv; return (dev->pos_regs[2] & 0x01); } static void * -ncr53c90_mca_init(const device_t *info) +ncr53c90_mca_init(UNUSED(const device_t *info)) { esp_t *dev; diff --git a/src/scsi/scsi_spock.c b/src/scsi/scsi_spock.c index cddf15740..3b9f5108c 100644 --- a/src/scsi/scsi_spock.c +++ b/src/scsi/scsi_spock.c @@ -286,9 +286,9 @@ spock_add_to_period(spock_t *scsi, int TransferLength) } static void -spock_write(uint16_t port, uint8_t val, void *p) +spock_write(uint16_t port, uint8_t val, void *priv) { - spock_t *scsi = (spock_t *) p; + spock_t *scsi = (spock_t *) priv; spock_log("spock_write: port=%04x val=%02x %04x:%04x\n", port, val, CS, cpu_state.pc); @@ -320,13 +320,16 @@ spock_write(uint16_t port, uint8_t val, void *p) scsi->basic_ctrl = val; spock_rethink_irqs(scsi); break; + + default: + break; } } static void -spock_writew(uint16_t port, uint16_t val, void *p) +spock_writew(uint16_t port, uint16_t val, void *priv) { - spock_t *scsi = (spock_t *) p; + spock_t *scsi = (spock_t *) priv; switch (port & 7) { case 0: /*Command Interface Register*/ @@ -339,15 +342,18 @@ spock_writew(uint16_t port, uint16_t val, void *p) scsi->cir_pending[3] = val >> 8; scsi->cir_status |= 2; break; + + default: + break; } spock_log("spock_writew: port=%04x val=%04x\n", port, val); } static uint8_t -spock_read(uint16_t port, void *p) +spock_read(uint16_t port, void *priv) { - spock_t *scsi = (spock_t *) p; + const spock_t *scsi = (spock_t *) priv; uint8_t temp = 0xff; switch (port & 7) { @@ -378,6 +384,9 @@ spock_read(uint16_t port, void *p) temp |= STATUS_CMD_FULL; } break; + + default: + break; } spock_log("spock_read: port=%04x val=%02x %04x(%05x):%04x.\n", port, temp, CS, cs, cpu_state.pc); @@ -385,10 +394,10 @@ spock_read(uint16_t port, void *p) } static uint16_t -spock_readw(uint16_t port, void *p) +spock_readw(uint16_t port, void *priv) { - spock_t *scsi = (spock_t *) p; - uint16_t temp = 0xffff; + const spock_t *scsi = (spock_t *) priv; + uint16_t temp = 0xffff; switch (port & 7) { case 0: /*Command Interface Register*/ @@ -397,6 +406,9 @@ spock_readw(uint16_t port, void *p) case 2: /*Command Interface Register*/ temp = scsi->cir_pending[2] | (scsi->cir_pending[3] << 8); break; + + default: + break; } spock_log("spock_readw: port=%04x val=%04x\n", port, temp); @@ -797,6 +809,9 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) scsi->scsi_state = SCSI_STATE_SELECT; scsi->scb_state = 2; return; + + default: + break; } break; @@ -843,6 +858,9 @@ spock_execute_cmd(spock_t *scsi, scb_t *scb) spock_log("Complete SCB ID = %d.\n", scsi->attention & 0x0f); } break; + + default: + break; } } while (scsi->scb_state != old_scb_state); } @@ -1000,6 +1018,9 @@ spock_callback(void *priv) case CMD_RESET: spock_process_imm_cmd(scsi); break; + + default: + break; } break; @@ -1024,6 +1045,9 @@ spock_callback(void *priv) scsi->irq_status = 0; spock_clear_irq(scsi, scsi->attention & 0x0f); break; + + default: + break; } } } @@ -1062,7 +1086,7 @@ spock_mca_write(int port, uint8_t val, void *priv) static uint8_t spock_mca_read(int port, void *priv) { - spock_t *scsi = (spock_t *) priv; + const spock_t *scsi = (spock_t *) priv; return scsi->pos_regs[port & 7]; } @@ -1070,7 +1094,7 @@ spock_mca_read(int port, void *priv) static uint8_t spock_mca_feedb(void *priv) { - spock_t *scsi = (spock_t *) priv; + const spock_t *scsi = (spock_t *) priv; return (scsi->pos_regs[2] & 0x01); } @@ -1097,7 +1121,7 @@ spock_mca_reset(void *priv) } static void * -spock_init(const device_t *info) +spock_init(UNUSED(const device_t *info)) { spock_t *scsi = malloc(sizeof(spock_t)); memset(scsi, 0x00, sizeof(spock_t)); @@ -1117,6 +1141,9 @@ spock_init(const device_t *info) rom_init_interleaved(&scsi->bios_rom, SPOCK_U68_1990_ROM, SPOCK_U69_1990_ROM, 0xc8000, 0x8000, 0x7fff, 0x4000, MEM_MAPPING_EXTERNAL); break; + + default: + break; } mem_mapping_disable(&scsi->bios_rom.mapping); @@ -1142,9 +1169,9 @@ spock_init(const device_t *info) } static void -spock_close(void *p) +spock_close(void *priv) { - spock_t *scsi = (spock_t *) p; + spock_t *scsi = (spock_t *) priv; if (scsi) { free(scsi); diff --git a/src/scsi/scsi_x54x.c b/src/scsi/scsi_x54x.c index b379f322c..7a6923def 100644 --- a/src/scsi/scsi_x54x.c +++ b/src/scsi/scsi_x54x.c @@ -238,6 +238,9 @@ completion_code(uint8_t *sense) case ASC_MEDIUM_NOT_PRESENT: ret = 0xaa; break; + + default: + break; } return ret; @@ -483,6 +486,9 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) default: x54x_log("BIOS: Unimplemented command: %02X\n", cmd->command); +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x05: /* Format Track, invalid since SCSI has no tracks */ case 0x0a: /* ???? */ case 0x0b: /* ???? */ @@ -583,8 +589,8 @@ x54x_mbi_setup(x54x_t *dev, uint32_t CCBPointer, CCBU *CmdBlock, static void x54x_ccb(x54x_t *dev) { - Req_t *req = &dev->Req; - uint8_t bytes[4] = { 0, 0, 0, 0 }; + const Req_t *req = &dev->Req; + uint8_t bytes[4] = { 0, 0, 0, 0 }; /* Rewrite the CCB up to the CDB. */ x54x_log("CCB completion code and statuses rewritten (pointer %08X)\n", req->CCBPointer); @@ -605,7 +611,9 @@ static void x54x_mbi(x54x_t *dev) { Req_t *req = &dev->Req; - // uint32_t CCBPointer = req->CCBPointer; +#if 0 + uint32_t CCBPointer = req->CCBPointer; +#endif addr24_t CCBPointer; CCBU *CmdBlock = &(req->CmdBlock); uint8_t HostStatus = req->HostStatus; @@ -1017,7 +1025,7 @@ x54x_mbo_free(x54x_t *dev) static void x54x_notify(x54x_t *dev) { - Req_t *req = &dev->Req; + const Req_t *req = &dev->Req; scsi_device_t *sd; sd = &scsi_devices[dev->bus][req->TargetID]; @@ -1035,7 +1043,7 @@ x54x_notify(x54x_t *dev) } static void -x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) +x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, UNUSED(Mailbox32_t *Mailbox32)) { Req_t *req = &dev->Req; uint8_t id; @@ -1161,9 +1169,11 @@ x54x_mbo_process(x54x_t *dev) } else if (!dev->MailboxIsBIOS && (mb32.u.out.ActionCode == MBO_ABORT)) { x54x_log("Abort Mailbox Command\n"); x54x_req_abort(dev, mb32.CCBPointer); - } /* else { +#if 0 + } else { x54x_log("Invalid action code: %02X\n", mb32.u.out.ActionCode); - } */ +#endif + } if ((mb32.u.out.ActionCode == MBO_START) || (!dev->MailboxIsBIOS && (mb32.u.out.ActionCode == MBO_ABORT))) { /* We got the mailbox, decrease the number of pending requests. */ @@ -1282,7 +1292,9 @@ x54x_cmd_callback(void *priv) period = (1000000.0 / dev->ha_bps) * ((double) dev->temp_period); timer_on(&dev->timer, dev->media_period + period + 10.0, 0); - // x54x_log("Temporary period: %lf us (%" PRIi64 " periods)\n", dev->timer.period, dev->temp_period); +#if 0 + x54x_log("Temporary period: %lf us (%" PRIi64 " periods)\n", dev->timer.period, dev->temp_period); +#endif } static uint8_t @@ -1292,8 +1304,8 @@ x54x_in(uint16_t port, void *priv) uint8_t ret; switch (port & 3) { - case 0: default: + case 0: ret = dev->Status; break; @@ -1329,8 +1341,8 @@ x54x_in(uint16_t port, void *priv) ret = dev->Geometry; else { switch (dev->Geometry) { - case 0: default: + case 0: ret = 'A'; break; case 1: diff --git a/src/sio/sio_82091aa.c b/src/sio/sio_82091aa.c index 800bf1b1a..346d2d435 100644 --- a/src/sio/sio_82091aa.c +++ b/src/sio/sio_82091aa.c @@ -142,7 +142,7 @@ i82091aa_write(uint16_t port, uint8_t val, void *priv) { i82091aa_t *dev = (i82091aa_t *) priv; uint8_t index; - uint8_t valxor; + uint8_t valxor = 0; uint8_t uart = (dev->cur_reg >> 4) - 0x03; uint8_t *reg = &(dev->regs[dev->cur_reg]); diff --git a/src/sound/midi.c b/src/sound/midi.c index 50ddaaeb4..1a9c24657 100644 --- a/src/sound/midi.c +++ b/src/sound/midi.c @@ -408,7 +408,7 @@ midi_clear_buffer(void) } void -midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int (*sysex)(void *p, uint8_t *buffer, uint32_t len, int abort), void *p) +midi_in_handler(int set, void (*msg)(void *priv, uint8_t *msg, uint32_t len), int (*sysex)(void *priv, uint8_t *buffer, uint32_t len, int abort), void *priv) { midi_in_handler_t *temp = NULL; midi_in_handler_t *next; @@ -425,7 +425,7 @@ midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int ( memset(temp, 0, sizeof(midi_in_handler_t)); temp->msg = msg; temp->sysex = sysex; - temp->p = p; + temp->priv = priv; if (mih_last == NULL) mih_first = mih_last = temp; @@ -440,7 +440,7 @@ midi_in_handler(int set, void (*msg)(void *p, uint8_t *msg, uint32_t len), int ( if (temp == NULL) break; - if ((temp->msg == msg) && (temp->sysex == sysex) && (temp->p == p)) { + if ((temp->msg == msg) && (temp->sysex == sysex) && (temp->priv == priv)) { if (temp->prev != NULL) temp->prev->next = temp->next; @@ -500,7 +500,7 @@ midi_in_msg(uint8_t *msg, uint32_t len) break; if (temp->msg) - temp->msg(temp->p, msg, len); + temp->msg(temp->priv, msg, len); temp = temp->next; @@ -548,9 +548,9 @@ midi_do_sysex(void) ret = 0; if (temp->sysex) { if (temp->cnt == 0) - ret = temp->sysex(temp->p, temp->buf, 0, 0); + ret = temp->sysex(temp->priv, temp->buf, 0, 0); else - ret = temp->sysex(temp->p, temp->buf, temp->len, 0); + ret = temp->sysex(temp->priv, temp->buf, temp->len, 0); } /* If count is 0 and length is 0, then this is just a finishing diff --git a/src/sound/midi_fluidsynth.c b/src/sound/midi_fluidsynth.c index efe8159fc..08aefe16c 100644 --- a/src/sound/midi_fluidsynth.c +++ b/src/sound/midi_fluidsynth.c @@ -17,6 +17,7 @@ # include <86box/midi.h> # include <86box/thread.h> # include <86box/sound.h> +# include <86box/plat_unused.h> # define RENDER_RATE 100 # define BUFFER_SEGMENTS 10 @@ -151,7 +152,7 @@ fluidsynth_sysex(uint8_t *data, unsigned int len) } void * -fluidsynth_init(const device_t *info) +fluidsynth_init(UNUSED(const device_t *info)) { fluidsynth_t *data = &fsdev; midi_device_t *dev; @@ -165,7 +166,7 @@ fluidsynth_init(const device_t *info) data->synth = new_fluid_synth(data->settings); - const char *sound_font = (char *) device_get_config_string("sound_font"); + const char *sound_font = device_get_config_string("sound_font"); # ifdef __unix__ if (!sound_font || sound_font[0] == 0) sound_font = (access("/usr/share/sounds/sf2/FluidR3_GM.sf2", F_OK) == 0 ? "/usr/share/sounds/sf2/FluidR3_GM.sf2" : @@ -286,9 +287,9 @@ fluidsynth_init(const device_t *info) } void -fluidsynth_close(void *p) +fluidsynth_close(void *priv) { - if (!p) + if (!priv) return; fluidsynth_t *data = &fsdev; diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index 230914d72..91d85e438 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -110,7 +110,7 @@ static mt32emu_context context = NULL; static int roms_present[2] = { -1, -1 }; mt32emu_return_code -mt32_check(const char *func, mt32emu_return_code ret, mt32emu_return_code expected) +mt32_check(UNUSED(const char *func), mt32emu_return_code ret, mt32emu_return_code expected) { if (ret != expected) { return 0; @@ -165,13 +165,13 @@ static int16_t *buffer_int16 = NULL; static int midi_pos = 0; static mt32emu_report_handler_version -get_mt32_report_handler_version(mt32emu_report_handler_i i) +get_mt32_report_handler_version(UNUSED(mt32emu_report_handler_i i)) { return MT32EMU_REPORT_HANDLER_VERSION_0; } static void -display_mt32_message(void *instance_data, const char *message) +display_mt32_message(UNUSED(void *instance_data), const char *message) { int sz = 0; char *ui_msg = NULL; @@ -209,7 +209,7 @@ mt32_poll(void) } static void -mt32_thread(void *param) +mt32_thread(UNUSED(void *param)) { int buf_pos = 0; int bsize = buf_size / BUFFER_SEGMENTS; @@ -321,33 +321,33 @@ mt32emu_init(char *control_rom, char *pcm_rom) } void * -mt32_old_init(const device_t *info) +mt32_old_init(UNUSED(const device_t *info)) { return mt32emu_init(MT32_OLD_CTRL_ROM, MT32_OLD_PCM_ROM); } void * -mt32_new_init(const device_t *info) +mt32_new_init(UNUSED(const device_t *info)) { return mt32emu_init(MT32_NEW_CTRL_ROM, MT32_NEW_PCM_ROM); } void * -cm32l_init(const device_t *info) +cm32l_init(UNUSED(const device_t *info)) { return mt32emu_init(CM32L_CTRL_ROM, CM32L_PCM_ROM); } void * -cm32ln_init(const device_t *info) +cm32ln_init(UNUSED(const device_t *info)) { return mt32emu_init(CM32LN_CTRL_ROM, CM32LN_PCM_ROM); } void -mt32_close(void *p) +mt32_close(void *priv) { - if (!p) + if (!priv) return; mt32_on = 0; diff --git a/src/sound/midi_rtmidi.cpp b/src/sound/midi_rtmidi.cpp index 354c7f61b..72df8fd32 100644 --- a/src/sound/midi_rtmidi.cpp +++ b/src/sound/midi_rtmidi.cpp @@ -35,6 +35,7 @@ extern "C" { #include <86box/midi_rtmidi.h> #include <86box/ini.h> #include <86box/config.h> +#include <86box/plat_unused.h> // Disable c99-designator to avoid the warnings in rtmidi_*_device #ifdef __clang__ @@ -50,7 +51,7 @@ static int midi_out_id = 0, midi_in_id = 0; static const int midi_lengths[8] = { 3, 3, 3, 3, 2, 2, 3, 1 }; int -rtmidi_write(uint8_t val) +rtmidi_write(UNUSED(uint8_t val)) { return 0; } @@ -70,7 +71,7 @@ rtmidi_play_sysex(uint8_t *sysex, unsigned int len) } void * -rtmidi_output_init(const device_t *info) +rtmidi_output_init(UNUSED(const device_t *info)) { midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t)); @@ -110,7 +111,7 @@ rtmidi_output_init(const device_t *info) } void -rtmidi_output_close(void *p) +rtmidi_output_close(UNUSED(void *priv)) { if (!midiout) return; @@ -144,7 +145,7 @@ rtmidi_out_get_dev_name(int num, char *s) } void -rtmidi_input_callback(double timeStamp, std::vector *message, void *userData) +rtmidi_input_callback(UNUSED(double timeStamp), std::vector *message, UNUSED(void *userData)) { if (message->front() == 0xF0) midi_in_sysex(message->data(), message->size()); @@ -153,7 +154,7 @@ rtmidi_input_callback(double timeStamp, std::vector *message, voi } void * -rtmidi_input_init(const device_t *info) +rtmidi_input_init(UNUSED(const device_t *info)) { midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t)); @@ -198,7 +199,7 @@ rtmidi_input_init(const device_t *info) } void -rtmidi_input_close(void *p) +rtmidi_input_close(UNUSED(void *priv)) { midiin->cancelCallback(); midiin->closePort(); diff --git a/src/sound/openal.c b/src/sound/openal.c index 8fe101d64..76656c66e 100644 --- a/src/sound/openal.c +++ b/src/sound/openal.c @@ -33,6 +33,7 @@ #include <86box/86box.h> #include <86box/midi.h> #include <86box/sound.h> +#include <86box/plat_unused.h> #define FREQ SOUND_FREQ #define BUFLEN SOUNDBUFLEN @@ -58,7 +59,7 @@ al_set_midi(int freq, int buf_size) void closeal(void); ALvoid -alutInit(ALint *argc, ALbyte **argv) +alutInit(UNUSED(ALint *argc), UNUSED(ALbyte **argv)) { /* Open device */ Device = alcOpenDevice((ALCchar *) ""); @@ -118,8 +119,8 @@ inital(void) int16_t *cd_buf_int16 = NULL; int16_t *midi_buf_int16 = NULL; - char *mdn; - int init_midi = 0; + const char *mdn; + int init_midi = 0; if (initialized) return; diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 7a3701c9f..929574dce 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -25,83 +25,91 @@ #include <86box/device.h> #include <86box/io.h> #include <86box/snd_ac97.h> +#include <86box/plat_fallthrough.h> static const struct { - const uint32_t vendor_id, min_rate, max_rate, misc_flags; /* definitions for misc_flags in snd_ac97.h */ - const uint16_t reset_flags, extid_flags, /* definitions in snd_ac97.h */ - powerdown_mask; /* bits [7:0] => register 26 bits [15:8]; bits [11:8] => register 2A bits [14:11] */ - const ac97_vendor_reg_t *vendor_regs; /* bits [11:8] of index are the page number if applicable (registers [60:6F]) */ - const device_t *device; + const device_t *device; + + /* Definitions for *_flags and vendor_regs in snd_ac97.h */ + uint32_t min_rate; + uint32_t max_rate; + uint32_t misc_flags; + uint16_t reset_flags; + uint16_t extid_flags; + uint8_t pcsr_mask; /* register 26 bits [15:8] */ + uint8_t eascr_mask; /* register 2A bits [14:11] */ + + const ac97_vendor_reg_t *vendor_regs; } ac97_codecs[] = { // clang-format off - [AC97_CODEC_AD1881] = { - .vendor_id = AC97_VENDOR_ID('A', 'D', 'S', 0x40), + { + .device = &ad1881_device, .min_rate = 7000, .max_rate = 48000, .misc_flags = AC97_MASTER_6B | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_POP | AC97_MS | AC97_LPBK, .reset_flags = (1 << AC97_3D_SHIFT), /* datasheet contradicts itself on AC97_HPOUT */ .extid_flags = AC97_VRA, - .powerdown_mask = 0x0bf, - .vendor_regs = (const ac97_vendor_reg_t[]) {{0x74, 0x0000, 0xff07}, {0x76, 0x0404, 0xdde5}, {0x78, 48000, 0x0000}, {0x7a, 48000, 0x0000}, {0}}, - .device = &ad1881_device + .pcsr_mask = 0xbf, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x74, 0x0000, 0xff07}, {0, 0x76, 0x0404, 0xdde5}, {0, 0x78, 48000, 0x0000}, {0, 0x7a, 48000, 0x0000}, {0}} }, - [AC97_CODEC_AK4540] = { - .vendor_id = AC97_VENDOR_ID('A', 'K', 'M', 0x00), + { + .device = &ak4540_device, .misc_flags = AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, - .powerdown_mask = 0x01f, - .device = &ak4540_device + .pcsr_mask = 0x1f }, - [AC97_CODEC_ALC100] = { - .vendor_id = AC97_VENDOR_ID('A', 'L', 'C', 0x20), + { + .device = &alc100_device, .misc_flags = AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_POP | AC97_MS | AC97_LPBK, .reset_flags = (22 << AC97_3D_SHIFT), .extid_flags = AC97_AMAP, - .powerdown_mask = 0x0bf, - .device = &alc100_device + .pcsr_mask = 0xbf }, - [AC97_CODEC_CS4297] = { - .vendor_id = AC97_VENDOR_ID('C', 'R', 'Y', 0x03), + { + .device = &cs4297_device, .misc_flags = AC97_MASTER_6B | AC97_AUXOUT | AC97_AUXOUT_6B | AC97_MONOOUT | AC97_MONOOUT_6B | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = AC97_HPOUT | AC97_DAC_18B | AC97_ADC_18B, .extid_flags = 0, - .powerdown_mask = 0x07f, - .vendor_regs = (const ac97_vendor_reg_t[]) {{0x5a, 0x0301, 0x0000}, {0}}, - .device = &cs4297_device + .pcsr_mask = 0x7f, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x5a, 0x0301, 0x0000}, {0}} }, - [AC97_CODEC_CS4297A] = { - .vendor_id = AC97_VENDOR_ID('C', 'R', 'Y', 0x11), + { + .device = &cs4297a_device, .misc_flags = AC97_MASTER_6B | AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = AC97_HPOUT | AC97_DAC_20B | AC97_ADC_18B | (6 << AC97_3D_SHIFT), .extid_flags = AC97_AMAP, - .powerdown_mask = 0x0ff, - .vendor_regs = (const ac97_vendor_reg_t[]) {{0x5e, 0x0000, 0x01b0}, {0x60, 0x0023, 0x0001}, {0x68, 0x0000, 0xdfff}, {0}}, - .device = &cs4297a_device + .pcsr_mask = 0xff, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x5e, 0x0000, 0x01b0}, {0, 0x60, 0x0023, 0x0001}, {0, 0x68, 0x0000, 0xdfff}, {0}} }, - [AC97_CODEC_STAC9708] = { - .vendor_id = AC97_VENDOR_ID(0x83, 0x84, 0x76, 0x08), + { + .device = &stac9708_device, .misc_flags = AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = (26 << AC97_3D_SHIFT) | AC97_DAC_18B | AC97_ADC_18B, .extid_flags = AC97_SDAC, - .powerdown_mask = 0x2ff, - .vendor_regs = (const ac97_vendor_reg_t []) {{0x6c, 0x0000, 0x0003}, {0x74, 0x0000, 0x0003}, {0}}, - .device = &stac9708_device + .pcsr_mask = 0xff, + .eascr_mask = 0x02, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x6c, 0x0000, 0x0003}, {0, 0x74, 0x0000, 0x0003}, {0}} }, - [AC97_CODEC_STAC9721] = { - .vendor_id = AC97_VENDOR_ID(0x83, 0x84, 0x76, 0x09), + { + .device = &stac9721_device, .misc_flags = AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = (26 << AC97_3D_SHIFT) | AC97_DAC_18B | AC97_ADC_18B, .extid_flags = AC97_AMAP, - .powerdown_mask = 0x0ff, - .vendor_regs = (const ac97_vendor_reg_t []) {{0x6c, 0x0000, 0x0000}, {0x6e, 0x0000, 0x0003}, {0x70, 0x0000, 0xffff}, {0x72, 0x0000, 0x0006}, {0x74, 0x0000, 0x0003}, {0x76, 0x0000, 0xffff}, {0x78, 0x0000, 0x3802}, {0}}, - .device = &stac9721_device + .pcsr_mask = 0xff, + .vendor_regs = (const ac97_vendor_reg_t[]) {{0, 0x6c, 0x0000, 0x0000}, {0, 0x6e, 0x0000, 0x0003}, {0, 0x70, 0x0000, 0xffff}, {0, 0x72, 0x0000, 0x0006}, {0, 0x74, 0x0000, 0x0003}, {0, 0x76, 0x0000, 0xffff}, {0, 0x78, 0x0000, 0x3802}, {0}} }, - [AC97_CODEC_WM9701A] = { - .vendor_id = AC97_VENDOR_ID('W', 'M', 'L', 0x00), + { + .device = &tr28023_device, + .misc_flags = AC97_MASTER_6B | AC97_MONOOUT | AC97_MONOOUT_6B | AC97_PCBEEP | AC97_PHONE | AC97_POP | AC97_MS | AC97_LPBK, + .reset_flags = 0, + .extid_flags = 0, + .pcsr_mask = 0x3f + }, + { + .device = &wm9701a_device, .misc_flags = AC97_AUXOUT | AC97_MONOOUT | AC97_PCBEEP | AC97_PHONE | AC97_VIDEO | AC97_AUXIN | AC97_MS | AC97_LPBK, .reset_flags = AC97_DAC_18B | AC97_ADC_18B, .extid_flags = 0, - .powerdown_mask = 0x03f, - .device = &wm9701a_device + .pcsr_mask = 0x3f } // clang-format on }; @@ -163,7 +171,7 @@ ac97_codec_writew(ac97_codec_t *dev, uint8_t reg, uint16_t val) ac97_codec_log("AC97 Codec %d: writew(%02X, %04X)\n", dev->codec_id, reg, val); reg &= 0x7e; - uint16_t i = 0; + uint16_t i = 0; uint16_t prev = dev->regs[reg >> 1]; int j; @@ -176,7 +184,7 @@ ac97_codec_writew(ac97_codec_t *dev, uint8_t reg, uint16_t val) val &= 0xbf3f; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_MASTER_6B)) { + if (!(ac97_codecs[dev->model].misc_flags & AC97_MASTER_6B)) { clamp_5b: if (val & 0x2000) val = (val & ~0x2000) | 0x1f00; @@ -187,41 +195,41 @@ clamp_5b_r: break; case 0x04: /* Aux Out Volume */ - if (!(dev->misc_flags & AC97_AUXOUT)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_AUXOUT)) return; val &= 0xbf3f; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_AUXOUT_6B)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_AUXOUT_6B)) goto clamp_5b; break; case 0x06: /* Mono Out Volume */ - if (!(dev->misc_flags & AC97_MONOOUT)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_MONOOUT)) return; val &= 0x803f; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_MONOOUT_6B)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_MONOOUT_6B)) goto clamp_5b_r; break; case 0x08: /* Master Tone Control */ - if (!(dev->reset_flags & AC97_TONECTL)) + if (!(ac97_codecs[dev->model].reset_flags & AC97_TONECTL)) return; val &= 0x0f0f; break; case 0x0a: /* PC Beep Volume */ - if (dev->misc_flags & AC97_PCBEEP) + if (ac97_codecs[dev->model].misc_flags & AC97_PCBEEP) i |= 0x801e; - if (dev->misc_flags & AC97_PCBEEP_GEN) + if (ac97_codecs[dev->model].misc_flags & AC97_PCBEEP_GEN) i |= 0x1fe0; val &= i; break; case 0x0c: /* Phone Volume */ - if (!(dev->misc_flags & AC97_PHONE)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_PHONE)) return; val &= 0x801f; break; @@ -238,12 +246,12 @@ line_gain: break; case 0x14: /* Video Volume */ - if (!(dev->misc_flags & AC97_VIDEO)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_VIDEO)) return; goto line_gain; case 0x16: /* Aux In Volume */ - if (!(dev->misc_flags & AC97_AUXIN)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_AUXIN)) return; goto line_gain; @@ -256,26 +264,26 @@ line_gain: break; case 0x1e: /* Record Gain Mic */ - if (!(dev->reset_flags & AC97_MICPCM)) + if (!(ac97_codecs[dev->model].reset_flags & AC97_MICPCM)) return; val &= 0x800f; break; case 0x20: /* General Purpose */ - i = AC97_MIX | (dev->misc_flags & (AC97_POP | AC97_MS | AC97_LPBK)); - if (dev->reset_flags >> AC97_3D_SHIFT) + i = AC97_MIX | (ac97_codecs[dev->model].misc_flags & (AC97_POP | AC97_MS | AC97_LPBK)); + if (ac97_codecs[dev->model].reset_flags >> AC97_3D_SHIFT) i |= AC97_3D; - if (dev->reset_flags & AC97_SIMSTEREO) + if (ac97_codecs[dev->model].reset_flags & AC97_SIMSTEREO) i |= AC97_ST; - if (dev->reset_flags & AC97_LOUDNESS) + if (ac97_codecs[dev->model].reset_flags & AC97_LOUDNESS) i |= AC97_LD; - if (dev->extid_flags & AC97_DRA) + if (ac97_codecs[dev->model].extid_flags & AC97_DRA) i |= AC97_DRSS_MASK; val &= i; break; - case 0x22: /* 3D Control */ - switch (dev->reset_flags >> AC97_3D_SHIFT) { + case 0x22: /* 3D Control */ + switch (ac97_codecs[dev->model].reset_flags >> AC97_3D_SHIFT) { case 1: /* Analog Devices */ case 6: /* Crystal */ val &= 0x000f; @@ -287,7 +295,7 @@ line_gain: case 26: /* SigmaTel */ i = 0x0003; - if (dev->extid_flags & AC97_SDAC) + if (ac97_codecs[dev->model].extid_flags & AC97_SDAC) i |= 0x000c; val &= i; break; @@ -298,13 +306,13 @@ line_gain: break; case 0x24: /* Audio Interrupt and Paging Mechanism */ - if ((dev->extid_flags & AC97_REV_MASK) < AC97_REV_2_3) + if ((ac97_codecs[dev->model].extid_flags & AC97_REV_MASK) < AC97_REV_2_3) return; val &= 0x000f; break; case 0x26: /* Powerdown Control/Status */ - i = dev->powerdown_mask << 8; + i = ac97_codecs[dev->model].pcsr_mask << 8; val = (val & i) | (prev & ~i); /* Update status bits to reflect powerdowns. */ @@ -314,16 +322,16 @@ line_gain: break; case 0x28: /* Extended Audio ID */ - if (dev->misc_flags & AC97_DSA) + if (ac97_codecs[dev->model].misc_flags & AC97_DSA) i |= 0x0030; val = (val & i) | (prev & ~i); break; case 0x2a: /* Extended Audio Status/Control */ - i = dev->extid_flags & (AC97_VRA | AC97_DRA | AC97_SPDIF | AC97_VRM); - if (dev->extid_flags & AC97_SPDIF) + i = ac97_codecs[dev->model].extid_flags & (AC97_VRA | AC97_DRA | AC97_SPDIF | AC97_VRM); + if (ac97_codecs[dev->model].extid_flags & AC97_SPDIF) i |= AC97_SPSA_MASK << AC97_SPSA_SHIFT; - i |= (dev->powerdown_mask << 3) & 0x7800; /* multichannel powerdowns */ + i |= (ac97_codecs[dev->model].eascr_mask << 11) & 0x7800; val = (val & i) | (prev & ~i); /* Reset DAC sample rates to 48 KHz (96 KHz with DRA) if VRA is being cleared. */ @@ -343,57 +351,57 @@ line_gain: case 0x32: /* PCM L/R ADC Rate */ rate: /* Writable only if VRA/VRM is set. */ i = (reg >= 0x32) ? AC97_VRM : AC97_VRA; - if (!(dev->extid_flags & i)) + if (!(ac97_codecs[dev->model].extid_flags & i)) return; /* Limit to supported sample rate range. */ - if (val < dev->min_rate) - val = dev->min_rate; - else if (val > dev->max_rate) - val = dev->max_rate; + if (val < ac97_codecs[dev->model].min_rate) + val = ac97_codecs[dev->model].min_rate; + else if (val > ac97_codecs[dev->model].max_rate) + val = ac97_codecs[dev->model].max_rate; break; case 0x2e: /* PCM Surround DAC Rate */ - if (!(dev->extid_flags & AC97_SDAC)) + if (!(ac97_codecs[dev->model].extid_flags & AC97_SDAC)) return; goto rate; case 0x30: /* PCM LFE DAC Rate */ - if (!(dev->extid_flags & AC97_LDAC)) + if (!(ac97_codecs[dev->model].extid_flags & AC97_LDAC)) return; goto rate; case 0x34: /* Mic ADC Rate */ - if (!(dev->reset_flags & AC97_MICPCM)) + if (!(ac97_codecs[dev->model].reset_flags & AC97_MICPCM)) return; goto rate; case 0x36: /* Center/LFE Volume */ - if (dev->extid_flags & AC97_LDAC) + if (ac97_codecs[dev->model].extid_flags & AC97_LDAC) i |= 0xbf00; - if (dev->extid_flags & AC97_CDAC) + if (ac97_codecs[dev->model].extid_flags & AC97_CDAC) i |= 0x00bf; val &= i; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_LFE_6B) && (val & 0x2000)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_LFE_6B) && (val & 0x2000)) val = (val & ~0x2000) | 0x1f00; - if (!(dev->misc_flags & AC97_CENTER_6B)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_CENTER_6B)) goto clamp_5b_r; break; case 0x38: /* Surround Volume */ - if (!(dev->extid_flags & AC97_SDAC)) + if (!(ac97_codecs[dev->model].extid_flags & AC97_SDAC)) return; val &= 0xbfbf; /* Convert 1xxxxx to 011111 where unsupported, per specification. */ - if (!(dev->misc_flags & AC97_SURR_6B)) + if (!(ac97_codecs[dev->model].misc_flags & AC97_SURR_6B)) goto clamp_5b; break; case 0x3a: /* S/PDIF Control */ - if (!(dev->extid_flags & AC97_SPDIF)) + if (!(ac97_codecs[dev->model].extid_flags & AC97_SPDIF)) return; break; @@ -410,32 +418,30 @@ rate: /* Writable only if VRA/VRM is set. */ /* Get actual previous value. */ prev = dev->vendor_reg_pages[(i << 3) | ((reg & 0x0e) >> 1)]; } - - i <<= 8; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x5a ... 0x5e: /* Vendor Reserved */ case 0x70 ... 0x7a: /* Stop if no vendor-specific registers are defined. */ - if (!dev->vendor_regs) + if (!ac97_codecs[dev->model].vendor_regs) return; /* Look for a matching vendor-specific register. */ - i |= reg; - for (j = 0; dev->vendor_regs[j].index; j++) { + for (j = 0; ac97_codecs[dev->model].vendor_regs[j].index; j++) { /* If a match was found, inject written bits. */ - if (dev->vendor_regs[j].index == i) { - val = (val & dev->vendor_regs[j].write_mask) | (prev & ~dev->vendor_regs[j].write_mask); + if ((ac97_codecs[dev->model].vendor_regs[j].page == i) && (ac97_codecs[dev->model].vendor_regs[j].index == reg)) { + val = (val & ac97_codecs[dev->model].vendor_regs[j].write_mask) | (prev & ~ac97_codecs[dev->model].vendor_regs[j].write_mask); break; } } /* No match found. */ - if (!dev->vendor_regs[j].index) + if (!ac97_codecs[dev->model].vendor_regs[j].index) return; /* Redirect a write to page 1+ to the right array, part 2. */ - i >>= 8; if (i > 0) { dev->vendor_reg_pages[(i << 3) | ((reg & 0x0e) >> 1)] = val; return; @@ -465,52 +471,51 @@ ac97_codec_reset(void *priv) /* Set default level and gain values. */ dev->regs[0x02 >> 1] = AC97_MUTE; - if (dev->misc_flags & AC97_AUXOUT) + if (ac97_codecs[dev->model].misc_flags & AC97_AUXOUT) dev->regs[0x04 >> 1] = AC97_MUTE; - if (dev->misc_flags & AC97_MONOOUT) + if (ac97_codecs[dev->model].misc_flags & AC97_MONOOUT) dev->regs[0x06 >> 1] = AC97_MUTE; - if (dev->misc_flags & AC97_PHONE) + if (ac97_codecs[dev->model].misc_flags & AC97_PHONE) dev->regs[0x0c >> 1] = AC97_MUTE | 0x0008; dev->regs[0x0e >> 1] = AC97_MUTE | 0x0008; /* mic */ dev->regs[0x10 >> 1] = dev->regs[0x12 >> 1] = dev->regs[0x18 >> 1] = AC97_MUTE | 0x0808; /* line in, CD, PCM out */ - if (dev->misc_flags & AC97_VIDEO) + if (ac97_codecs[dev->model].misc_flags & AC97_VIDEO) dev->regs[0x14 >> 1] = AC97_MUTE | 0x0808; - if (dev->misc_flags & AC97_AUXIN) + if (ac97_codecs[dev->model].misc_flags & AC97_AUXIN) dev->regs[0x14 >> 1] = AC97_MUTE | 0x0808; - dev->regs[0x1c >> 1] = AC97_MUTE; /* record gain */ - if (dev->reset_flags & AC97_MICPCM) + dev->regs[0x1c >> 1] = AC97_MUTE; /* record gain */ + if (ac97_codecs[dev->model].reset_flags & AC97_MICPCM) dev->regs[0x1e >> 1] = AC97_MUTE; /* mic record gain */ - if (dev->misc_flags & AC97_LDAC) + if (ac97_codecs[dev->model].misc_flags & AC97_LDAC) dev->regs[0x36 >> 1] = AC97_MUTE_L; - if (dev->misc_flags & AC97_CDAC) + if (ac97_codecs[dev->model].misc_flags & AC97_CDAC) dev->regs[0x36 >> 1] |= AC97_MUTE_R; - if (dev->misc_flags & AC97_SDAC) + if (ac97_codecs[dev->model].misc_flags & AC97_SDAC) dev->regs[0x38 >> 1] = AC97_MUTE_L | AC97_MUTE_R; /* Set flags. */ - dev->regs[0x00 >> 1] = dev->reset_flags; - dev->regs[0x26 >> 1] = 0x000f; /* codec ready */ - dev->regs[0x28 >> 1] = (dev->codec_id << 14) | dev->extid_flags; + dev->regs[0x00 >> 1] = ac97_codecs[dev->model].reset_flags; + dev->regs[0x26 >> 1] = 0x000f; /* codec ready */ + dev->regs[0x28 >> 1] = (dev->codec_id << 14) | ac97_codecs[dev->model].extid_flags; ac97_codec_writew(dev, 0x2a, 0x0000); /* reset variable DAC/ADC sample rates */ - i = dev->extid_flags & (AC97_CDAC | AC97_SDAC | AC97_LDAC); + i = ac97_codecs[dev->model].extid_flags & (AC97_CDAC | AC97_SDAC | AC97_LDAC); dev->regs[0x2a >> 1] |= i | (i << 5); /* any additional DACs are ready but powered down */ - if (dev->extid_flags & AC97_SPDIF) + if (ac97_codecs[dev->model].extid_flags & AC97_SPDIF) dev->regs[0x2a >> 1] |= AC97_SPCV; - if (dev->reset_flags & AC97_MICPCM) + if (ac97_codecs[dev->model].reset_flags & AC97_MICPCM) dev->regs[0x2a >> 1] |= AC97_MADC | AC97_PRL; /* Set vendor ID. */ - dev->regs[0x7c >> 1] = dev->vendor_id >> 16; - dev->regs[0x7e >> 1] = dev->vendor_id; + dev->regs[0x7c >> 1] = ac97_codecs[dev->model].device->local >> 16; + dev->regs[0x7e >> 1] = ac97_codecs[dev->model].device->local; /* Set vendor-specific registers. */ - if (dev->vendor_regs) { - for (uint16_t j = 0; dev->vendor_regs[j].index; j++) { - i = (dev->vendor_regs[j].index >> 8) & 0x000f; - if (i > 0) - dev->vendor_reg_pages[(i << 3) | (dev->vendor_regs[j].index >> 1)] = dev->vendor_regs[j].value; + if (ac97_codecs[dev->model].vendor_regs) { + for (i = 0; ac97_codecs[dev->model].vendor_regs[i].index; i++) { + if (ac97_codecs[dev->model].vendor_regs[i].page > 0) + dev->vendor_reg_pages[(ac97_codecs[dev->model].vendor_regs[i].page << 3) | (ac97_codecs[dev->model].vendor_regs[i].index >> 1)] = ac97_codecs[dev->model].vendor_regs[i].value; else - dev->regs[dev->vendor_regs[j].index >> 1] = dev->vendor_regs[j].value; + dev->regs[ac97_codecs[dev->model].vendor_regs[i].index >> 1] = ac97_codecs[dev->model].vendor_regs[i].value; } } } @@ -518,8 +523,8 @@ ac97_codec_reset(void *priv) void ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) { - ac97_codec_t *dev = (ac97_codec_t *) priv; - uint16_t val = dev->regs[reg >> 1]; + const ac97_codec_t *dev = (ac97_codec_t *) priv; + uint16_t val = dev->regs[reg >> 1]; /* Apply full mute and powerdowns. */ int full_mute = (reg < 0x36); @@ -557,7 +562,7 @@ ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) uint32_t ac97_codec_getrate(void *priv, uint8_t reg) { - ac97_codec_t *dev = (ac97_codec_t *) priv; + const ac97_codec_t *dev = (ac97_codec_t *) priv; /* Get configured sample rate, which is always 48000 if VRA/VRM is not set. */ uint32_t ret = dev->regs[reg >> 1]; @@ -577,15 +582,18 @@ ac97_codec_init(const device_t *info) ac97_codec_t *dev = malloc(sizeof(ac97_codec_t)); memset(dev, 0, sizeof(ac97_codec_t)); - dev->vendor_id = ac97_codecs[info->local].vendor_id; - dev->min_rate = ac97_codecs[info->local].min_rate; - dev->max_rate = ac97_codecs[info->local].max_rate; - dev->reset_flags = ac97_codecs[info->local].reset_flags; - dev->extid_flags = ac97_codecs[info->local].extid_flags; - dev->misc_flags = ac97_codecs[info->local].misc_flags; - dev->powerdown_mask = ac97_codecs[info->local].powerdown_mask; - dev->vendor_regs = ac97_codecs[info->local].vendor_regs; - ac97_codec_log("AC97 Codec %d: init(%c%c%c%02X)\n", ac97_codec_id, (dev->vendor_id >> 24) & 0xff, (dev->vendor_id >> 16) & 0xff, (dev->vendor_id >> 8) & 0xff, dev->vendor_id & 0xff); + for (; dev->model < (sizeof(ac97_codecs) / sizeof(ac97_codecs[0])); dev->model++) { + if (ac97_codecs[dev->model].device->local == info->local) + break; + } + if (dev->model >= (sizeof(ac97_codecs) / sizeof(ac97_codecs[0]))) { + fatal("AC97 Codec %d: Unknown ID %c%c%c%02X\n", ac97_codec_id, (info->local >> 24) & 0xff, (info->local >> 16) & 0xff, (info->local >> 8) & 0xff, info->local & 0xff); + free(dev); + return NULL; + } + ac97_codec_log("AC97 Codec %d: init(%c%c%c%02X)\n", ac97_codec_id, + (ac97_codecs[dev->model].device->local >> 24) & 0xff, (ac97_codecs[dev->model].device->local >> 16) & 0xff, + (ac97_codecs[dev->model].device->local >> 8) & 0xff, ac97_codecs[dev->model].device->local & 0xff); /* Associate this codec to the current controller. */ if (!ac97_codec || (ac97_codec_count <= 0)) { @@ -601,20 +609,17 @@ ac97_codec_init(const device_t *info) dev->codec_id = ac97_codec_id++; /* Allocate vendor-specific register pages if required. */ - if (dev->vendor_regs) { + if (ac97_codecs[dev->model].vendor_regs) { /* Get the highest vendor-specific register page number. */ - int i; - dev->vendor_reg_page_max = 0; - for (uint16_t j = 0; dev->vendor_regs[j].index; j++) { - i = (dev->vendor_regs[j].index >> 8) & 0x000f; - if (i > dev->vendor_reg_page_max) - dev->vendor_reg_page_max = i; + for (uint16_t i = 0; ac97_codecs[dev->model].vendor_regs[i].index; i++) { + if (ac97_codecs[dev->model].vendor_regs[i].page > dev->vendor_reg_page_max) + dev->vendor_reg_page_max = ac97_codecs[dev->model].vendor_regs[i].page; } /* Allocate pages 1+. */ if (dev->vendor_reg_page_max > 0) { ac97_codec_log("AC97 Codec %d: Allocating %d vendor-specific register pages\n", dev->codec_id, dev->vendor_reg_page_max); - i = 16 * dev->vendor_reg_page_max; + int i = 16 * dev->vendor_reg_page_max; dev->vendor_reg_pages = (uint16_t *) malloc(i); memset(dev->vendor_reg_pages, 0, i); } @@ -641,12 +646,13 @@ ac97_codec_close(void *priv) } const device_t * -ac97_codec_get(int model) +ac97_codec_get(uint32_t id) { - if ((model >= 0) && (model < (sizeof(ac97_codecs) / sizeof(ac97_codecs[0])))) - return ac97_codecs[model].device; - else - return &cs4297a_device; /* fallback */ + for (int i = 0; i < (sizeof(ac97_codecs) / sizeof(ac97_codecs[0])); i++) { + if (ac97_codecs[i].device->local == id) + return ac97_codecs[i].device; + } + return &tr28023_device; /* fallback */ } const device_t ad1881_device = { @@ -747,6 +753,20 @@ const device_t stac9721_device = { .config = NULL }; +const device_t tr28023_device = { + .name = "TriTech TR28023 / Creative CT1297", + .internal_name = "tr28023", + .flags = DEVICE_AC97, + .local = AC97_CODEC_TR28023, + .init = ac97_codec_init, + .close = ac97_codec_close, + .reset = ac97_codec_reset, + { .available = NULL }, + .speed_changed = NULL, + .force_redraw = NULL, + .config = NULL +}; + const device_t wm9701a_device = { .name = "Wolfson WM9701A", .internal_name = "wm9701a", diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 81babc78b..e074d17e2 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -30,38 +30,59 @@ #include <86box/snd_ac97.h> #include <86box/sound.h> #include <86box/timer.h> +#include <86box/plat_unused.h> -typedef struct { - uint8_t id, always_run; +typedef struct ac97_via_sgd_t { + uint8_t id; + uint8_t always_run; struct _ac97_via_ *dev; - uint32_t entry_ptr, sample_ptr, fifo_pos, fifo_end; + uint32_t entry_ptr; + uint32_t sample_ptr; + uint32_t fifo_pos; + uint32_t fifo_end; int32_t sample_count; - uint8_t entry_flags, fifo[32], restart; + uint8_t entry_flags; + uint8_t fifo[32]; + uint8_t restart; - int16_t out_l, out_r; - int vol_l, vol_r, pos; + int16_t out_l; + int16_t out_r; + int vol_l; + int vol_r; + int pos; int32_t buffer[SOUNDBUFLEN * 2]; uint64_t timer_latch; - pc_timer_t dma_timer, poll_timer; + pc_timer_t dma_timer; + pc_timer_t poll_timer; } ac97_via_sgd_t; typedef struct _ac97_via_ { - uint16_t audio_sgd_base, audio_codec_base, modem_sgd_base, modem_codec_base; - uint8_t sgd_regs[256], pcm_enabled : 1, fm_enabled : 1, vsr_enabled : 1; + uint16_t audio_sgd_base; + uint16_t audio_codec_base; + uint16_t modem_sgd_base; + uint16_t modem_codec_base; + uint8_t sgd_regs[256]; + uint8_t pcm_enabled : 1; + uint8_t fm_enabled : 1; + uint8_t vsr_enabled : 1; struct { union { uint8_t regs_codec[2][128]; uint8_t regs_linear[256]; }; } codec_shadow[2]; - int slot, irq_pin; + int slot; + int irq_pin; ac97_codec_t *codec[2][2]; ac97_via_sgd_t sgd[6]; - int master_vol_l, master_vol_r, cd_vol_l, cd_vol_r; + int master_vol_l; + int master_vol_r; + int cd_vol_l; + int cd_vol_r; } ac97_via_t; #ifdef ENABLE_AC97_VIA_LOG @@ -101,8 +122,8 @@ ac97_via_set_slot(void *priv, int slot, int irq_pin) uint8_t ac97_via_read_status(void *priv, uint8_t modem) { - ac97_via_t *dev = (ac97_via_t *) priv; - uint8_t ret = 0x00; + const ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t ret = 0x00; /* Flag each codec as ready if present. */ for (uint8_t i = 0; i <= 1; i++) { @@ -188,7 +209,7 @@ ac97_via_update_codec(ac97_via_t *dev) uint8_t ac97_via_sgd_read(uint16_t addr, void *priv) { - ac97_via_t *dev = (ac97_via_t *) priv; + const ac97_via_t *dev = (ac97_via_t *) priv; #ifdef ENABLE_AC97_VIA_LOG uint8_t modem = (addr & 0xff00) == dev->modem_sgd_base; #endif @@ -350,6 +371,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) case 0x8 ... 0xf: /* Read-only registers. */ return; + + default: + break; } } else { /* Process regular registers. */ @@ -404,6 +428,9 @@ ac97_via_sgd_write(uint16_t addr, uint8_t val, void *priv) val = dev->sgd_regs[addr] | (val & 0xc0); #endif break; + + default: + break; } } @@ -441,10 +468,11 @@ ac97_via_remap_modem_sgd(void *priv, uint16_t new_io_base, uint8_t enable) uint8_t ac97_via_codec_read(uint16_t addr, void *priv) { - ac97_via_t *dev = (ac97_via_t *) priv; - uint8_t modem = (addr & 0xff00) == dev->modem_codec_base; + const ac97_via_t *dev = (ac97_via_t *) priv; + uint8_t modem = (addr & 0xff00) == dev->modem_codec_base; + uint8_t ret = 0xff; + addr &= 0xff; - uint8_t ret = 0xff; ret = dev->codec_shadow[modem].regs_linear[addr]; @@ -676,6 +704,9 @@ ac97_via_poll_stereo(void *priv) return; } break; + + default: + break; } /* Feed silence if the FIFO is empty. */ @@ -728,9 +759,9 @@ ac97_via_get_buffer(int32_t *buffer, int len, void *priv) static void ac97_via_filter_cd_audio(int channel, double *buffer, void *priv) { - ac97_via_t *dev = (ac97_via_t *) priv; - double c; - double volume = channel ? dev->cd_vol_r : dev->cd_vol_l; + const ac97_via_t *dev = (ac97_via_t *) priv; + double c; + double volume = channel ? dev->cd_vol_r : dev->cd_vol_l; c = ((*buffer) * volume) / 65536.0; *buffer = c; @@ -753,7 +784,7 @@ ac97_via_speed_changed(void *priv) } static void * -ac97_via_init(const device_t *info) +ac97_via_init(UNUSED(const device_t *info)) { ac97_via_t *dev = malloc(sizeof(ac97_via_t)); memset(dev, 0, sizeof(ac97_via_t)); diff --git a/src/sound/snd_ad1848.c b/src/sound/snd_ad1848.c index 284836704..acc143636 100644 --- a/src/sound/snd_ad1848.c +++ b/src/sound/snd_ad1848.c @@ -30,6 +30,7 @@ #include <86box/timer.h> #include <86box/sound.h> #include <86box/snd_ad1848.h> +#include <86box/plat_fallthrough.h> #define CS4231 0x80 #define CS4236 0x03 @@ -65,8 +66,8 @@ ad1848_updatevolmask(ad1848_t *ad1848) static void ad1848_updatefreq(ad1848_t *ad1848) { - double freq; - uint8_t set = 0; + double freq = 0.0; + uint8_t set = 0; if (ad1848->type >= AD1848_TYPE_CS4235) { if (ad1848->xregs[11] & 0x20) { @@ -111,6 +112,9 @@ ad1848_updatefreq(ad1848_t *ad1848) case 0x20: freq /= 256 * set; break; + + default: + break; } set = 1; } @@ -143,6 +147,9 @@ ad1848_updatefreq(ad1848_t *ad1848) case 7: freq /= 2560; break; + + default: + break; } } @@ -194,12 +201,18 @@ ad1848_read(uint16_t addr, void *priv) ret = ad1848->xregs[ad1848->xindex]; } break; + + default: + break; } break; case 2: ret = ad1848->status; break; + + default: + break; } return ret; @@ -229,7 +242,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) case 10: if (ad1848->type < AD1848_TYPE_CS4235) break; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 8: updatefreq = 1; @@ -359,6 +374,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) case 25: return; + + default: + break; } ad1848->xregs[ad1848->xindex] = val; @@ -383,6 +401,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) if (ad1848->type != AD1848_TYPE_DEFAULT) return; break; + + default: + break; } ad1848->regs[ad1848->index] = val; @@ -406,6 +427,9 @@ ad1848_write(uint16_t addr, uint8_t val, void *priv) ad1848->status &= 0xfe; ad1848->regs[24] &= 0x0f; break; + + default: + break; } } @@ -561,6 +585,9 @@ ad1848_poll(void *priv) break; /* 0xe0 and 0xf0 reserved */ + + default: + break; } if (ad1848->regs[6] & 0x80) @@ -595,9 +622,9 @@ ad1848_poll(void *priv) void ad1848_filter_cd_audio(int channel, double *buffer, void *priv) { - ad1848_t *ad1848 = (ad1848_t *) priv; - double c; - double volume = channel ? ad1848->cd_vol_r : ad1848->cd_vol_l; + const ad1848_t *ad1848 = (ad1848_t *) priv; + double c; + double volume = channel ? ad1848->cd_vol_r : ad1848->cd_vol_l; c = ((*buffer) * volume) / 65536.0; *buffer = c; @@ -606,7 +633,7 @@ ad1848_filter_cd_audio(int channel, double *buffer, void *priv) void ad1848_filter_aux2(void *priv, double *out_l, double *out_r) { - ad1848_t *ad1848 = (ad1848_t *) priv; + const ad1848_t *ad1848 = (ad1848_t *) priv; if (ad1848->regs[4] & 0x80) { *out_l = 0.0; diff --git a/src/sound/snd_adlib.c b/src/sound/snd_adlib.c index d9498d567..5d0d7c7aa 100644 --- a/src/sound/snd_adlib.c +++ b/src/sound/snd_adlib.c @@ -13,6 +13,7 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/snd_opl.h> +#include <86box/plat_unused.h> #ifdef ENABLE_ADLIB_LOG int adlib_do_log = ENABLE_ADLIB_LOG; @@ -39,22 +40,22 @@ typedef struct adlib_t { } adlib_t; static void -adlib_get_buffer(int32_t *buffer, int len, void *p) +adlib_get_buffer(int32_t *buffer, int len, void *priv) { - adlib_t *adlib = (adlib_t *) p; + adlib_t *adlib = (adlib_t *) priv; - int32_t *opl_buf = adlib->opl.update(adlib->opl.priv); + const int32_t *opl_buf = adlib->opl.update(adlib->opl.priv); for (int c = 0; c < len * 2; c++) - buffer[c] += (int32_t) opl_buf[c]; + buffer[c] += opl_buf[c]; adlib->opl.reset_buffer(adlib->opl.priv); } uint8_t -adlib_mca_read(int port, void *p) +adlib_mca_read(int port, void *priv) { - adlib_t *adlib = (adlib_t *) p; + const adlib_t *adlib = (adlib_t *) priv; adlib_log("adlib_mca_read: port=%04x\n", port); @@ -62,9 +63,9 @@ adlib_mca_read(int port, void *p) } void -adlib_mca_write(int port, uint8_t val, void *p) +adlib_mca_write(int port, uint8_t val, void *priv) { - adlib_t *adlib = (adlib_t *) p; + adlib_t *adlib = (adlib_t *) priv; if (port < 0x102) return; @@ -84,20 +85,23 @@ adlib_mca_write(int port, uint8_t val, void *p) adlib->opl.write, NULL, NULL, adlib->opl.priv); break; + + default: + break; } adlib->pos_regs[port & 7] = val; } uint8_t -adlib_mca_feedb(void *p) +adlib_mca_feedb(void *priv) { - adlib_t *adlib = (adlib_t *) p; + const adlib_t *adlib = (adlib_t *) priv; return (adlib->pos_regs[2] & 1); } void * -adlib_init(const device_t *info) +adlib_init(UNUSED(const device_t *info)) { adlib_t *adlib = malloc(sizeof(adlib_t)); memset(adlib, 0, sizeof(adlib_t)); @@ -133,9 +137,9 @@ adlib_mca_init(const device_t *info) } void -adlib_close(void *p) +adlib_close(void *priv) { - adlib_t *adlib = (adlib_t *) p; + adlib_t *adlib = (adlib_t *) priv; free(adlib); } diff --git a/src/sound/snd_adlibgold.c b/src/sound/snd_adlibgold.c index e4330cba3..984a06ea9 100644 --- a/src/sound/snd_adlibgold.c +++ b/src/sound/snd_adlibgold.c @@ -17,15 +17,18 @@ #include <86box/sound.h> #include <86box/snd_opl.h> #include <86box/snd_ym7128.h> +#include <86box/plat_unused.h> typedef struct adgold_t { int adgold_irq_status; - int irq, dma; + int irq; + int dma; uint8_t adgold_eeprom[0x1a]; uint8_t adgold_status; - int adgold_38x_state, adgold_38x_addr; + int adgold_38x_state; + int adgold_38x_addr; uint8_t adgold_38x_regs[0x1a]; int adgold_mma_addr; @@ -33,7 +36,8 @@ typedef struct adgold_t { int adgold_mma_enable[2]; uint8_t adgold_mma_fifo[2][256]; - int adgold_mma_fifo_start[2], adgold_mma_fifo_end[2]; + int adgold_mma_fifo_start[2]; + int adgold_mma_fifo_end[2]; uint8_t adgold_mma_status; int16_t adgold_mma_out[2]; @@ -41,28 +45,42 @@ typedef struct adgold_t { pc_timer_t adgold_mma_timer_count; - uint8_t adgold_midi_ctrl, midi_queue[16]; - int midi_r, midi_w; - int uart_in, uart_out, sysex; + uint8_t adgold_midi_ctrl; + uint8_t midi_queue[16]; + int midi_r; + int midi_w; + int uart_in; + int uart_out; + int sysex; - struct - { - int timer0_latch, timer0_count; - int timerbase_latch, timerbase_count; - int timer1_latch, timer1_count; - int timer2_latch, timer2_count, timer2_read; + struct { + int timer0_latch; + int timer0_count; + int timerbase_latch; + int timerbase_count; + int timer1_latch; + int timer1_count; + int timer2_latch; + int timer2_count; + int timer2_read; - int voice_count[2], voice_latch[2]; + int voice_count[2]; + int voice_latch[2]; } adgold_mma; fm_drv_t opl; ym7128_t ym7128; - int fm_vol_l, fm_vol_r; - int samp_vol_l, samp_vol_r; - int aux_vol_l, aux_vol_r; - int vol_l, vol_r; - int treble, bass; + int fm_vol_l; + int fm_vol_r; + int samp_vol_l; + int samp_vol_r; + int aux_vol_l; + int aux_vol_r; + int vol_l; + int vol_r; + int treble; + int bass; int16_t opl_buffer[SOUNDBUFLEN * 2]; int16_t mma_buffer[2][SOUNDBUFLEN]; @@ -131,7 +149,7 @@ static int treble_cut[6] = { (int) (0.354 * 16384) /*-3 dB - filter output is at +6 dB*/ }; -void adgold_timer_poll(void *p); +void adgold_timer_poll(void *priv); void adgold_update(adgold_t *adgold); void @@ -192,9 +210,9 @@ adgold_getsamp_dma(adgold_t *adgold, int channel) } void -adgold_write(uint16_t addr, uint8_t val, void *p) +adgold_write(uint16_t addr, uint8_t val, void *priv) { - adgold_t *adgold = (adgold_t *) p; + adgold_t *adgold = (adgold_t *) priv; switch (addr & 7) { case 0: case 1: @@ -337,6 +355,9 @@ adgold_write(uint16_t addr, uint8_t val, void *p) case 0x18: adgold->adgold_mma.voice_latch[0] = 72; break; /* 7350 Hz*/ + + default: + break; } if (val & 0x80) { adgold->adgold_mma_enable[0] = 0; @@ -438,6 +459,9 @@ adgold_write(uint16_t addr, uint8_t val, void *p) adgold_update_irq_status(adgold); } break; + + default: + break; } adgold->adgold_mma_regs[0][adgold->adgold_mma_addr] = val; break; @@ -460,6 +484,9 @@ adgold_write(uint16_t addr, uint8_t val, void *p) case 0x18: adgold->adgold_mma.voice_latch[1] = 72; break; /* 7350 Hz*/ + + default: + break; } if (val & 0x80) { adgold->adgold_mma_enable[1] = 0; @@ -497,16 +524,22 @@ adgold_write(uint16_t addr, uint8_t val, void *p) case 0xc: adgold->adgold_mma_intpos[1] = (7 - ((val >> 2) & 7)) * 8; break; + + default: + break; } adgold->adgold_mma_regs[1][adgold->adgold_mma_addr] = val; break; + + default: + break; } } uint8_t -adgold_read(uint16_t addr, void *p) +adgold_read(uint16_t addr, void *priv) { - adgold_t *adgold = (adgold_t *) p; + adgold_t *adgold = (adgold_t *) priv; uint8_t temp = 0; switch (addr & 7) { @@ -586,6 +619,9 @@ adgold_read(uint16_t addr, void *p) else temp = adgold->adgold_mma_regs[1][adgold->adgold_mma_addr]; break; + + default: + break; } return temp; } @@ -633,6 +669,9 @@ adgold_mma_poll(adgold_t *adgold, int channel) adgold->adgold_mma_fifo_start[channel] = (adgold->adgold_mma_fifo_start[channel] + 1) & 255; adgold->adgold_mma_out[channel] = dat; break; + + default: + break; } if (adgold->adgold_mma_regs[channel][0xc] & 1) { @@ -649,9 +688,9 @@ adgold_mma_poll(adgold_t *adgold, int channel) } void -adgold_timer_poll(void *p) +adgold_timer_poll(void *priv) { - adgold_t *adgold = (adgold_t *) p; + adgold_t *adgold = (adgold_t *) priv; /*A small timer period will result in hangs.*/ timer_on_auto(&adgold->adgold_mma_timer_count, 4.88964); @@ -718,16 +757,16 @@ adgold_timer_poll(void *p) } static void -adgold_get_buffer(int32_t *buffer, int len, void *p) +adgold_get_buffer(int32_t *buffer, int len, void *priv) { - adgold_t *adgold = (adgold_t *) p; + adgold_t *adgold = (adgold_t *) priv; int16_t *adgold_buffer = malloc(sizeof(int16_t) * len * 2); if (adgold_buffer == NULL) fatal("adgold_buffer = NULL"); int c; - int32_t *opl_buf = adgold->opl.update(adgold->opl.priv); + const int32_t *opl_buf = adgold->opl.update(adgold->opl.priv); adgold_update(adgold); for (c = 0; c < len * 2; c += 2) { @@ -755,6 +794,9 @@ adgold_get_buffer(int32_t *buffer, int len, void *p) break; case 6: /*Left and right channels*/ break; + + default: + break; } switch (adgold->adgold_38x_regs[0x8] & 0x18) { @@ -781,6 +823,9 @@ adgold_get_buffer(int32_t *buffer, int len, void *p) adgold_buffer[c + 1] += (l / 3) + ((r * 2) / 3); } break; + + default: + break; } for (c = 0; c < len * 2; c += 2) { @@ -831,12 +876,12 @@ adgold_get_buffer(int32_t *buffer, int len, void *p) } static void -adgold_filter_cd_audio(int channel, double *buffer, void *p) +adgold_filter_cd_audio(int channel, double *buffer, void *priv) { - adgold_t *adgold = (adgold_t *) p; - double c; - int aux = channel ? adgold->aux_vol_r : adgold->aux_vol_l; - int vol = channel ? adgold->vol_r : adgold->vol_l; + const adgold_t *adgold = (adgold_t *) priv; + double c; + int aux = channel ? adgold->aux_vol_r : adgold->aux_vol_l; + int vol = channel ? adgold->vol_r : adgold->vol_l; c = ((((*buffer) * aux) / 4096.0) * vol) / 4096.0; *buffer = c; @@ -883,7 +928,7 @@ adgold_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort) } void * -adgold_init(const device_t *info) +adgold_init(UNUSED(const device_t *info)) { FILE *f; int c; @@ -957,6 +1002,9 @@ adgold_init(const device_t *info) case 7: adgold->adgold_eeprom[0x13] |= 0x03; break; + + default: + break; } adgold->adgold_eeprom[0x13] |= (adgold->dma << 3); adgold->adgold_eeprom[0x14] |= (adgold->dma << 4); @@ -993,15 +1041,15 @@ adgold_init(const device_t *info) } void -adgold_close(void *p) +adgold_close(void *priv) { - FILE *f; - adgold_t *adgold = (adgold_t *) p; + FILE *fp; + adgold_t *adgold = (adgold_t *) priv; - f = nvr_fopen("adgold.bin", "wb"); - if (f) { - fwrite(adgold->adgold_eeprom, 0x1a, 1, f); - fclose(f); + fp = nvr_fopen("adgold.bin", "wb"); + if (fp) { + fwrite(adgold->adgold_eeprom, 0x1a, 1, fp); + fclose(fp); } free(adgold); diff --git a/src/sound/snd_audiopci.c b/src/sound/snd_audiopci.c index 6b9d8d792..fb156a205 100644 --- a/src/sound/snd_audiopci.c +++ b/src/sound/snd_audiopci.c @@ -38,6 +38,7 @@ #include <86box/snd_ac97.h> #include <86box/sound.h> #include <86box/timer.h> +#include <86box/plat_unused.h> #define N 16 @@ -45,8 +46,9 @@ static float low_fir_es1371_coef[ES1371_NCoef]; -typedef struct { - uint8_t pci_command, pci_serr; +typedef struct es1371_t { + uint8_t pci_command; + uint8_t pci_serr; uint32_t base_addr; @@ -54,9 +56,10 @@ typedef struct { uint16_t pmcsr; - uint32_t int_ctrl, int_status, - legacy_ctrl; - void *gameport; + uint32_t int_ctrl; + uint32_t int_status; + uint32_t legacy_ctrl; + void *gameport; int mem_page; @@ -65,17 +68,22 @@ typedef struct { uint32_t sr_cir; uint16_t sr_ram[128]; - uint8_t uart_data, uart_ctrl, - uart_status, uart_res; + uint8_t uart_data; + uint8_t uart_ctrl; + uint8_t uart_status; + uint8_t uart_res; uint32_t uart_fifo[8]; - uint8_t read_fifo_pos, write_fifo_pos; + uint8_t read_fifo_pos; + uint8_t write_fifo_pos; ac97_codec_t *codec; uint32_t codec_ctrl; struct { - uint32_t addr, addr_latch; - uint16_t count, size; + uint32_t addr; + uint32_t addr_latch; + uint16_t count; + uint16_t size; uint16_t samp_ct; int curr_samp_ct; @@ -83,24 +91,34 @@ typedef struct { pc_timer_t timer; uint64_t latch; - uint32_t vf, ac; + uint32_t vf; + uint32_t ac; - int16_t buffer_l[64], buffer_r[64]; - int buffer_pos, buffer_pos_end; + int16_t buffer_l[64]; + int16_t buffer_r[64]; + int buffer_pos; + int buffer_pos_end; - int filtered_l[32], filtered_r[32]; + int filtered_l[32]; + int filtered_r[32]; int f_pos; - int16_t out_l, out_r; + int16_t out_l; + int16_t out_r; - int32_t vol_l, vol_r; + int32_t vol_l; + int32_t vol_r; } dac[2], adc; - int64_t dac_latch, dac_time; + int64_t dac_latch; + int64_t dac_time; - int master_vol_l, master_vol_r, - pcm_vol_l, pcm_vol_r, - cd_vol_l, cd_vol_r; + int master_vol_l; + int master_vol_r; + int pcm_vol_l; + int pcm_vol_r; + int cd_vol_l; + int cd_vol_r; int card; @@ -299,15 +317,15 @@ es1371_reset_fifo(es1371_t *dev) } static void -es1371_reset(void *p) +es1371_reset(void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; nmi = 0; /* Interrupt/Chip Select Control Register, Address 00H Addressable as byte, word, longword */ - dev->int_ctrl = 0xfc0f0000; + dev->int_ctrl = 0xfcff0000; /* Interrupt/Chip Select Control Register, Address 00H Addressable as longword only */ @@ -315,7 +333,7 @@ es1371_reset(void *p) /* UART Status Register, Address 09H Addressable as byte only */ - dev->uart_status = 0x00; + dev->uart_status = 0xff; /* UART Control Register, Address 09H Addressable as byte only */ @@ -323,15 +341,15 @@ es1371_reset(void *p) /* UART Reserved Register, Address 0AH Addressable as byte only */ - dev->uart_res = 0x00; + dev->uart_res = 0xff; /* Memory Page Register, Address 0CH Addressable as byte, word, longword */ - dev->mem_page = 0x00; + dev->mem_page = 0xf0; /* FIXME: hardware reads 0xfffffff0 */ /* Sample Rate Converter Interface Register, Address 10H Addressable as longword only */ - dev->sr_cir = 0x00000000; + dev->sr_cir = 0x00470000; /* CODEC Write Register, Address 14H Addressable as longword only */ @@ -339,7 +357,7 @@ es1371_reset(void *p) /* Legacy Control/Status Register, Address 18H Addressable as byte, word, longword */ - dev->legacy_ctrl = 0x0000f800; + dev->legacy_ctrl = 0x0000f801; /* Serial Interface Control Register, Address 20H Addressable as byte, word, longword */ @@ -347,17 +365,17 @@ es1371_reset(void *p) /* DAC1 Channel Sample Count Register, Address 24H Addressable as word, longword */ - dev->dac[0].samp_ct = 0x00000000; + dev->dac[0].samp_ct = 0x00000000; /* FIXME: hardware reads 0x00010000 */ dev->dac[0].curr_samp_ct = 0x00000000; /* DAC2 Channel Sample Count Register, Address 28H Addressable as word, longword */ - dev->dac[1].samp_ct = 0x00000000; + dev->dac[1].samp_ct = 0x00000000; /* FIXME: hardware reads 0x00010000 */ dev->dac[1].curr_samp_ct = 0x00000000; /* ADC Channel Sample Count Register, Address 2CH Addressable as word, longword */ - dev->adc.samp_ct = 0x00000000; + dev->adc.samp_ct = 0x00000000; /* FIXME: hardware reads 0x00010000 */ dev->adc.curr_samp_ct = 0x00000000; /* DAC1 Frame Register 1, Address 30H, Memory Page 1100b @@ -429,6 +447,9 @@ es1371_read_frame_reg(es1371_t *dev, int frame, int page) dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]); ret = dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]; break; + + default: + break; } break; case 0x34: @@ -452,6 +473,9 @@ es1371_read_frame_reg(es1371_t *dev, int frame, int page) dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]); ret = dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]; break; + + default: + break; } break; case 0x38: @@ -470,6 +494,9 @@ es1371_read_frame_reg(es1371_t *dev, int frame, int page) dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]); ret = dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]; break; + + default: + break; } break; case 0x3c: @@ -488,8 +515,14 @@ es1371_read_frame_reg(es1371_t *dev, int frame, int page) dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]); ret = dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)]; break; + + default: + break; } break; + + default: + break; } return ret; @@ -519,6 +552,9 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) ((page & 0x01) << 2) + ((frame >> 2) & 0x03), val); dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)] = val; break; + + default: + break; } break; case 0x34: @@ -543,6 +579,9 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) ((page & 0x01) << 2) + ((frame >> 2) & 0x03), val); dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)] = val; break; + + default: + break; } break; case 0x38: @@ -560,6 +599,9 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) ((page & 0x01) << 2) + ((frame >> 2) & 0x03), val); dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)] = val; break; + + default: + break; } break; case 0x3c: @@ -578,8 +620,14 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) ((page & 0x01) << 2) + ((frame >> 2) & 0x03), val); dev->uart_fifo[((page & 0x01) << 2) + ((frame >> 2) & 0x03)] = val; break; + + default: + break; } break; + + default: + break; } if (page == 0x0e || page == 0x0f) { @@ -588,9 +636,9 @@ es1371_write_frame_reg(es1371_t *dev, int frame, int page, uint32_t val) } static uint8_t -es1371_inb(uint16_t port, void *p) +es1371_inb(uint16_t port, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint8_t ret = 0xff; switch (port & 0x3f) { @@ -621,11 +669,11 @@ es1371_inb(uint16_t port, void *p) audiopci_log("[R] STATUS 8-15 = %02X\n", ret); break; case 0x06: - ret = (dev->int_status >> 16) & 0x0f; + ret = (dev->int_status >> 16) & 0xff; audiopci_log("[R] STATUS 16-23 = %02X\n", ret); break; case 0x07: - ret = ((dev->int_status >> 24) & 0x03) | 0xfc; + ret = (dev->int_status >> 24) & 0xff; audiopci_log("[R] STATUS 24-31 = %02X\n", ret); break; @@ -699,9 +747,9 @@ es1371_inb(uint16_t port, void *p) } static uint16_t -es1371_inw(uint16_t port, void *p) +es1371_inw(uint16_t port, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint16_t ret = 0xffff; switch (port & 0x3e) { @@ -780,6 +828,9 @@ es1371_inw(uint16_t port, void *p) case 0x3e: ret = es1371_read_frame_reg(dev, port & 0x3c, dev->mem_page) >> 16; break; + + default: + break; } audiopci_log("es1371_inw: port=%04x ret=%04x\n", port, ret); @@ -788,9 +839,9 @@ es1371_inw(uint16_t port, void *p) } static uint32_t -es1371_inl(uint16_t port, void *p) +es1371_inl(uint16_t port, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint32_t ret = 0xffffffff; switch (port & 0x3c) { @@ -862,6 +913,9 @@ es1371_inl(uint16_t port, void *p) case 0x3c: ret = es1371_read_frame_reg(dev, port & 0x3c, dev->mem_page); break; + + default: + break; } audiopci_log("es1371_inl: port=%04x ret=%08x\n", port, ret); @@ -869,9 +923,9 @@ es1371_inl(uint16_t port, void *p) } static void -es1371_outb(uint16_t port, uint8_t val, void *p) +es1371_outb(uint16_t port, uint8_t val, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint32_t old_legacy_ctrl; audiopci_log("es1371_outb: port=%04x val=%02x\n", port, val); @@ -989,9 +1043,9 @@ es1371_outb(uint16_t port, uint8_t val, void *p) } static void -es1371_outw(uint16_t port, uint16_t val, void *p) +es1371_outw(uint16_t port, uint16_t val, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint32_t old_legacy_ctrl; switch (port & 0x3f) { @@ -1068,13 +1122,16 @@ es1371_outw(uint16_t port, uint16_t val, void *p) case 0x2c: dev->adc.samp_ct = val; break; + + default: + break; } } static void -es1371_outl(uint16_t port, uint32_t val, void *p) +es1371_outl(uint16_t port, uint32_t val, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; uint32_t old_legacy_ctrl; audiopci_log("es1371_outl: port=%04x val=%08x\n", port, val); @@ -1154,6 +1211,9 @@ es1371_outl(uint16_t port, uint32_t val, void *p) case 0x7f: dev->dac[1].vol_r = (int32_t) (int16_t) (val & 0xffff); break; + + default: + break; } } break; @@ -1219,6 +1279,9 @@ es1371_outl(uint16_t port, uint32_t val, void *p) case 0x3c: es1371_write_frame_reg(dev, port & 0x3c, dev->mem_page, val); break; + + default: + break; } } @@ -1237,106 +1300,106 @@ capture_event(es1371_t *dev, int type, int rw, uint16_t port) } static void -capture_write_sscape(uint16_t port, uint8_t val, void *p) +capture_write_sscape(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_SSCAPE, 1, port); + capture_event(priv, LEGACY_EVENT_SSCAPE, 1, port); } static void -capture_write_codec(uint16_t port, uint8_t val, void *p) +capture_write_codec(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_CODEC, 1, port); + capture_event(priv, LEGACY_EVENT_CODEC, 1, port); } static void -capture_write_sb(uint16_t port, uint8_t val, void *p) +capture_write_sb(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_SB, 1, port); + capture_event(priv, LEGACY_EVENT_SB, 1, port); } static void -capture_write_adlib(uint16_t port, uint8_t val, void *p) +capture_write_adlib(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_ADLIB, 1, port); + capture_event(priv, LEGACY_EVENT_ADLIB, 1, port); } static void -capture_write_master_pic(uint16_t port, uint8_t val, void *p) +capture_write_master_pic(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_MASTER_PIC, 1, port); + capture_event(priv, LEGACY_EVENT_MASTER_PIC, 1, port); } static void -capture_write_master_dma(uint16_t port, uint8_t val, void *p) +capture_write_master_dma(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_MASTER_DMA, 1, port); + capture_event(priv, LEGACY_EVENT_MASTER_DMA, 1, port); } static void -capture_write_slave_pic(uint16_t port, uint8_t val, void *p) +capture_write_slave_pic(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_SLAVE_PIC, 1, port); + capture_event(priv, LEGACY_EVENT_SLAVE_PIC, 1, port); } static void -capture_write_slave_dma(uint16_t port, uint8_t val, void *p) +capture_write_slave_dma(uint16_t port, UNUSED(uint8_t val), void *priv) { - capture_event(p, LEGACY_EVENT_SLAVE_DMA, 1, port); + capture_event(priv, LEGACY_EVENT_SLAVE_DMA, 1, port); } static uint8_t -capture_read_sscape(uint16_t port, void *p) +capture_read_sscape(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_SSCAPE, 0, port); + capture_event(priv, LEGACY_EVENT_SSCAPE, 0, port); return 0xff; } static uint8_t -capture_read_codec(uint16_t port, void *p) +capture_read_codec(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_CODEC, 0, port); + capture_event(priv, LEGACY_EVENT_CODEC, 0, port); return 0xff; } static uint8_t -capture_read_sb(uint16_t port, void *p) +capture_read_sb(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_SB, 0, port); + capture_event(priv, LEGACY_EVENT_SB, 0, port); return 0xff; } static uint8_t -capture_read_adlib(uint16_t port, void *p) +capture_read_adlib(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_ADLIB, 0, port); + capture_event(priv, LEGACY_EVENT_ADLIB, 0, port); return 0xff; } static uint8_t -capture_read_master_pic(uint16_t port, void *p) +capture_read_master_pic(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_MASTER_PIC, 0, port); + capture_event(priv, LEGACY_EVENT_MASTER_PIC, 0, port); return 0xff; } static uint8_t -capture_read_master_dma(uint16_t port, void *p) +capture_read_master_dma(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_MASTER_DMA, 0, port); + capture_event(priv, LEGACY_EVENT_MASTER_DMA, 0, port); return 0xff; } static uint8_t -capture_read_slave_pic(uint16_t port, void *p) +capture_read_slave_pic(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_SLAVE_PIC, 0, port); + capture_event(priv, LEGACY_EVENT_SLAVE_PIC, 0, port); return 0xff; } static uint8_t -capture_read_slave_dma(uint16_t port, void *p) +capture_read_slave_dma(uint16_t port, void *priv) { - capture_event(p, LEGACY_EVENT_SLAVE_DMA, 0, port); + capture_event(priv, LEGACY_EVENT_SLAVE_DMA, 0, port); return 0xff; } @@ -1365,6 +1428,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) capture_read_sscape, NULL, NULL, capture_write_sscape, NULL, NULL, dev); break; + + default: + break; } } @@ -1385,6 +1451,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) capture_read_codec, NULL, NULL, capture_write_codec, NULL, NULL, dev); break; + + default: + break; } } @@ -1452,6 +1521,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) capture_read_sscape, NULL, NULL, capture_write_sscape, NULL, NULL, dev); break; + + default: + break; } } @@ -1472,6 +1544,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) capture_read_codec, NULL, NULL, capture_write_codec, NULL, NULL, dev); break; + + default: + break; } } @@ -1519,9 +1594,9 @@ update_legacy(es1371_t *dev, uint32_t old_legacy_ctrl) } static uint8_t -es1371_pci_read(int func, int addr, void *p) +es1371_pci_read(int func, int addr, void *priv) { - es1371_t *dev = (es1371_t *) p; + const es1371_t *dev = (es1371_t *) priv; if (func > 0) return 0xff; @@ -1551,7 +1626,7 @@ es1371_pci_read(int func, int addr, void *p) return 0x00; case 0x08: - return 0x08; /* Revision ID - 0x02 (datasheet, VMware) has issues with the 2001 Creative WDM driver */ + return 0x02; /* Revision ID - 0x02 is actual Ensoniq-branded ES1371 */ case 0x09: return 0x00; /* Multimedia audio device */ case 0x0a: @@ -1603,6 +1678,9 @@ es1371_pci_read(int func, int addr, void *p) return dev->pmcsr & 0xff; case 0xe1: return dev->pmcsr >> 8; + + default: + break; } return 0x00; @@ -1619,9 +1697,9 @@ es1371_io_set(es1371_t *dev, int set) } static void -es1371_pci_write(int func, int addr, uint8_t val, void *p) +es1371_pci_write(int func, int addr, uint8_t val, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; if (func) return; @@ -1663,6 +1741,9 @@ es1371_pci_write(int func, int addr, uint8_t val, void *p) case 0xe1: dev->pmcsr = (dev->pmcsr & 0x00ff) | ((val & 0x01) << 8); break; + + default: + break; } } @@ -1748,6 +1829,9 @@ es1371_fetch(es1371_t *dev, int dac_nr) } } break; + + default: + break; } } @@ -1839,9 +1923,9 @@ es1371_update(es1371_t *dev) } static void -es1371_poll(void *p) +es1371_poll(void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; int frac; int idx; int samp1_l; @@ -1907,9 +1991,9 @@ es1371_poll(void *p) } static void -es1371_get_buffer(int32_t *buffer, int len, void *p) +es1371_get_buffer(int32_t *buffer, int len, void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; es1371_update(dev); @@ -1920,12 +2004,12 @@ es1371_get_buffer(int32_t *buffer, int len, void *p) } static void -es1371_filter_cd_audio(int channel, double *buffer, void *p) +es1371_filter_cd_audio(int channel, double *buffer, void *priv) { - es1371_t *dev = (es1371_t *) p; - double c; - int cd = channel ? dev->cd_vol_r : dev->cd_vol_l; - int master = channel ? dev->master_vol_r : dev->master_vol_l; + const es1371_t *dev = (es1371_t *) priv; + double c; + int cd = channel ? dev->cd_vol_r : dev->cd_vol_l; + int master = channel ? dev->master_vol_r : dev->master_vol_l; c = ((((*buffer) * cd) / 65536.0) * master) / 65536.0; *buffer = c; @@ -2035,17 +2119,17 @@ es1371_init(const device_t *info) } static void -es1371_close(void *p) +es1371_close(void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; free(dev); } static void -es1371_speed_changed(void *p) +es1371_speed_changed(void *priv) { - es1371_t *dev = (es1371_t *) p; + es1371_t *dev = (es1371_t *) priv; dev->dac[1].latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / (double) SOUND_FREQ)); } @@ -2054,7 +2138,7 @@ static const device_config_t es1371_config[] = { // clang-format off { .name = "codec", - .description = "CODEC", + .description = "Codec", .type = CONFIG_SELECTION, .selection = { { @@ -2062,23 +2146,12 @@ static const device_config_t es1371_config[] = { .value = AC97_CODEC_AK4540 }, { - .description = "Crystal CS4297", - .value = AC97_CODEC_CS4297 + .description = "TriTech TR28023 / Creative CT1297", + .value = AC97_CODEC_TR28023 }, - { - .description = "Crystal CS4297A", - .value = AC97_CODEC_CS4297A - }, - { - .description = "SigmaTel STAC9708", - .value = AC97_CODEC_STAC9708 - }, - { - .description = "SigmaTel STAC9721", - .value = AC97_CODEC_STAC9721 - } + { .description = "" } }, - .default_int = AC97_CODEC_CS4297A + .default_int = AC97_CODEC_TR28023 }, { .name = "receive_input", diff --git a/src/sound/snd_azt2316a.c b/src/sound/snd_azt2316a.c index ee5c982f4..b4a4dd238 100644 --- a/src/sound/snd_azt2316a.c +++ b/src/sound/snd_azt2316a.c @@ -150,6 +150,7 @@ #include <86box/snd_ad1848.h> #include <86box/snd_azt2316a.h> #include <86box/snd_sb.h> +#include <86box/plat_unused.h> /*530, 11, 3 - 530=23*/ /*530, 11, 1 - 530=22*/ @@ -164,7 +165,9 @@ static int azt2316a_wss_dma[4] = { 0, 0, 1, 3 }; static int azt2316a_wss_irq[8] = { 5, 7, 9, 10, 11, 12, 14, 15 }; /* W95 only uses 7-10, others may be wrong */ -// static uint16_t azt2316a_wss_addr[4] = {0x530, 0x604, 0xe80, 0xf40}; +#if 0 +static uint16_t azt2316a_wss_addr[4] = {0x530, 0x604, 0xe80, 0xf40}; +#endif typedef struct azt2316a_t { int type; @@ -172,10 +175,14 @@ typedef struct azt2316a_t { uint8_t wss_config; - uint16_t cur_addr, cur_wss_addr, cur_mpu401_addr; + uint16_t cur_addr; + uint16_t cur_wss_addr; + uint16_t cur_mpu401_addr; int cur_irq, cur_dma; - int cur_wss_enabled, cur_wss_irq, cur_wss_dma; + int cur_wss_enabled; + int cur_wss_irq; + int cur_wss_dma; int cur_mpu401_irq; int cur_mpu401_enabled; @@ -191,10 +198,10 @@ typedef struct azt2316a_t { } azt2316a_t; static uint8_t -azt2316a_wss_read(uint16_t addr, void *p) +azt2316a_wss_read(uint16_t addr, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; - uint8_t temp; + const azt2316a_t *azt2316a = (azt2316a_t *) priv; + uint8_t temp; /* TODO: when windows is initializing, writing 0x48, 0x58 and 0x60 to 0x530 makes reading from 0x533 return 0x44, but writing 0x50 @@ -208,9 +215,9 @@ azt2316a_wss_read(uint16_t addr, void *p) } static void -azt2316a_wss_write(uint16_t addr, uint8_t val, void *p) +azt2316a_wss_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; int interrupt = 0; if (azt2316a->wss_interrupt_after_config) { @@ -231,9 +238,9 @@ azt2316a_wss_write(uint16_t addr, uint8_t val, void *p) /* generate a config word based on current settings */ static void -azt1605_create_config_word(void *p) +azt1605_create_config_word(void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; uint32_t temp = 0; /* not implemented / hardcoded */ @@ -244,8 +251,10 @@ azt1605_create_config_word(void *p) switch (azt2316a->cur_addr) { case 0x220: - /* do nothing - temp += 0 << 0; */ + // do nothing +#if 0 + temp += 0 << 0; +#endif break; case 0x240: temp += 1 << 0; @@ -258,6 +267,8 @@ azt1605_create_config_word(void *p) temp += 3 << 0; break; #endif + default: + break; } switch (azt2316a->cur_irq) { @@ -273,12 +284,17 @@ azt1605_create_config_word(void *p) case 7: temp += 1 << 11; break; + + default: + break; } switch (azt2316a->cur_wss_addr) { case 0x530: - /* do nothing - temp += 0 << 16; */ + // do nothing +#if 0 + temp += 0 << 16; +#endif break; case 0x604: temp += 1 << 16; @@ -289,6 +305,9 @@ azt1605_create_config_word(void *p) case 0xF40: temp += 3 << 16; break; + + default: + break; } if (azt2316a->cur_wss_enabled) @@ -299,12 +318,17 @@ azt1605_create_config_word(void *p) switch (azt2316a->cur_mpu401_addr) { case 0x300: - /* do nothing - temp += 0 << 2; */ + // do nothing +#if 0 + temp += 0 << 2; +#endif break; case 0x330: temp += 1 << 2; break; + + default: + break; } if (azt2316a->cur_mpu401_enabled) @@ -336,6 +360,9 @@ azt1605_create_config_word(void *p) case 7: // unused temp += 7 << 5; break; + + default: + break; } switch (cd_dma8) { @@ -352,6 +379,9 @@ azt1605_create_config_word(void *p) case 3: temp += 3 << 22; break; + + default: + break; } switch (azt2316a->cur_mpu401_irq) { @@ -367,6 +397,9 @@ azt1605_create_config_word(void *p) case 7: temp += 1 << 15; break; + + default: + break; } switch (cd_irq) { @@ -382,15 +415,18 @@ azt1605_create_config_word(void *p) case 15: temp += 1 << 21; break; + + default: + break; } azt2316a->config_word = temp; } static void -azt2316a_create_config_word(void *p) +azt2316a_create_config_word(void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; uint32_t temp = 0; /* not implemented / hardcoded */ @@ -402,14 +438,16 @@ azt2316a_create_config_word(void *p) uint8_t cd_irq = 15; if (azt2316a->type == SB_SUBTYPE_CLONE_AZT1605_0X0C) { - azt1605_create_config_word(p); + azt1605_create_config_word(priv); return; } switch (azt2316a->cur_addr) { case 0x220: - /* do nothing - temp += 0 << 0; */ + // do nothing +#if 0 + temp += 0 << 0; +#endif break; case 0x240: temp += 1 << 0; @@ -422,6 +460,8 @@ azt2316a_create_config_word(void *p) temp += 3 << 0; break; #endif + default: + break; } switch (azt2316a->cur_irq) { @@ -437,6 +477,9 @@ azt2316a_create_config_word(void *p) case 10: temp += 1 << 5; break; + + default: + break; } switch (azt2316a->cur_dma) { @@ -456,12 +499,17 @@ azt2316a_create_config_word(void *p) case 3: temp += 3 << 6; break; + + default: + break; } switch (azt2316a->cur_wss_addr) { case 0x530: // do nothing - // temp += 0 << 8; +#if 0 + temp += 0 << 8; +#endif break; case 0x604: temp += 1 << 8; @@ -472,6 +520,9 @@ azt2316a_create_config_word(void *p) case 0xF40: temp += 3 << 8; break; + + default: + break; } if (azt2316a->cur_wss_enabled) temp += 1 << 10; @@ -480,11 +531,16 @@ azt2316a_create_config_word(void *p) switch (azt2316a->cur_mpu401_addr) { case 0x300: // do nothing - // temp += 0 << 12; +#if 0 + temp += 0 << 12; +#endif break; case 0x330: temp += 1 << 12; break; + + default: + break; } if (azt2316a->cur_mpu401_enabled) @@ -493,7 +549,9 @@ azt2316a_create_config_word(void *p) switch (cd_addr) { case 0x310: // do nothing - // temp += 0 << 14; +#if 0 + temp += 0 << 14; +#endif break; case 0x320: temp += 1 << 14; @@ -504,11 +562,16 @@ azt2316a_create_config_word(void *p) case 0x350: temp += 3 << 14; break; + + default: + break; } switch (cd_type) { - case 0: /* disabled - do nothing + case 0: /* disabled */ + // do nothing +#if 0 temp += 0 << 16; */ +#endif break; case 1: /* panasonic */ temp += 1 << 16; @@ -531,6 +594,9 @@ azt2316a_create_config_word(void *p) case 7: /* unused */ temp += 7 << 16; break; + + default: + break; } switch (cd_dma8) { @@ -549,6 +615,9 @@ azt2316a_create_config_word(void *p) case 3: temp += 3 << 20; break; + + default: + break; } switch (cd_dma16) { @@ -565,6 +634,9 @@ azt2316a_create_config_word(void *p) case 7: temp += 3 << 22; break; + + default: + break; } switch (azt2316a->cur_mpu401_irq) { @@ -580,6 +652,9 @@ azt2316a_create_config_word(void *p) case 10: temp += 1 << 27; break; + + default: + break; } switch (cd_irq) { @@ -595,16 +670,19 @@ azt2316a_create_config_word(void *p) case 15: temp += 1 << 31; break; + + default: + break; } azt2316a->config_word = temp; } static uint8_t -azt2316a_config_read(uint16_t addr, void *p) +azt2316a_config_read(uint16_t addr, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; - uint8_t temp = 0; + const azt2316a_t *azt2316a = (azt2316a_t *) priv; + uint8_t temp = 0; /* Some WSS config here + config change enable bit (setting bit 7 and writing back) */ @@ -635,6 +713,9 @@ azt2316a_config_read(uint16_t addr, void *p) case 3: temp = (azt2316a->config_word >> 24); break; + + default: + break; } } @@ -642,9 +723,9 @@ azt2316a_config_read(uint16_t addr, void *p) } static void -azt1605_config_write(uint16_t addr, uint8_t val, void *p) +azt1605_config_write(uint16_t addr, uint8_t val, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; uint8_t temp; if (addr == (azt2316a->cur_addr + 0x404)) { @@ -731,6 +812,9 @@ azt1605_config_write(uint16_t addr, uint8_t val, void *p) break; case 3: break; + + default: + break; } /* update sbprov2 configs */ sb_dsp_setaddr(&azt2316a->sb->dsp, azt2316a->cur_addr); @@ -743,9 +827,9 @@ azt1605_config_write(uint16_t addr, uint8_t val, void *p) } static void -azt2316a_config_write(uint16_t addr, uint8_t val, void *p) +azt2316a_config_write(uint16_t addr, uint8_t val, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; uint8_t temp; if (azt2316a->type == SB_SUBTYPE_CLONE_AZT1605_0X0C) { @@ -839,6 +923,9 @@ azt2316a_config_write(uint16_t addr, uint8_t val, void *p) azt2316a->cur_mpu401_irq = 10; /* else undefined? */ break; + + default: + break; } /* update sbprov2 configs */ sb_dsp_setaddr(&azt2316a->sb->dsp, azt2316a->cur_addr); @@ -852,9 +939,9 @@ azt2316a_config_write(uint16_t addr, uint8_t val, void *p) /* How it behaves when one or another is activated may affect games auto-detecting (and will also use more of the limited system resources!) */ void -azt2316a_enable_wss(uint8_t enable, void *p) +azt2316a_enable_wss(uint8_t enable, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; if (enable) azt2316a->cur_mode = 1; @@ -863,9 +950,9 @@ azt2316a_enable_wss(uint8_t enable, void *p) } static void -azt2316a_get_buffer(int32_t *buffer, int len, void *p) +azt2316a_get_buffer(int32_t *buffer, int len, void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; /* wss part */ ad1848_update(&azt2316a->ad1848); @@ -1182,9 +1269,9 @@ azt_init(const device_t *info) } static void -azt_close(void *p) +azt_close(void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; char *fn = NULL; FILE *f; uint8_t checksum = 0x7f; @@ -1217,9 +1304,9 @@ azt_close(void *p) } static void -azt_speed_changed(void *p) +azt_speed_changed(void *priv) { - azt2316a_t *azt2316a = (azt2316a_t *) p; + azt2316a_t *azt2316a = (azt2316a_t *) priv; ad1848_speed_changed(&azt2316a->ad1848); sb_speed_changed(azt2316a->sb); diff --git a/src/sound/snd_cmi8x38.c b/src/sound/snd_cmi8x38.c index ee37d7f26..ea81230a9 100644 --- a/src/sound/snd_cmi8x38.c +++ b/src/sound/snd_cmi8x38.c @@ -34,6 +34,8 @@ #include <86box/gameport.h> #include <86box/nmi.h> #include <86box/ui.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> enum { /* [23:16] = reg 0F [7:0] (reg 0C [31:24]) @@ -53,37 +55,67 @@ enum { TRAP_MAX }; -typedef struct { - uint8_t id, reg, always_run, playback_enabled, channels; +typedef struct cmi8x38_dma_t { + uint8_t id; + uint8_t reg; + uint8_t always_run; + uint8_t playback_enabled; + uint8_t channels; struct _cmi8x38_ *dev; - uint32_t sample_ptr, fifo_pos, fifo_end; - int32_t frame_count_dma, frame_count_fragment, sample_count_out; - uint8_t fifo[256], restart; + uint32_t sample_ptr; + uint32_t fifo_pos; + uint32_t fifo_end; + int32_t frame_count_dma; + int32_t frame_count_fragment; + int32_t sample_count_out; + uint8_t fifo[256]; + uint8_t restart; - int16_t out_fl, out_fr, out_rl, out_rr, out_c, out_lfe; - int vol_l, vol_r, pos; + int16_t out_fl; + int16_t out_fr; + int16_t out_rl; + int16_t out_rr; + int16_t out_c; + int16_t out_lfe; + int vol_l; + int vol_r; + int pos; int32_t buffer[SOUNDBUFLEN * 2]; uint64_t timer_latch; double dma_latch; - pc_timer_t dma_timer, poll_timer; + pc_timer_t dma_timer; + pc_timer_t poll_timer; } cmi8x38_dma_t; typedef struct _cmi8x38_ { uint32_t type; - uint16_t io_base, sb_base, opl_base, mpu_base; - uint8_t pci_regs[256], io_regs[256]; + uint16_t io_base; + uint16_t sb_base; + uint16_t opl_base; + uint16_t mpu_base; + uint8_t pci_regs[256]; + uint8_t io_regs[256]; int slot; sb_t *sb; - void *gameport, *io_traps[TRAP_MAX]; + void *gameport; + void *io_traps[TRAP_MAX]; cmi8x38_dma_t dma[2]; - uint16_t tdma_base_addr, tdma_base_count; - int tdma_8, tdma_16, tdma_mask, prev_mask, tdma_irq_mask; + uint16_t tdma_base_addr; + uint16_t tdma_base_count; + int tdma_8; + int tdma_16; + int tdma_mask; + int prev_mask; + int tdma_irq_mask; - int master_vol_l, master_vol_r, cd_vol_l, cd_vol_r; + int master_vol_l; + int master_vol_r; + int cd_vol_l; + int cd_vol_r; } cmi8x38_t; #ifdef ENABLE_CMI8X38_LOG @@ -138,7 +170,8 @@ cmi8x38_mpu_irq_update(void *priv, int set) static int cmi8x38_mpu_irq_pending(void *priv) { - cmi8x38_t *dev = (cmi8x38_t *) priv; + const cmi8x38_t *dev = (cmi8x38_t *) priv; + return dev->io_regs[0x12] & 0x01; } @@ -307,7 +340,7 @@ cmi8x38_sb_dma_writew(void *priv, uint16_t val) } static void -cmi8x38_dma_write(uint16_t addr, uint8_t val, void *priv) +cmi8x38_dma_write(uint16_t addr, UNUSED(uint8_t val), void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; @@ -348,7 +381,7 @@ cmi8x38_dma_write(uint16_t addr, uint8_t val, void *priv) } static void -cmi8x38_dma_mask_write(uint16_t addr, uint8_t val, void *priv) +cmi8x38_dma_mask_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; @@ -365,7 +398,7 @@ cmi8x38_dma_mask_write(uint16_t addr, uint8_t val, void *priv) } static void -cmi8338_io_trap(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) +cmi8338_io_trap(UNUSED(int size), uint16_t addr, uint8_t write, uint8_t val, void *priv) { cmi8x38_t *dev = (cmi8x38_t *) priv; @@ -390,9 +423,9 @@ cmi8338_io_trap(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv) static uint8_t cmi8x38_sb_mixer_read(uint16_t addr, void *priv) { - cmi8x38_t *dev = (cmi8x38_t *) priv; - sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; - uint8_t ret = sb_ct1745_mixer_read(addr, dev->sb); + cmi8x38_t *dev = (cmi8x38_t *) priv; + const sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; + uint8_t ret = sb_ct1745_mixer_read(addr, dev->sb); if (addr & 1) { if ((mixer->index == 0x0e) || (mixer->index >= 0xf0)) @@ -435,10 +468,15 @@ cmi8x38_sb_mixer_write(uint16_t addr, uint8_t val, void *priv) case 0xf8 ... 0xff: if (dev->type == CMEDIA_CMI8338) mixer->regs[mixer->index] = val; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xf1 ... 0xf7: return; + + default: + break; } sb_ct1745_mixer_write(addr, val, dev->sb); @@ -446,8 +484,8 @@ cmi8x38_sb_mixer_write(uint16_t addr, uint8_t val, void *priv) /* No [3F:47] controls. */ mixer->input_gain_L = 0; mixer->input_gain_R = 0; - mixer->output_gain_L = (double) 1.0; - mixer->output_gain_R = (double) 1.0; + mixer->output_gain_L = 1.0; + mixer->output_gain_R = 1.0; mixer->bass_l = 8; mixer->bass_r = 8; mixer->treble_l = 8; @@ -920,8 +958,8 @@ cmi8x38_remap(cmi8x38_t *dev) static uint8_t cmi8x38_pci_read(int func, int addr, void *priv) { - cmi8x38_t *dev = (cmi8x38_t *) priv; - uint8_t ret = 0xff; + const cmi8x38_t *dev = (cmi8x38_t *) priv; + uint8_t ret = 0xff; if (!func) { ret = dev->pci_regs[addr]; @@ -990,9 +1028,9 @@ cmi8x38_pci_write(int func, int addr, uint8_t val, void *priv) static void cmi8x38_update(cmi8x38_t *dev, cmi8x38_dma_t *dma) { - sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; - int32_t l = (dma->out_fl * mixer->voice_l) * mixer->master_l; - int32_t r = (dma->out_fr * mixer->voice_r) * mixer->master_r; + const sb_ct1745_mixer_t *mixer = &dev->sb->mixer_sb16; + int32_t l = (dma->out_fl * mixer->voice_l) * mixer->master_l; + int32_t r = (dma->out_fr * mixer->voice_r) * mixer->master_r; for (; dma->pos < sound_pos_global; dma->pos++) { dma->buffer[dma->pos * 2] = l; @@ -1201,8 +1239,14 @@ cmi8x38_poll(void *priv) return; } break; + + default: + break; } break; + + default: + break; } /* Feed silence if the FIFO is empty. */ diff --git a/src/sound/snd_cms.c b/src/sound/snd_cms.c index b451dea30..d33eba83a 100644 --- a/src/sound/snd_cms.c +++ b/src/sound/snd_cms.c @@ -10,17 +10,16 @@ #include <86box/io.h> #include <86box/snd_cms.h> #include <86box/sound.h> +#include <86box/plat_unused.h> void cms_update(cms_t *cms) { for (; cms->pos < sound_pos_global; cms->pos++) { - int c; - int d; int16_t out_l = 0; int16_t out_r = 0; - for (c = 0; c < 4; c++) { + for (uint8_t c = 0; c < 4; c++) { switch (cms->noisetype[c >> 1][c & 1]) { case 0: cms->noisefreq[c >> 1][c & 1] = MASTER_CLOCK / 256; @@ -34,11 +33,14 @@ cms_update(cms_t *cms) case 3: cms->noisefreq[c >> 1][c & 1] = cms->freq[c >> 1][(c & 1) * 3]; break; + + default: + break; } } - for (c = 0; c < 2; c++) { + for (uint8_t c = 0; c < 2; c++) { if (cms->regs[c][0x1C] & 1) { - for (d = 0; d < 6; d++) { + for (uint8_t d = 0; d < 6; d++) { if (cms->regs[c][0x14] & (1 << d)) { if (cms->stat[c][d]) out_l += (cms->vol[c][d][0] * 90); @@ -56,7 +58,7 @@ cms_update(cms_t *cms) out_r += (cms->vol[c][d][0] * 90); } } - for (d = 0; d < 2; d++) { + for (uint8_t d = 0; d < 2; d++) { cms->noisecount[c][d] += cms->noisefreq[c][d]; while (cms->noisecount[c][d] >= 24000) { cms->noisecount[c][d] -= 24000; @@ -73,9 +75,9 @@ cms_update(cms_t *cms) } void -cms_get_buffer(int32_t *buffer, int len, void *p) +cms_get_buffer(int32_t *buffer, int len, void *priv) { - cms_t *cms = (cms_t *) p; + cms_t *cms = (cms_t *) priv; cms_update(cms); @@ -86,9 +88,9 @@ cms_get_buffer(int32_t *buffer, int len, void *p) } void -cms_write(uint16_t addr, uint8_t val, void *p) +cms_write(uint16_t addr, uint8_t val, void *priv) { - cms_t *cms = (cms_t *) p; + cms_t *cms = (cms_t *) priv; int voice; int chip = (addr & 2) >> 1; @@ -138,19 +140,25 @@ cms_write(uint16_t addr, uint8_t val, void *p) cms->noisetype[chip][0] = val & 3; cms->noisetype[chip][1] = (val >> 4) & 3; break; + + default: + break; } break; case 0x6: case 0x7: cms->latched_data = val; break; + + default: + break; } } uint8_t -cms_read(uint16_t addr, void *p) +cms_read(uint16_t addr, void *priv) { - cms_t *cms = (cms_t *) p; + const cms_t *cms = (cms_t *) priv; switch (addr & 0xf) { case 0x1: @@ -162,12 +170,15 @@ cms_read(uint16_t addr, void *p) case 0xa: case 0xb: return cms->latched_data; + + default: + break; } return 0xff; } void * -cms_init(const device_t *info) +cms_init(UNUSED(const device_t *info)) { cms_t *cms = malloc(sizeof(cms_t)); memset(cms, 0, sizeof(cms_t)); @@ -179,9 +190,9 @@ cms_init(const device_t *info) } void -cms_close(void *p) +cms_close(void *priv) { - cms_t *cms = (cms_t *) p; + cms_t *cms = (cms_t *) priv; free(cms); } diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 58b217fbd..fff716e28 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -36,6 +36,8 @@ #include <86box/snd_ad1848.h> #include <86box/snd_opl.h> #include <86box/snd_sb.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #define CRYSTAL_NOEEPROM 0x100 @@ -133,14 +135,32 @@ typedef struct cs423x_t { ad1848_t ad1848; sb_t *sb; void *gameport; - void *i2c, *eeprom; + void *i2c; + void *eeprom; - uint16_t wss_base, opl_base, sb_base, ctrl_base, ram_addr, eeprom_size : 11, pnp_offset; - uint8_t type, ad1848_type, regs[8], indirect_regs[16], - eeprom_data[2048], ram_data[65536], ram_dl : 2, opl_wss : 1; - char *nvr_path; + uint16_t wss_base; + uint16_t opl_base; + uint16_t sb_base; + uint16_t ctrl_base; + uint16_t ram_addr; + uint16_t eeprom_size : 11; + uint16_t pnp_offset; + uint8_t type; + uint8_t ad1848_type; + uint8_t regs[8]; + uint8_t indirect_regs[16]; + uint8_t eeprom_data[2048]; + uint8_t ram_data[65536]; + uint8_t ram_dl : 2; + uint8_t opl_wss : 1; + char *nvr_path; - uint8_t pnp_enable : 1, key_pos : 5, slam_enable : 1, slam_state : 2, slam_ld, slam_reg; + uint8_t pnp_enable : 1; + uint8_t key_pos : 5; + uint8_t slam_enable : 1; + uint8_t slam_state : 2; + uint8_t slam_ld; + uint8_t slam_reg; isapnp_device_config_t *slam_config; } cs423x_t; @@ -198,6 +218,9 @@ cs423x_read(uint16_t addr, void *priv) ret |= 0x20; break; + + default: + break; } return ret; @@ -264,6 +287,9 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) dev->ad1848.wten = !!(val & 0x08); ad1848_updatevolmask(&dev->ad1848); break; + + default: + break; } dev->indirect_regs[dev->regs[3]] = val; break; @@ -274,7 +300,9 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) switch (val) { case 0x55: /* Disable PnP Key */ dev->pnp_enable = 0; - /* fall-through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x5a: /* Update Hardware Configuration Data */ cs423x_pnp_enable(dev, 0, 1); @@ -290,6 +318,9 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) case 0xaa: /* Download RAM */ dev->ram_dl = 1; break; + + default: + break; } break; @@ -306,6 +337,9 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) case 3: /* data */ dev->ram_data[dev->ram_addr++] = val; break; + + default: + break; } break; @@ -321,13 +355,16 @@ cs423x_write(uint16_t addr, uint8_t val, void *priv) case 7: /* Global Status */ return; + + default: + break; } dev->regs[reg] = val; } static void -cs423x_slam_write(uint16_t addr, uint8_t val, void *priv) +cs423x_slam_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { cs423x_t *dev = (cs423x_t *) priv; uint8_t idx; @@ -441,11 +478,17 @@ cs423x_slam_write(uint16_t addr, uint8_t val, void *priv) /* Activate or deactivate the device. */ dev->slam_config->activate = val & 0x01; break; + + default: + break; } /* Prepare for the next register, unless a two-byte read returns above. */ dev->slam_state = CRYSTAL_SLAM_INDEX; break; + + default: + break; } } @@ -467,7 +510,7 @@ cs423x_slam_enable(cs423x_t *dev, uint8_t enable) } static void -cs423x_ctxswitch_write(uint16_t addr, uint8_t val, void *priv) +cs423x_ctxswitch_write(uint16_t addr, UNUSED(uint8_t val), void *priv) { cs423x_t *dev = (cs423x_t *) priv; uint8_t ctx = (dev->regs[7] & 0x80); @@ -503,9 +546,9 @@ cs423x_ctxswitch_write(uint16_t addr, uint8_t val, void *priv) static void cs423x_get_buffer(int32_t *buffer, int len, void *priv) { - cs423x_t *dev = (cs423x_t *) priv; - int opl_wss = dev->opl_wss; - int32_t *opl_buf = NULL; + cs423x_t *dev = (cs423x_t *) priv; + int opl_wss = dev->opl_wss; + const int32_t *opl_buf = NULL; /* Output audio from the WSS codec, and also the OPL if we're in charge of it. */ ad1848_update(&dev->ad1848); @@ -542,7 +585,9 @@ cs423x_pnp_enable(cs423x_t *dev, uint8_t update_rom, uint8_t update_hwconfig) /* But wait! The TriGem Delhi-III BIOS sends command 0x55, and its behavior doesn't line up with real hardware (still listed in the POST summary and seen by software). Disable the PnP key disabling mechanism until someone figures something out. */ - // isapnp_enable_card(dev->pnp_card, ((dev->ram_data[0x4002] & 0x20) || !dev->pnp_enable) ? ISAPNP_CARD_NO_KEY : ISAPNP_CARD_ENABLE); +#if 0 + isapnp_enable_card(dev->pnp_card, ((dev->ram_data[0x4002] & 0x20) || !dev->pnp_enable) ? ISAPNP_CARD_NO_KEY : ISAPNP_CARD_ENABLE); +#endif if ((dev->ram_data[0x4002] & 0x20) || !dev->pnp_enable) pclog("CS423x: Attempted to disable PnP key\n"); } @@ -674,6 +719,9 @@ cs423x_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv } break; + + default: + break; } } @@ -764,6 +812,9 @@ cs423x_init(const device_t *info) dev->eeprom_data[26] = 0x38; dev->nvr_path = "cs4238b.nvr"; break; + + default: + break; } /* Load EEPROM contents from file if present. */ @@ -775,6 +826,9 @@ cs423x_init(const device_t *info) dev->gameport = gameport_add(((dev->type == CRYSTAL_CS4235) || (dev->type == CRYSTAL_CS4236B)) ? &gameport_pnp_device : &gameport_pnp_6io_device); break; + + default: + break; } /* Initialize I2C bus for the EEPROM. */ diff --git a/src/sound/snd_emu8k.c b/src/sound/snd_emu8k.c index 99a703d14..ad00461f1 100644 --- a/src/sound/snd_emu8k.c +++ b/src/sound/snd_emu8k.c @@ -17,81 +17,90 @@ #include <86box/sound.h> #include <86box/snd_emu8k.h> #include <86box/timer.h> +#include <86box/plat_unused.h> #if !defined FILTER_INITIAL && !defined FILTER_MOOG && !defined FILTER_CONSTANT -// #define FILTER_INITIAL +#if 0 +#define FILTER_INITIAL +#endif # define FILTER_MOOG -// #define FILTER_CONSTANT +#if 0 +#define FILTER_CONSTANT +#endif #endif #if !defined RESAMPLER_LINEAR && !defined RESAMPLER_CUBIC -// #define RESAMPLER_LINEAR +#if 0 +#define RESAMPLER_LINEAR +#endif # define RESAMPLER_CUBIC #endif -// #define EMU8K_DEBUG_REGISTERS +#if 0 +#define EMU8K_DEBUG_REGISTERS +#endif char *PORT_NAMES[][8] = { - /* Data 0 ( 0x620/0x622) */ + /* Data 0 ( 0x620/0x622) */ { - "AWE_CPF", - "AWE_PTRX", - "AWE_CVCF", - "AWE_VTFT", - "Unk-620-4", - "Unk-620-5", - "AWE_PSST", - "AWE_CSL", - }, - /* Data 1 0xA20 */ + "AWE_CPF", + "AWE_PTRX", + "AWE_CVCF", + "AWE_VTFT", + "Unk-620-4", + "Unk-620-5", + "AWE_PSST", + "AWE_CSL", + }, + /* Data 1 0xA20 */ { - "AWE_CCCA", - 0, - /* - "AWE_HWCF4" - "AWE_HWCF5" - "AWE_HWCF6" - "AWE_HWCF7" - "AWE_SMALR" - "AWE_SMARR" - "AWE_SMALW" - "AWE_SMARW" - "AWE_SMLD" - "AWE_SMRD" - "AWE_WC" - "AWE_HWCF1" - "AWE_HWCF2" - "AWE_HWCF3" - */ - 0, //"AWE_INIT1", - 0, //"AWE_INIT3", + "AWE_CCCA", + 0, + /* + "AWE_HWCF4" + "AWE_HWCF5" + "AWE_HWCF6" + "AWE_HWCF7" + "AWE_SMALR" + "AWE_SMARR" + "AWE_SMALW" + "AWE_SMARW" + "AWE_SMLD" + "AWE_SMRD" + "AWE_WC" + "AWE_HWCF1" + "AWE_HWCF2" + "AWE_HWCF3" + */ + 0, //"AWE_INIT1", + 0, //"AWE_INIT3", "AWE_ENVVOL", - "AWE_DCYSUSV", - "AWE_ENVVAL", - "AWE_DCYSUS", - }, - /* Data 2 0xA22 */ + "AWE_DCYSUSV", + "AWE_ENVVAL", + "AWE_DCYSUS", + }, + /* Data 2 0xA22 */ { - "AWE_CCCA", - 0, - 0, //"AWE_INIT2", - 0, //"AWE_INIT4", + "AWE_CCCA", + 0, + 0, //"AWE_INIT2", + 0, //"AWE_INIT4", "AWE_ATKHLDV", - "AWE_LFO1VAL", - "AWE_ATKHLD", - "AWE_LFO2VAL", - }, - /* Data 3 0xE20 */ + "AWE_LFO1VAL", + "AWE_ATKHLD", + "AWE_LFO2VAL", + }, + /* Data 3 0xE20 */ { - "AWE_IP", - "AWE_IFATN", - "AWE_PEFE", - "AWE_FMMOD", - "AWE_TREMFRQ", - "AWE_FM2FRQ2", - 0, - 0, - }, + "AWE_IP", + "AWE_IFATN", + "AWE_PEFE", + "AWE_FMMOD", + "AWE_TREMFRQ", + "AWE_FM2FRQ2", + 0, + 0, + }, }; enum { @@ -143,13 +152,13 @@ static int32_t env_attack_to_samples[128]; * In other words, the unit of the table is the 1/21845th of a dB per sample frame, to be added or * substracted to the accumulating value_db of the envelope. */ static int32_t env_decay_to_dbs_or_oct[128] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 32, - 33, 34, 36, 38, 39, 41, 43, 45, 49, 51, 53, 55, 58, 60, 63, 66, - 69, 72, 75, 78, 82, 85, 89, 93, 97, 102, 106, 111, 116, 121, 126, 132, - 138, 144, 150, 157, 164, 171, 179, 186, 195, 203, 212, 222, 232, 243, 253, 264, - 276, 288, 301, 315, 328, 342, 358, 374, 390, 406, 425, 444, 466, 485, 506, 528, - 553, 580, 602, 634, 660, 689, 721, 755, 780, 820, 849, 897, 932, 970, 1012, 1057, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 32, + 33, 34, 36, 38, 39, 41, 43, 45, 49, 51, 53, 55, 58, 60, 63, 66, + 69, 72, 75, 78, 82, 85, 89, 93, 97, 102, 106, 111, 116, 121, 126, 132, + 138, 144, 150, 157, 164, 171, 179, 186, 195, 203, 212, 222, 232, 243, 253, 264, + 276, 288, 301, 315, 328, 342, 358, 374, 390, 406, 425, 444, 466, 485, 506, 528, + 553, 580, 602, 634, 660, 689, 721, 755, 780, 820, 849, 897, 932, 970, 1012, 1057, 1106, 1160, 1219, 1285, 1321, 1399, 1441, 1534, 1585, 1640, 1698, 1829, 1902, 1981, 2068, 2162 }; @@ -158,17 +167,19 @@ static int32_t env_decay_to_dbs_or_oct[128] = { * I tried calculating it using the instructions in awe32p10 from Judge Dredd, but the formula there * is wrong. * + */ +#if 0 static int32_t env_decay_to_millis[128] = { -0, 45120, 22614, 15990, 11307, 9508, 7995, 6723, 5653, 5184, 4754, 4359, 3997, 3665, 3361, 3082, -2828, 2765, 2648, 2535, 2428, 2325, 2226, 2132, 2042, 1955, 1872, 1793, 1717, 1644, 1574, 1507, -1443, 1382, 1324, 1267, 1214, 1162, 1113, 1066, 978, 936, 897, 859, 822, 787, 754, 722, -691, 662, 634, 607, 581, 557, 533, 510, 489, 468, 448, 429, 411, 393, 377, 361, -345, 331, 317, 303, 290, 278, 266, 255, 244, 234, 224, 214, 205, 196, 188, 180, -172, 165, 158, 151, 145, 139, 133, 127, 122, 117, 112, 107, 102, 98, 94, 90, -86, 82, 79, 75, 72, 69, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45, -43, 41, 39, 37, 36, 34, 33, 31, 30, 29, 28, 26, 25, 24, 23, 22, + 0, 45120, 22614, 15990, 11307, 9508, 7995, 6723, 5653, 5184, 4754, 4359, 3997, 3665, 3361, 3082, + 2828, 2765, 2648, 2535, 2428, 2325, 2226, 2132, 2042, 1955, 1872, 1793, 1717, 1644, 1574, 1507, + 1443, 1382, 1324, 1267, 1214, 1162, 1113, 1066, 978, 936, 897, 859, 822, 787, 754, 722, + 691, 662, 634, 607, 581, 557, 533, 510, 489, 468, 448, 429, 411, 393, 377, 361, + 345, 331, 317, 303, 290, 278, 266, 255, 244, 234, 224, 214, 205, 196, 188, 180, + 172, 165, 158, 151, 145, 139, 133, 127, 122, 117, 112, 107, 102, 98, 94, 90, + 86, 82, 79, 75, 72, 69, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45, + 43, 41, 39, 37, 36, 34, 33, 31, 30, 29, 28, 26, 25, 24, 23, 22, }; -*/ +#endif /* Table represeting the LFO waveform (signed 16bits with 32768 max int. >> 15 to move back to +/-1 range). */ static int32_t lfotable[65536]; @@ -348,7 +359,9 @@ EMU8K_READ_INTERP_CUBIC(emu8k_t *emu8k, uint32_t int_addr, uint16_t fract) * the card could use two oscillators (usually 31 and 32) where it would * be writing the OPL3 output, and to which, chorus and reverb could be applied to get * those effects for OPL3 sounds.*/ - // if ((addr & EMU8K_FM_MEM_ADDRESS) == EMU8K_FM_MEM_ADDRESS) {} +#if 0 + if ((addr & EMU8K_FM_MEM_ADDRESS) == EMU8K_FM_MEM_ADDRESS) {} +#endif /* This is cubic interpolation. * Not the same than 3-point interpolation, but a better approximation than linear @@ -383,9 +396,9 @@ EMU8K_WRITE(emu8k_t *emu8k, uint32_t addr, uint16_t val) } uint16_t -emu8k_inw(uint16_t addr, void *p) +emu8k_inw(uint16_t addr, void *priv) { - emu8k_t *emu8k = (emu8k_t *) p; + emu8k_t *emu8k = (emu8k_t *) priv; uint16_t ret = 0xffff; #ifdef EMU8K_DEBUG_REGISTERS @@ -557,6 +570,9 @@ emu8k_inw(uint16_t addr, void *p) case 7: READ16(addr, emu8k->voice[emu8k->cur_voice].csl); return ret; + + default: + break; } break; @@ -611,6 +627,9 @@ emu8k_inw(uint16_t addr, void *p) | ((emu8k->hwcf3 & 0x08) ? 0x20 : 0) | ((emu8k->hwcf3 & 0x10) ? 0x80 : 0); case 31: /*Configuration Word 3*/ return emu8k->hwcf2 & 0x1f; + + default: + break; } break; @@ -631,6 +650,9 @@ emu8k_inw(uint16_t addr, void *p) case 7: return emu8k->voice[emu8k->cur_voice].dcysus; + + default: + break; } break; @@ -690,6 +712,9 @@ emu8k_inw(uint16_t addr, void *p) the amount of calls and wait time */ case 27: /*Sample Counter ( 44Khz clock) */ return emu8k->wc; + + default: + break; } break; @@ -710,6 +735,9 @@ emu8k_inw(uint16_t addr, void *p) case 7: return emu8k->voice[emu8k->cur_voice].lfo2val; + + default: + break; } break; @@ -738,6 +766,9 @@ emu8k_inw(uint16_t addr, void *p) case 7: /*ID?*/ return 0x1c | ((emu8k->id & 0x0002) ? 0xff02 : 0); + + default: + break; } break; @@ -749,15 +780,18 @@ emu8k_inw(uint16_t addr, void *p) * cubic player has a similar code, where it waits until value & 0x1000 is nonzero, and then waits again until it changes to zero.*/ random_helper = (random_helper + 1) & 0x1F; return ((0x80 | random_helper) << 8) | (emu8k->cur_reg << 5) | emu8k->cur_voice; + + default: + break; } emu8k_log("EMU8K READ : Unknown register read: %04X-%02X(%d/%d) \n", addr, (emu8k->cur_reg << 5) | emu8k->cur_voice, emu8k->cur_reg, emu8k->cur_voice); return 0xffff; } void -emu8k_outw(uint16_t addr, uint16_t val, void *p) +emu8k_outw(uint16_t addr, uint16_t val, void *priv) { - emu8k_t *emu8k = (emu8k_t *) p; + emu8k_t *emu8k = (emu8k_t *) priv; /*TODO: I would like to not call this here, but i found it was needed or else cubic player would not finish opening (take a looot more of time than usual). * Basically, being here means that the audio is generated in the emulation thread, instead of the audio thread.*/ @@ -879,6 +913,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) /* TODO: Should we update only on MSB update, or this could be used as some sort of hack by applications? */ emu8k->voice[emu8k->cur_voice].loop_end.int_address = emu8k->voice[emu8k->cur_voice].csl & EMU8K_MEM_ADDRESS_MASK; return; + + default: + break; } break; @@ -933,6 +970,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 31: emu8k->hwcf3 = val; return; + + default: + break; } break; @@ -966,17 +1006,29 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 0x9: emu8k->reverb_engine.reflections[0].feedback = (val & 0xF) / 15.0; break; - case 0xB: // emu8k->reverb_engine.reflections[0].feedback_r = (val&0xF)/15.0; + case 0xB: +#if 0 + emu8k->reverb_engine.reflections[0].feedback_r = (val&0xF)/15.0; +#endif break; case 0x11: emu8k->reverb_engine.reflections[1].feedback = (val & 0xF) / 15.0; break; - case 0x13: // emu8k->reverb_engine.reflections[1].feedback_r = (val&0xF)/15.0; + case 0x13: +#if 0 + emu8k->reverb_engine.reflections[1].feedback_r = (val&0xF)/15.0; +#endif break; case 0x19: emu8k->reverb_engine.reflections[2].feedback = (val & 0xF) / 15.0; break; - case 0x1B: // emu8k->reverb_engine.reflections[2].feedback_r = (val&0xF)/15.0; + case 0x1B: +#if 0 + emu8k->reverb_engine.reflections[2].feedback_r = (val&0xF)/15.0; +#endif + break; + + default: break; } } @@ -998,7 +1050,13 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 1: emu8k->reverb_engine.refl_in_amp = val & 0xFF; break; - case 3: // emu8k->reverb_engine.refl_in_amp_r = val&0xFF; + case 3: +#if 0 + emu8k->reverb_engine.refl_in_amp_r = val&0xFF; +#endif + break; + + default: break; } } @@ -1105,6 +1163,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) } } return; + + default: + break; } break; @@ -1180,6 +1241,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) EMU8K_WRITE(emu8k, emu8k->smarw, val); emu8k->smarw++; return; + + default: + break; } break; @@ -1230,17 +1294,29 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 0x1: emu8k->reverb_engine.reflections[3].feedback = (val & 0xF) / 15.0; break; - case 0x3: // emu8k->reverb_engine.reflections[3].feedback_r = (val&0xF)/15.0; + case 0x3: +#if 0 + emu8k->reverb_engine.reflections[3].feedback_r = (val&0xF)/15.0; +#endif break; case 0x9: emu8k->reverb_engine.reflections[4].feedback = (val & 0xF) / 15.0; break; - case 0xb: // emu8k->reverb_engine.reflections[4].feedback_r = (val&0xF)/15.0; + case 0xb: +#if 0 + emu8k->reverb_engine.reflections[4].feedback_r = (val&0xF)/15.0; +#endif break; case 0x11: emu8k->reverb_engine.reflections[5].feedback = (val & 0xF) / 15.0; break; - case 0x13: // emu8k->reverb_engine.reflections[5].feedback_r = (val&0xF)/15.0; + case 0x13: +#if 0 + emu8k->reverb_engine.reflections[5].feedback_r = (val&0xF)/15.0; +#endif + break; + + default: break; } } @@ -1261,6 +1337,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 0x1F: emu8k->reverb_engine.link_return_amp = val & 0xFF; break; + + default: + break; } } return; @@ -1346,6 +1425,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) emu8k->voice[emu8k->cur_voice].lfo2_delay_samples = LFOxVAL_TO_EMU_SAMPLES(val); return; + + default: + break; } break; @@ -1429,6 +1511,9 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) case 7: /*ID? I believe that this allows applications to know if the emu is in use by another application */ emu8k->id = val; return; + + default: + break; } break; @@ -1436,30 +1521,33 @@ emu8k_outw(uint16_t addr, uint16_t val, void *p) emu8k->cur_voice = (val & 31); emu8k->cur_reg = ((val >> 5) & 7); return; + + default: + break; } emu8k_log("EMU8K WRITE: Unknown register write: %04X-%02X(%d/%d): %04X \n", addr, (emu8k->cur_reg) << 5 | emu8k->cur_voice, emu8k->cur_reg, emu8k->cur_voice, val); } uint8_t -emu8k_inb(uint16_t addr, void *p) +emu8k_inb(uint16_t addr, void *priv) { /* Reading a single byte is a feature that at least Impulse tracker uses, * but only on detection code and not for odd addresses.*/ if (addr & 1) - return emu8k_inw(addr & ~1, p) >> 1; - return emu8k_inw(addr, p) & 0xff; + return emu8k_inw(addr & ~1, priv) >> 1; + return emu8k_inw(addr, priv) & 0xff; } void -emu8k_outb(uint16_t addr, uint8_t val, void *p) +emu8k_outb(uint16_t addr, uint8_t val, void *priv) { /* TODO: AWE32 docs says that you cannot write in bytes, but if * an app were to use this implementation, the content of the LS Byte would be lost.*/ if (addr & 1) - emu8k_outw(addr & ~1, val << 8, p); + emu8k_outw(addr & ~1, val << 8, priv); else - emu8k_outw(addr, val, p); + emu8k_outw(addr, val, priv); } /* TODO: This is not a correct emulation, just a workalike implementation. */ @@ -1468,7 +1556,9 @@ emu8k_work_chorus(int32_t *inbuf, int32_t *outbuf, emu8k_chorus_eng_t *engine, i { for (int pos = 0; pos < count; pos++) { double lfo_inter1 = chortable[engine->lfo_pos.int_address]; - // double lfo_inter2 = chortable[(engine->lfo_pos.int_address+1)&0xFFFF]; +#if 0 + double lfo_inter2 = chortable[(engine->lfo_pos.int_address+1)&0xFFFF]; +#endif double offset_lfo = lfo_inter1; //= lfo_inter1 + ((lfo_inter2-lfo_inter1)*engine->lfo_pos.fract_address/65536.0); offset_lfo *= engine->lfodepth_multip; @@ -1567,10 +1657,14 @@ emu8k_reverb_tail_work(emu8k_reverb_combfilter_t *comb, emu8k_reverb_combfilter_ /* store new value in delayed buffer */ comb->reflection[comb->read_pos] = in; - // output = emu8k_reverb_allpass_work(&allpasses[0],output); +#if 0 + output = emu8k_reverb_allpass_work(&allpasses[0],output); +#endif output = emu8k_reverb_diffuser_work(&allpasses[1], output); output = emu8k_reverb_diffuser_work(&allpasses[2], output); - // output = emu8k_reverb_allpass_work(&allpasses[3],output); +#if 0 + output = emu8k_reverb_allpass_work(&allpasses[3],output); +#endif if (++comb->read_pos >= comb->bufsize) comb->read_pos = 0; @@ -1636,7 +1730,7 @@ emu8k_work_reverb(int32_t *inbuf, int32_t *outbuf, emu8k_reverb_eng_t *engine, i } } void -emu8k_work_eq(int32_t *inoutbuf, int count) +emu8k_work_eq(UNUSED(int32_t *inoutbuf), UNUSED(int count)) { // TODO: Work EQ over buf } @@ -1656,9 +1750,11 @@ emu8k_vol_slide(emu8k_slide_t *slide, int32_t target) return slide->last; } -// int32_t old_pitch[32]={0}; -// int32_t old_cut[32]={0}; -// int32_t old_vol[32]={0}; +#if 0 +int32_t old_pitch[32] = { 0 }; +int32_t old_cut[32] = { 0 }; +int32_t old_vol[32] = { 0 }; +#endif void emu8k_update(emu8k_t *emu8k) { @@ -1861,6 +1957,9 @@ emu8k_update(emu8k_t *emu8k) case ENV_STOPPED: attenuation = 0x1FFFFF; break; + + default: + break; } emu8k_envelope_t *modenv = &emu_voice->mod_envelope; @@ -1912,6 +2011,9 @@ emu8k_update(emu8k_t *emu8k) modenv->state = ENV_SUSTAIN; } break; + + default: + break; } /* run lfos */ @@ -2009,11 +2111,13 @@ emu8k_update(emu8k_t *emu8k) emu_voice->ccca = (((uint32_t) emu_voice->ccca_qcontrol) << 24) | emu_voice->addr.int_address; emu_voice->cpf_curr_frac_addr = emu_voice->addr.fract_address; - // if ( emu_voice->cvcf_curr_volume != old_vol[c]) { - // pclog("EMUVOL (%d):%d\n", c, emu_voice->cvcf_curr_volume); - // old_vol[c]=emu_voice->cvcf_curr_volume; - // } - // pclog("EMUFILT :%d\n", emu_voice->cvcf_curr_filt_ctoff); +#if 0 + if (emu_voice->cvcf_curr_volume != old_vol[c]) { + pclog("EMUVOL (%d):%d\n", c, emu_voice->cvcf_curr_volume); + old_vol[c]=emu_voice->cvcf_curr_volume; + } + pclog("EMUFILT :%d\n", emu_voice->cvcf_curr_filt_ctoff); +#endif } buf = &emu8k->buffer[emu8k->pos * 2]; @@ -2142,8 +2246,10 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram) * Important: Using 65535 as max output value because this is intended to be used with the volume target register! */ out = 65535.0; for (c = 0; c < 0x10000; c++) { - // double db = -(c*6.0205999/65535.0)*16.0; - // out = powf(10.f,db/20.f) * 65536.0; +#if 0 + double db = -(c*6.0205999/65535.0)*16.0; + out = powf(10.f,db/20.f) * 65536.0; +#endif env_vol_db_to_vol_target[c] = (int32_t) out; /* calculated from the 65536th root of 65536 */ out /= 1.00016923970; diff --git a/src/sound/snd_gus.c b/src/sound/snd_gus.c index 9dfd7269b..c7e6d39f9 100644 --- a/src/sound/snd_gus.c +++ b/src/sound/snd_gus.c @@ -17,6 +17,8 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/snd_ad1848.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> enum { MIDI_INT_RECEIVE = 0x01, @@ -48,28 +50,42 @@ typedef struct gus_t { int reset; int global; - uint32_t addr, dmaaddr; + uint32_t addr; + uint32_t dmaaddr; int voice; - uint32_t start[32], end[32], cur[32]; - uint32_t startx[32], endx[32], curx[32]; - int rstart[32], rend[32]; + uint32_t start[32]; + uint32_t end[32]; + uint32_t cur[32]; + uint32_t startx[32]; + uint32_t endx[32]; + uint32_t curx[32]; + int rstart[32]; + int rend[32]; int rcur[32]; uint16_t freq[32]; uint16_t rfreq[32]; uint8_t ctrl[32]; uint8_t rctrl[32]; int curvol[32]; - int pan_l[32], pan_r[32]; - int t1on, t2on; + int pan_l[32]; + int pan_r[32]; + int t1on; + int t2on; uint8_t tctrl; - uint16_t t1, t2, t1l, t2l; - uint8_t irqstatus, irqstatus2; + uint16_t t1; + uint16_t t2; + uint16_t t1l; + uint16_t t2l; + uint8_t irqstatus; + uint8_t irqstatus2; uint8_t adcommand; - int waveirqs[32], rampirqs[32]; + int waveirqs[32]; + int rampirqs[32]; int voices; uint8_t dmactrl; - int32_t out_l, out_r; + int32_t out_l; + int32_t out_r; int16_t buffer[2][SOUNDBUFLEN]; int pos; @@ -82,27 +98,41 @@ typedef struct gus_t { int irqnext; - pc_timer_t timer_1, timer_2; + pc_timer_t timer_1; + pc_timer_t timer_2; - int irq, dma, irq_midi; + int irq; + int dma; + int irq_midi; uint16_t base; int latch_enable; - uint8_t sb_2xa, sb_2xc, sb_2xe; + uint8_t sb_2xa; + uint8_t sb_2xc; + uint8_t sb_2xe; uint8_t sb_ctrl; int sb_nmi; uint8_t reg_ctrl; - uint8_t ad_status, ad_data; + uint8_t ad_status; + uint8_t ad_data; uint8_t ad_timer_ctrl; - uint8_t midi_ctrl, midi_status, midi_queue[64], midi_data; - int midi_r, midi_w; - int uart_in, uart_out, sysex; + uint8_t midi_ctrl; + uint8_t midi_status; + uint8_t midi_queue[64]; + uint8_t midi_data; + int midi_r; + int midi_w; + int uart_in; + int uart_out; + int sysex; - uint8_t gp1, gp2; - uint16_t gp1_addr, gp2_addr; + uint8_t gp1; + uint8_t gp2; + uint16_t gp1_addr; + uint16_t gp2_addr; uint8_t usrr; @@ -127,13 +157,12 @@ double vol16bit[4096]; void gus_update_int_status(gus_t *gus) { - int c; int irq_pending = 0; int midi_irq_pending = 0; gus->irqstatus &= ~0x60; gus->irqstatus2 = 0xE0; - for (c = 0; c < 32; c++) { + for (uint8_t c = 0; c < 32; c++) { if (gus->waveirqs[c]) { gus->irqstatus2 = 0x60 | c; if (gus->rampirqs[c]) @@ -199,9 +228,9 @@ gus_midi_update_int_status(gus_t *gus) } void -writegus(uint16_t addr, uint8_t val, void *p) +writegus(uint16_t addr, uint8_t val, void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; int c; int d; int old; @@ -299,6 +328,9 @@ writegus(uint16_t addr, uint8_t val, void *p) gus->tctrl = val; gus_update_int_status(gus); break; + + default: + break; } break; case 0x305: /*Global high*/ @@ -479,6 +511,9 @@ writegus(uint16_t addr, uint8_t val, void *p) case 0x4c: /*Reset*/ gus->reset = val; break; + + default: + break; } break; case 0x307: /*DRAM access*/ @@ -566,6 +601,9 @@ writegus(uint16_t addr, uint8_t val, void *p) break; case 6: break; + + default: + break; } break; @@ -589,7 +627,9 @@ writegus(uint16_t addr, uint8_t val, void *p) else if (gus->irq != -1) picint(1 << gus->irq); } - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x20d: gus->sb_2xc = val; break; @@ -619,13 +659,16 @@ writegus(uint16_t addr, uint8_t val, void *p) } #endif break; + + default: + break; } } uint8_t -readgus(uint16_t addr, void *p) +readgus(uint16_t addr, void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; uint8_t val = 0xff; uint16_t port; @@ -717,6 +760,9 @@ readgus(uint16_t addr, void *p) case 0x0f: val = 0xff; break; + + default: + break; } break; case 0x305: /*Global high*/ @@ -777,6 +823,9 @@ readgus(uint16_t addr, void *p) case 0x0f: val = 0xff; break; + + default: + break; } break; case 0x306: @@ -787,7 +836,6 @@ readgus(uint16_t addr, void *p) val = 0xff; /*Pre 3.7 - no mixer*/ break; - break; case 0x307: /*DRAM access*/ val = gus->ram[gus->addr]; gus->addr &= 0xFFFFF; @@ -813,6 +861,9 @@ readgus(uint16_t addr, void *p) case 4: val = gus->gp2_addr; break; + + default: + break; } break; @@ -848,14 +899,17 @@ readgus(uint16_t addr, void *p) case 0x20A: val = gus->adcommand; break; + + default: + break; } return val; } void -gus_poll_timer_1(void *p) +gus_poll_timer_1(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; timer_advance_u64(&gus->timer_1, (uint64_t) (TIMER_USEC * 80)); if (gus->t1on) { @@ -879,9 +933,9 @@ gus_poll_timer_1(void *p) } void -gus_poll_timer_2(void *p) +gus_poll_timer_2(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; timer_advance_u64(&gus->timer_2, (uint64_t) (TIMER_USEC * 320)); if (gus->t2on) { @@ -922,9 +976,9 @@ gus_update(gus_t *gus) } void -gus_poll_wave(void *p) +gus_poll_wave(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; uint32_t addr; int16_t v; int32_t vl; @@ -1055,9 +1109,9 @@ gus_poll_wave(void *p) } static void -gus_get_buffer(int32_t *buffer, int len, void *p) +gus_get_buffer(int32_t *buffer, int len, void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; #if defined(DEV_BRANCH) && defined(USE_GUSMAX) if (gus->max_ctrl) @@ -1121,7 +1175,7 @@ gus_input_sysex(void *p, uint8_t *buffer, uint32_t len, int abort) } void * -gus_init(const device_t *info) +gus_init(UNUSED(const device_t *info)) { int c; double out = 1.0; @@ -1180,18 +1234,18 @@ gus_init(const device_t *info) } void -gus_close(void *p) +gus_close(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; free(gus->ram); free(gus); } void -gus_speed_changed(void *p) +gus_speed_changed(void *priv) { - gus_t *gus = (gus_t *) p; + gus_t *gus = (gus_t *) priv; if (gus->voices < 14) gus->samp_latch = (uint64_t) (TIMER_USEC * (1000000.0 / 44100.0)); diff --git a/src/sound/snd_lpt_dac.c b/src/sound/snd_lpt_dac.c index c0712d8be..8fb526f14 100644 --- a/src/sound/snd_lpt_dac.c +++ b/src/sound/snd_lpt_dac.c @@ -11,11 +11,13 @@ #include <86box/machine.h> #include <86box/sound.h> #include <86box/timer.h> +#include <86box/plat_unused.h> typedef struct lpt_dac_t { void *lpt; - uint8_t dac_val_l, dac_val_r; + uint8_t dac_val_l; + uint8_t dac_val_r; int is_stereo; int channel; @@ -34,9 +36,9 @@ dac_update(lpt_dac_t *lpt_dac) } static void -dac_write_data(uint8_t val, void *p) +dac_write_data(uint8_t val, void *priv) { - lpt_dac_t *lpt_dac = (lpt_dac_t *) p; + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; if (lpt_dac->is_stereo) { if (lpt_dac->channel) @@ -49,24 +51,24 @@ dac_write_data(uint8_t val, void *p) } static void -dac_write_ctrl(uint8_t val, void *p) +dac_write_ctrl(uint8_t val, void *priv) { - lpt_dac_t *lpt_dac = (lpt_dac_t *) p; + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; if (lpt_dac->is_stereo) lpt_dac->channel = val & 0x01; } static uint8_t -dac_read_status(void *p) +dac_read_status(UNUSED(void *priv)) { return 0x0f; } static void -dac_get_buffer(int32_t *buffer, int len, void *p) +dac_get_buffer(int32_t *buffer, int len, void *priv) { - lpt_dac_t *lpt_dac = (lpt_dac_t *) p; + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; dac_update(lpt_dac); @@ -100,9 +102,9 @@ dac_stereo_init(void *lpt) return lpt_dac; } static void -dac_close(void *p) +dac_close(void *priv) { - lpt_dac_t *lpt_dac = (lpt_dac_t *) p; + lpt_dac_t *lpt_dac = (lpt_dac_t *) priv; free(lpt_dac); } diff --git a/src/sound/snd_lpt_dss.c b/src/sound/snd_lpt_dss.c index 9ae2ffdbe..bd794fffb 100644 --- a/src/sound/snd_lpt_dss.c +++ b/src/sound/snd_lpt_dss.c @@ -11,15 +11,17 @@ #include <86box/machine.h> #include <86box/sound.h> #include <86box/timer.h> +#include <86box/plat_unused.h> typedef struct dss_t { void *lpt; uint8_t fifo[16]; - int read_idx, write_idx; + int read_idx; + int write_idx; - uint8_t dac_val, - status; + uint8_t dac_val; + uint8_t status; pc_timer_t timer; @@ -49,9 +51,9 @@ dss_update_status(dss_t *dss) } static void -dss_write_data(uint8_t val, void *p) +dss_write_data(uint8_t val, void *priv) { - dss_t *dss = (dss_t *) p; + dss_t *dss = (dss_t *) priv; if ((dss->write_idx - dss->read_idx) < 16) { dss->fifo[dss->write_idx & 15] = val; @@ -61,22 +63,23 @@ dss_write_data(uint8_t val, void *p) } static void -dss_write_ctrl(uint8_t val, void *p) +dss_write_ctrl(UNUSED(uint8_t val), UNUSED(void *priv)) { + // } static uint8_t -dss_read_status(void *p) +dss_read_status(void *priv) { - dss_t *dss = (dss_t *) p; + const dss_t *dss = (dss_t *) priv; return dss->status | 0x0f; } static void -dss_get_buffer(int32_t *buffer, int len, void *p) +dss_get_buffer(int32_t *buffer, int len, void *priv) { - dss_t *dss = (dss_t *) p; + dss_t *dss = (dss_t *) priv; int16_t val; float fval; @@ -84,7 +87,7 @@ dss_get_buffer(int32_t *buffer, int len, void *p) for (int c = 0; c < len * 2; c += 2) { fval = dss_iir((float) dss->buffer[c >> 1]); - val = (float) fval; + val = fval; buffer[c] += val; buffer[c + 1] += val; @@ -94,9 +97,9 @@ dss_get_buffer(int32_t *buffer, int len, void *p) } static void -dss_callback(void *p) +dss_callback(void *priv) { - dss_t *dss = (dss_t *) p; + dss_t *dss = (dss_t *) priv; dss_update(dss); @@ -123,9 +126,9 @@ dss_init(void *lpt) return dss; } static void -dss_close(void *p) +dss_close(void *priv) { - dss_t *dss = (dss_t *) p; + dss_t *dss = (dss_t *) priv; free(dss); } diff --git a/src/sound/snd_mpu401.c b/src/sound/snd_mpu401.c index 0758393cc..d9e51df29 100644 --- a/src/sound/snd_mpu401.c +++ b/src/sound/snd_mpu401.c @@ -38,6 +38,7 @@ #include <86box/timer.h> #include <86box/snd_mpu401.h> #include <86box/sound.h> +#include <86box/plat_unused.h> static uint32_t MPUClockBase[8] = { 48, 72, 96, 120, 144, 168, 192 }; static uint8_t cth_data[16] = { 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0 }; @@ -52,7 +53,7 @@ int mpu401_standalone_enable = 0; static void MPU401_WriteCommand(mpu_t *mpu, uint8_t val); static void MPU401_IntelligentOut(mpu_t *mpu, uint8_t track); static void MPU401_EOIHandler(void *priv); -static void MPU401_EOIHandlerDispatch(void *p); +static void MPU401_EOIHandlerDispatch(void *priv); static void MPU401_NotesOff(mpu_t *mpu, int i); #ifdef ENABLE_MPU401_LOG @@ -137,7 +138,7 @@ MPU401_RunClock(mpu_t *mpu) } static void -MPU401_QueueByteEx(mpu_t *mpu, uint8_t data, int irq) +MPU401_QueueByteEx(mpu_t *mpu, uint8_t data, UNUSED(int irq)) { if (mpu->state.block_ack) { mpu->state.block_ack = 0; @@ -186,7 +187,7 @@ MPU401_IRQPending(mpu_t *mpu) } static void -MPU401_RecQueueBuffer(mpu_t *mpu, uint8_t *buf, uint32_t len, int block) +MPU401_RecQueueBuffer(mpu_t *mpu, uint8_t *buf, uint32_t len, UNUSED(int block)) { uint32_t cnt = 0; int pos; @@ -405,6 +406,9 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) mpu->clock.measure_counter = mpu->clock.meas_old; mpu->clock.cth_counter = mpu->clock.cth_old; break; + + default: + break; } switch (val & 0xc) { /* Playing */ case 0x4: /* Stop */ @@ -418,6 +422,9 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) mpu->state.playing = 1; MPU401_StartClock(mpu); break; + + default: + break; } switch (val & 0x30) { /* Recording */ case 0: /* check if it waited for MIDI RT command */ @@ -450,6 +457,9 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) MPU401_StartClock(mpu); } break; + + default: + break; } } MPU401_QueueByte(mpu, MSG_MPU_ACK); @@ -679,8 +689,11 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) return; break; - /* default: - mpu401_log("MPU-401:Unhandled command %X",val); */ + default: +#if 0 + mpu401_log("MPU-401:Unhandled command %X",val); +#endif + break; } MPU401_QueueByte(mpu, MSG_MPU_ACK); @@ -793,7 +806,9 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) break; case 0xf0: - /* mpu401_log("MPU-401:Illegal WSD byte\n"); */ +#if 0 + mpu401_log("MPU-401:Illegal WSD byte\n"); +#endif mpu->state.wsd = 0; mpu->state.track = mpu->state.old_track; return; @@ -900,6 +915,9 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) mpu->state.data_onoff = -1; mpu->state.cond_req = 0; break; + + default: + break; } return; } @@ -944,7 +962,9 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) if (val == 0xf9) mpu->clock.measure_counter = 0; } else { - /* mpu401_log("MPU-401:Illegal message"); */ +#if 0 + mpu401_log("MPU-401:Illegal message"); +#endif mpu->playbuf[mpu->state.track].type = T_OVERFLOW; } mpu->state.data_onoff = -1; @@ -969,6 +989,9 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) MPU401_EOIHandler(mpu); } break; + + default: + break; } return; @@ -1022,6 +1045,9 @@ MPU401_IntelligentOut(mpu_t *mpu, uint8_t track) return; } break; + + default: + break; } if (retrigger) { midi_raw_out_byte(0x80 | chan); @@ -1130,7 +1156,7 @@ MPU401_EOIHandlerDispatch(void *priv) } static void -imf_write(uint16_t addr, uint8_t val, void *priv) +imf_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), UNUSED(void *priv)) { mpu401_log("IMF:Wr %4X,%X\n", addr, val); } @@ -1245,6 +1271,9 @@ mpu401_write(uint16_t addr, uint8_t val, void *priv) MPU401_WriteCommand(mpu, val); mpu401_log("Write Command (0x331) %x\n", val); break; + + default: + break; } } @@ -1269,6 +1298,9 @@ mpu401_read(uint16_t addr, void *priv) mpu401_log("Read Status (0x331) %x\n", ret); break; + + default: + break; } /* mpu401_log("MPU401 Read Port %04X, ret %x\n", addr, ret); */ @@ -1520,8 +1552,11 @@ MPU401_InputMsg(void *p, uint8_t *msg, uint32_t len) } } } - break; } + break; + + default: + break; } } if ((msg[0] >= 0xf0) || (mpu->state.midi_mask & (1 << chan))) { @@ -1617,9 +1652,16 @@ MPU401_InputMsg(void *p, uint8_t *msg, uint32_t len) if (mpu->filter.rt_out) midi_raw_out_rt_byte(msg[0]); break; + + default: + break; } return; } + break; + + default: + break; } } if (send_thru && mpu->midi_thru) { @@ -1728,17 +1770,17 @@ mpu401_device_add(void) } static uint8_t -mpu401_mca_read(int port, void *p) +mpu401_mca_read(int port, void *priv) { - mpu_t *mpu = (mpu_t *) p; + const mpu_t *mpu = (mpu_t *) priv; return mpu->pos_regs[port & 7]; } static void -mpu401_mca_write(int port, uint8_t val, void *p) +mpu401_mca_write(int port, uint8_t val, void *priv) { - mpu_t *mpu = (mpu_t *) p; + mpu_t *mpu = (mpu_t *) priv; uint16_t addr; if (port < 0x102) @@ -1762,7 +1804,7 @@ mpu401_mca_write(int port, uint8_t val, void *p) } static uint8_t -mpu401_mca_feedb(void *p) +mpu401_mca_feedb(UNUSED(void *priv)) { return 1; } diff --git a/src/sound/snd_opl_nuked.c b/src/sound/snd_opl_nuked.c index 20b956b1d..6ed697bf3 100644 --- a/src/sound/snd_opl_nuked.c +++ b/src/sound/snd_opl_nuked.c @@ -125,9 +125,9 @@ typedef struct chan { uint8_t con; uint8_t alg; uint8_t ksv; - uint16_t cha, - chb; - uint8_t ch_num; + uint16_t cha; + uint16_t chb; + uint8_t ch_num; } chan_t; typedef struct wrbuf { @@ -177,12 +177,14 @@ typedef struct chip { typedef struct { nuked_t opl; - int8_t flags, pad; + int8_t flags; + int8_t pad; uint16_t port; - uint8_t status, timer_ctrl; - uint16_t timer_count[2], - timer_cur_count[2]; + uint8_t status; + uint8_t timer_ctrl; + uint16_t timer_count[2]; + uint16_t timer_cur_count[2]; pc_timer_t timers[2]; @@ -543,6 +545,9 @@ env_calc(slot_t *slot) case envelope_gen_num_release: reg_rate = slot->reg_rr; break; + + default: + break; } slot->pg_reset = reset; @@ -619,6 +624,9 @@ env_calc(slot_t *slot) if (!eg_off && !reset && shift > 0) eg_inc = 1 << (shift - 1); break; + + default: + break; } slot->eg_rout = (eg_rout + eg_inc) & 0x1ff; @@ -810,6 +818,9 @@ channel_setup_alg(chan_t *ch) ch->slots[0]->mod = &ch->slots[0]->fbmod; ch->slots[1]->mod = &ch->dev->zeromod; break; + + default: + break; } return; } @@ -867,6 +878,9 @@ channel_setup_alg(chan_t *ch) ch->out[2] = &ch->slots[1]->out; ch->out[3] = &ch->dev->zeromod; break; + + default: + break; } } else switch (ch->alg & 0x01) { @@ -887,6 +901,9 @@ channel_setup_alg(chan_t *ch) ch->out[2] = &ch->dev->zeromod; ch->out[3] = &ch->dev->zeromod; break; + + default: + break; } } @@ -1100,7 +1117,7 @@ channel_set_4op(nuked_t *dev, uint8_t data) uint16_t nuked_write_addr(void *priv, uint16_t port, uint8_t val) { - nuked_t *dev = (nuked_t *) priv; + const nuked_t *dev = (nuked_t *) priv; uint16_t addr; addr = val; @@ -1128,12 +1145,18 @@ nuked_write_reg(void *priv, uint16_t reg, uint8_t val) case 0x05: dev->newm = val & 0x01; break; + + default: + break; } else switch (regm & 0x0f) { case 0x08: dev->nts = (val >> 6) & 0x01; break; + + default: + break; } break; @@ -1191,6 +1214,9 @@ nuked_write_reg(void *priv, uint16_t reg, uint8_t val) if (ad_slot[regm & 0x1f] >= 0) slot_write_e0(&dev->slot[18 * high + ad_slot[regm & 0x1f]], val); break; + + default: + break; } } @@ -1576,6 +1602,9 @@ nuked_drv_write(uint16_t port, uint8_t val, void *priv) nuked_log("Status mask now %02X (val = %02X)\n", (val & ~CTRL_TMR_MASK) & CTRL_TMR_MASK, val); } break; + + default: + break; } } else { dev->port = nuked_write_addr(&dev->opl, port, val) & 0x01ff; diff --git a/src/sound/snd_opl_ymfm.cpp b/src/sound/snd_opl_ymfm.cpp index 8390bc1ed..c6cf13a33 100644 --- a/src/sound/snd_opl_ymfm.cpp +++ b/src/sound/snd_opl_ymfm.cpp @@ -29,6 +29,7 @@ extern "C" { #include <86box/snd_opl.h> #include <86box/mem.h> #include <86box/rom.h> +#include <86box/plat_unused.h> // Disable c99-designator to avoid the warnings in *_ymfm_device #ifdef __clang__ @@ -50,7 +51,7 @@ enum { class YMFMChipBase { public: - YMFMChipBase(uint32_t clock, fm_type type, uint32_t samplerate) + YMFMChipBase(uint32_t clock, fm_type type, UNUSED(uint32_t samplerate)) : m_buf_pos(0) , m_flags(0) , m_type(type) @@ -295,8 +296,8 @@ ymfm_drv_init(const device_t *info) YMFMChipBase *fm; switch (info->local) { - case FM_YM3812: default: + case FM_YM3812: fm = (YMFMChipBase *) new YMFMChip(3579545, FM_YM3812, OPL_FREQ); break; diff --git a/src/sound/snd_optimc.c b/src/sound/snd_optimc.c index 11aea6896..d7afca382 100644 --- a/src/sound/snd_optimc.c +++ b/src/sound/snd_optimc.c @@ -38,6 +38,7 @@ #include <86box/snd_sb.h> #include <86box/mem.h> #include <86box/rom.h> +#include <86box/plat_unused.h> static int optimc_wss_dma[4] = { 0, 0, 1, 3 }; static int optimc_wss_irq[8] = { 5, 7, 9, 10, 11, 12, 14, 15 }; @@ -48,14 +49,21 @@ enum optimc_local_flags { }; typedef struct optimc_t { - uint8_t type, fm_type; + uint8_t type; + uint8_t fm_type; - uint8_t wss_config, reg_enabled; + uint8_t wss_config; + uint8_t reg_enabled; - uint16_t cur_addr, cur_wss_addr, cur_mpu401_addr; + uint16_t cur_addr; + uint16_t cur_wss_addr; + uint16_t cur_mpu401_addr; - int cur_irq, cur_dma; - int cur_wss_enabled, cur_wss_irq, cur_wss_dma; + int cur_irq; + int cur_dma; + int cur_wss_enabled; + int cur_wss_irq; + int cur_wss_dma; int cur_mpu401_irq; int cur_mpu401_enabled; void *gameport; @@ -82,9 +90,9 @@ optimc_filter_opl(void *priv, double *out_l, double *out_r) } static uint8_t -optimc_wss_read(uint16_t addr, void *priv) +optimc_wss_read(UNUSED(uint16_t addr), void *priv) { - optimc_t *optimc = (optimc_t *) priv; + const optimc_t *optimc = (optimc_t *) priv; if (!(optimc->regs[4] & 0x10) && optimc->cur_mode == 0) return 0xFF; @@ -93,7 +101,7 @@ optimc_wss_read(uint16_t addr, void *priv) } static void -optimc_wss_write(uint16_t addr, uint8_t val, void *priv) +optimc_wss_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { optimc_t *optimc = (optimc_t *) priv; @@ -105,9 +113,9 @@ optimc_wss_write(uint16_t addr, uint8_t val, void *priv) } static void -optimc_get_buffer(int32_t *buffer, int len, void *p) +optimc_get_buffer(int32_t *buffer, int len, void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; if (optimc->regs[3] & 0x4) return; @@ -141,9 +149,9 @@ optimc_add_opl(optimc_t *optimc) } static void -optimc_reg_write(uint16_t addr, uint8_t val, void *p) +optimc_reg_write(uint16_t addr, uint8_t val, void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; uint16_t idx = addr - 0xF8D; uint8_t old = optimc->regs[idx]; static uint8_t reg_enable_phase = 0; @@ -176,6 +184,9 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) case 3: /* WSBase = 0x604 */ optimc->cur_wss_addr = 0x604; break; + + default: + break; } io_sethandler(optimc->cur_wss_addr, 0x0004, optimc_wss_read, NULL, NULL, optimc_wss_write, NULL, NULL, optimc); io_sethandler(optimc->cur_wss_addr + 0x0004, 0x0004, ad1848_read, NULL, NULL, ad1848_write, NULL, NULL, &optimc->ad1848); @@ -247,6 +258,9 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) case 3: optimc->cur_mpu401_irq = 7; break; + + default: + break; } switch ((val >> 5) & 0x3) { case 0: @@ -261,11 +275,17 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) case 3: optimc->cur_mpu401_addr = 0x300; break; + + default: + break; } mpu401_change_addr(optimc->mpu, optimc->cur_mpu401_addr); mpu401_setirq(optimc->mpu, optimc->cur_mpu401_irq); } break; + + default: + break; } } if (optimc->reg_enabled) @@ -291,6 +311,9 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) reg_enable_phase = 1; } break; + + default: + break; } } else reg_enable_phase = 1; @@ -299,9 +322,9 @@ optimc_reg_write(uint16_t addr, uint8_t val, void *p) } static uint8_t -optimc_reg_read(uint16_t addr, void *p) +optimc_reg_read(uint16_t addr, void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; uint8_t temp = 0xFF; if (optimc->reg_enabled) { @@ -316,6 +339,9 @@ optimc_reg_read(uint16_t addr, void *p) case 2: /* MC3 */ temp = (optimc->regs[2] & ~0x3) | 0x2; break; + + default: + break; } optimc->reg_enabled = 0; } @@ -398,19 +424,19 @@ optimc_init(const device_t *info) } static void -optimc_close(void *p) +optimc_close(void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; sb_close(optimc->sb); free(optimc->mpu); - free(p); + free(priv); } static void -optimc_speed_changed(void *p) +optimc_speed_changed(void *priv) { - optimc_t *optimc = (optimc_t *) p; + optimc_t *optimc = (optimc_t *) priv; ad1848_speed_changed(&optimc->ad1848); sb_speed_changed(optimc->sb); diff --git a/src/sound/snd_pas16.c b/src/sound/snd_pas16.c index 10e6bd1c4..674acfcbb 100644 --- a/src/sound/snd_pas16.c +++ b/src/sound/snd_pas16.c @@ -20,6 +20,7 @@ #include <86box/snd_opl.h> #include <86box/snd_sb.h> #include <86box/snd_sb_dsp.h> +#include <86box/plat_unused.h> /* Original PAS uses 2 x OPL2 @@ -97,39 +98,51 @@ typedef struct pas16_t { uint16_t base; - int irq, dma; + int irq; + int dma; uint8_t audiofilt; uint8_t audio_mixer; - uint8_t compat, compat_base; + uint8_t compat; + uint8_t compat_base; uint8_t enhancedscsi; - uint8_t io_conf_1, io_conf_2, io_conf_3, io_conf_4; + uint8_t io_conf_1; + uint8_t io_conf_2; + uint8_t io_conf_3; + uint8_t io_conf_4; - uint8_t irq_stat, irq_ena; + uint8_t irq_stat; + uint8_t irq_ena; uint8_t pcm_ctrl; uint16_t pcm_dat; - uint16_t pcm_dat_l, pcm_dat_r; + uint16_t pcm_dat_l; + uint16_t pcm_dat_r; uint8_t sb_irqdma; int stereo_lr; - uint8_t sys_conf_1, sys_conf_2, sys_conf_3, sys_conf_4; + uint8_t sys_conf_1; + uint8_t sys_conf_2; + uint8_t sys_conf_3; + uint8_t sys_conf_4; - struct - { + struct { uint32_t l[3]; int64_t c[3]; pc_timer_t timer[3]; uint8_t m[3]; - uint8_t ctrl, ctrls[2]; - int wp, rm[3], wm[3]; + uint8_t ctrl; + uint8_t ctrls[2]; + int wp; + int rm[3]; + int wm[3]; uint16_t rl[3]; int thit[3]; int delay[3]; @@ -192,9 +205,9 @@ pas16_log(const char *fmt, ...) #endif static uint8_t -pas16_in(uint16_t port, void *p) +pas16_in(uint16_t port, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; uint8_t temp = 0xff; switch ((port - pas16->base) + 0x388) { case 0x388: @@ -286,15 +299,18 @@ pas16_in(uint16_t port, void *p) case 0xff8b: /*Master mode read*/ temp = 0x20 | 0x10 | 0x01; /*AT bus, XT/AT timing*/ break; + + default: + break; } pas16_log("pas16_in : port %04X return %02X %04X:%04X\n", port, temp, CS, cpu_state.pc); return temp; } static void -pas16_out(uint16_t port, uint8_t val, void *p) +pas16_out(uint16_t port, uint8_t val, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; pas16_log("pas16_out : port %04X val %02X %04X:%04X\n", port, val, CS, cpu_state.pc); switch ((port - pas16->base) + 0x388) { case 0x388: @@ -409,9 +425,9 @@ pas16_out(uint16_t port, uint8_t val, void *p) } static void -pas16_pit_out(uint16_t port, uint8_t val, void *p) +pas16_pit_out(uint16_t port, uint8_t val, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; int t; switch (port & 3) { case 3: /*CTRL*/ @@ -496,6 +512,9 @@ pas16_pit_out(uint16_t port, uint8_t val, void *p) pas16->pit.l[t] |= val; pas16->pit.wm[t] = 0; break; + + default: + break; } if (!pas16->pit.l[t]) { pas16->pit.l[t] |= 0x10000; @@ -504,13 +523,16 @@ pas16_pit_out(uint16_t port, uint8_t val, void *p) timer_set_delay_u64(&pas16->pit.timer[t], pas16->pit.c[t] * PITCONST); } break; + + default: + break; } } static uint8_t -pas16_pit_in(uint16_t port, void *p) +pas16_pit_in(uint16_t port, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; uint8_t temp = 0xff; int t = port & 3; switch (port & 3) { @@ -550,11 +572,17 @@ pas16_pit_in(uint16_t port, void *p) else pas16->pit.rm[t] = 0; break; + + default: + break; } break; case 3: /*Control*/ temp = pas16->pit.ctrl; break; + + default: + break; } return temp; } @@ -566,9 +594,9 @@ pas16_readdma(pas16_t *pas16) } static void -pas16_pcm_poll(void *p) +pas16_pcm_poll(void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; pas16_update(pas16); if (pas16->pit.m[0] & 2) { @@ -633,9 +661,9 @@ pas16_pcm_poll(void *p) } static void -pas16_out_base(uint16_t port, uint8_t val, void *p) +pas16_out_base(UNUSED(uint16_t port), uint8_t val, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; io_removehandler((pas16->base - 0x388) + 0x0388, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); io_removehandler((pas16->base - 0x388) + 0x0788, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); @@ -696,11 +724,11 @@ pas16_update(pas16_t *pas16) } void -pas16_get_buffer(int32_t *buffer, int len, void *p) +pas16_get_buffer(int32_t *buffer, int len, void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; - int32_t *opl_buf = pas16->opl.update(pas16->opl.priv); + const int32_t *opl_buf = pas16->opl.update(pas16->opl.priv); sb_dsp_update(&pas16->dsp); pas16_update(pas16); for (int c = 0; c < len * 2; c++) { @@ -715,7 +743,7 @@ pas16_get_buffer(int32_t *buffer, int len, void *p) } static void * -pas16_init(const device_t *info) +pas16_init(UNUSED(const device_t *info)) { pas16_t *pas16 = malloc(sizeof(pas16_t)); memset(pas16, 0, sizeof(pas16_t)); @@ -733,9 +761,9 @@ pas16_init(const device_t *info) } static void -pas16_close(void *p) +pas16_close(void *priv) { - pas16_t *pas16 = (pas16_t *) p; + pas16_t *pas16 = (pas16_t *) priv; free(pas16); } diff --git a/src/sound/snd_ps1.c b/src/sound/snd_ps1.c index d440af9d0..60b4515f8 100644 --- a/src/sound/snd_ps1.c +++ b/src/sound/snd_ps1.c @@ -13,15 +13,18 @@ #include <86box/sound.h> #include <86box/snd_sn76489.h> #include <86box/timer.h> +#include <86box/plat_unused.h> -typedef struct { +typedef struct ps1snd_t { sn76489_t sn76489; - uint8_t status, ctrl; + uint8_t status; + uint8_t ctrl; uint64_t timer_latch; pc_timer_t timer_count; int timer_enable; uint8_t fifo[2048]; - int fifo_read_idx, fifo_write_idx; + int fifo_read_idx; + int fifo_write_idx; int fifo_threshold; uint8_t dac_val; int16_t buffer[SOUNDBUFLEN]; @@ -73,6 +76,10 @@ ps1snd_read(uint16_t port, void *priv) case 6: case 7: ret = 0; + break; + + default: + break; } return ret; @@ -109,6 +116,9 @@ ps1snd_write(uint16_t port, uint8_t val, void *priv) case 4: /* almost empty */ ps1snd->fifo_threshold = val * 4; break; + + default: + break; } } @@ -154,7 +164,7 @@ ps1snd_get_buffer(int32_t *buffer, int len, void *priv) } static void * -ps1snd_init(const device_t *info) +ps1snd_init(UNUSED(const device_t *info)) { ps1snd_t *ps1snd = malloc(sizeof(ps1snd_t)); memset(ps1snd, 0x00, sizeof(ps1snd_t)); diff --git a/src/sound/snd_pssj.c b/src/sound/snd_pssj.c index 705a83517..1e6f48ae3 100644 --- a/src/sound/snd_pssj.c +++ b/src/sound/snd_pssj.c @@ -12,6 +12,7 @@ #include <86box/sound.h> #include <86box/snd_sn76489.h> #include <86box/timer.h> +#include <86box/plat_unused.h> typedef struct pssj_t { sn76489_t sn76489; @@ -41,9 +42,9 @@ pssj_update_irq(pssj_t *pssj) } static void -pssj_write(uint16_t port, uint8_t val, void *p) +pssj_write(uint16_t port, uint8_t val, void *priv) { - pssj_t *pssj = (pssj_t *) p; + pssj_t *pssj = (pssj_t *) priv; switch (port & 3) { case 0: @@ -67,6 +68,9 @@ pssj_write(uint16_t port, uint8_t val, void *p) case 3: /*Direct DAC*/ pssj->dac_val = val; break; + + default: + break; } break; case 2: @@ -76,12 +80,15 @@ pssj_write(uint16_t port, uint8_t val, void *p) pssj->freq = (pssj->freq & 0x0ff) | ((val & 0xf) << 8); pssj->amplitude = val >> 4; break; + + default: + break; } } static uint8_t -pssj_read(uint16_t port, void *p) +pssj_read(uint16_t port, void *priv) { - pssj_t *pssj = (pssj_t *) p; + const pssj_t *pssj = (pssj_t *) priv; switch (port & 3) { case 0: @@ -96,6 +103,9 @@ pssj_read(uint16_t port, void *p) return 0x80; case 3: /*Direct DAC*/ return pssj->dac_val; + + default: + break; } break; case 2: @@ -117,9 +127,9 @@ pssj_update(pssj_t *pssj) } static void -pssj_callback(void *p) +pssj_callback(void *priv) { - pssj_t *pssj = (pssj_t *) p; + pssj_t *pssj = (pssj_t *) priv; int data; pssj_update(pssj); @@ -157,6 +167,9 @@ pssj_callback(void *p) case 0xc0: pssj->dac_val = 0x80; break; + + default: + break; } pssj->wave_pos = (pssj->wave_pos + 1) & 31; } @@ -165,9 +178,9 @@ pssj_callback(void *p) } static void -pssj_get_buffer(int32_t *buffer, int len, void *p) +pssj_get_buffer(int32_t *buffer, int len, void *priv) { - pssj_t *pssj = (pssj_t *) p; + pssj_t *pssj = (pssj_t *) priv; pssj_update(pssj); @@ -178,7 +191,7 @@ pssj_get_buffer(int32_t *buffer, int len, void *p) } void * -pssj_init(const device_t *info) +pssj_init(UNUSED(const device_t *info)) { pssj_t *pssj = malloc(sizeof(pssj_t)); memset(pssj, 0, sizeof(pssj_t)); @@ -193,7 +206,7 @@ pssj_init(const device_t *info) } void * -pssj_1e0_init(const device_t *info) +pssj_1e0_init(UNUSED(const device_t *info)) { pssj_t *pssj = malloc(sizeof(pssj_t)); memset(pssj, 0, sizeof(pssj_t)); @@ -208,7 +221,7 @@ pssj_1e0_init(const device_t *info) } void * -pssj_isa_init(const device_t *info) +pssj_isa_init(UNUSED(const device_t *info)) { pssj_t *pssj = malloc(sizeof(pssj_t)); memset(pssj, 0, sizeof(pssj_t)); @@ -225,9 +238,9 @@ pssj_isa_init(const device_t *info) } void -pssj_close(void *p) +pssj_close(void *priv) { - pssj_t *pssj = (pssj_t *) p; + pssj_t *pssj = (pssj_t *) priv; free(pssj); } diff --git a/src/sound/snd_resid.cc b/src/sound/snd_resid.cc index 68d9fa71c..94bbcd591 100644 --- a/src/sound/snd_resid.cc +++ b/src/sound/snd_resid.cc @@ -20,12 +20,16 @@ psid_t *psid; void * sid_init(void) { - // psid_t *psid; +#if 0 + psid_t *psid; +#endif sampling_method method = SAMPLE_INTERPOLATE; float cycles_per_sec = 14318180.0 / 16.0; psid = new psid_t; - // psid = (psid_t *)malloc(sizeof(sound_t)); +#if 0 + psid = (psid_t *)malloc(sizeof(sound_t)); +#endif psid->sid = new SIDFP; psid->sid->set_chip_model(MOS8580FP); @@ -42,9 +46,11 @@ sid_init(void) for (uint8_t c = 0; c < 32; c++) psid->sid->write(c, 0); - if (!psid->sid->set_sampling_parameters((float) cycles_per_sec, method, + if (!psid->sid->set_sampling_parameters(cycles_per_sec, method, (float) RESID_FREQ, 0.9 * (float) RESID_FREQ / 2.0)) { - // printf("reSID failed!\n"); +#if 0 + printf("reSID failed!\n"); +#endif } psid->sid->set_chip_model(MOS6581FP); @@ -58,17 +64,23 @@ sid_init(void) } void -sid_close(UNUSED(void *p)) +sid_close(UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif delete psid->sid; - // free(psid); +#if 0 + free(psid); +#endif } void -sid_reset(UNUSED(void *p)) +sid_reset(UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif psid->sid->reset(); @@ -77,18 +89,24 @@ sid_reset(UNUSED(void *p)) } uint8_t -sid_read(uint16_t addr, UNUSED(void *p)) +sid_read(uint16_t addr, UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif return psid->sid->read(addr & 0x1f); - // return 0xFF; +#if 0 + return 0xFF; +#endif } void -sid_write(uint16_t addr, uint8_t val, UNUSED(void *p)) +sid_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif psid->sid->write(addr & 0x1f, val); } @@ -105,9 +123,11 @@ fillbuf2(int &count, int16_t *buf, int len) psid->last_sample = *buf; } void -sid_fillbuf(int16_t *buf, int len, UNUSED(void *p)) +sid_fillbuf(int16_t *buf, int len, UNUSED(void *priv)) { - // psid_t *psid = (psid_t *)p; +#if 0 + psid_t *psid = (psid_t *) priv; +#endif int x = CLOCK_DELTA(len); fillbuf2(x, buf, len); diff --git a/src/sound/snd_sb.c b/src/sound/snd_sb.c index 84f31f500..ae0cebabf 100644 --- a/src/sound/snd_sb.c +++ b/src/sound/snd_sb.c @@ -41,6 +41,7 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/snd_sb.h> +#include <86box/plat_unused.h> /* 0 to 7 -> -14dB to 0dB i 2dB steps. 8 to 15 -> 0 to +14dB in 2dB steps. Note that for positive dB values, this is not amplitude, it is amplitude - 1. */ @@ -177,14 +178,14 @@ sb_log(const char *fmt, ...) /* SB 1, 1.5, MCV, and 2 do not have a mixer, so signal is hardwired. */ static void -sb_get_buffer_sb2(int32_t *buffer, int len, void *p) +sb_get_buffer_sb2(int32_t *buffer, int len, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; - double out_mono = 0.0; - double out_l = 0.0; - double out_r = 0.0; - int32_t *opl_buf = NULL; + sb_t *sb = (sb_t *) priv; + const sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; + double out_mono = 0.0; + double out_l = 0.0; + double out_r = 0.0; + const int32_t *opl_buf = NULL; if (sb->opl_enabled) opl_buf = sb->opl.update(sb->opl.priv); @@ -245,30 +246,30 @@ sb_get_buffer_sb2(int32_t *buffer, int len, void *p) } static void -sb2_filter_cd_audio(int channel, double *buffer, void *p) +sb2_filter_cd_audio(UNUSED(int channel), double *buffer, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; - double c; + const sb_t *sb = (sb_t *) priv; + const sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; + double c; if (sb->mixer_enabled) { c = ((sb_iir(1, 0, *buffer) / 1.3) * mixer->cd) / 3.0; *buffer = c * mixer->master; } else { - c = (((sb_iir(1, 0, ((double) *buffer)) / 1.3) * 65536) / 3.0) / 65536.0; + c = (((sb_iir(1, 0, (*buffer)) / 1.3) * 65536) / 3.0) / 65536.0; *buffer = c; } } void -sb_get_buffer_sbpro(int32_t *buffer, int len, void *p) +sb_get_buffer_sbpro(int32_t *buffer, int len, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; - double out_l = 0.0; - double out_r = 0.0; - int32_t *opl_buf = NULL; - int32_t *opl2_buf = NULL; + sb_t *sb = (sb_t *) priv; + const sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; + double out_l = 0.0; + double out_r = 0.0; + const int32_t *opl_buf = NULL; + const int32_t *opl2_buf = NULL; if (sb->opl_enabled) { if (sb->dsp.sb_type == SBPRO) { @@ -281,7 +282,8 @@ sb_get_buffer_sbpro(int32_t *buffer, int len, void *p) sb_dsp_update(&sb->dsp); for (int c = 0; c < len * 2; c += 2) { - out_l = 0.0, out_r = 0.0; + out_l = 0.0; + out_r = 0.0; if (sb->opl_enabled) { if (sb->dsp.sb_type == SBPRO) { @@ -327,13 +329,13 @@ sb_get_buffer_sbpro(int32_t *buffer, int len, void *p) } void -sbpro_filter_cd_audio(int channel, double *buffer, void *p) +sbpro_filter_cd_audio(int channel, double *buffer, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; - double c; - double cd = channel ? mixer->cd_r : mixer->cd_l; - double master = channel ? mixer->master_r : mixer->master_l; + const sb_t *sb = (sb_t *) priv; + const sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; + double c; + double cd = channel ? mixer->cd_r : mixer->cd_l; + double master = channel ? mixer->master_r : mixer->master_l; if (mixer->output_filter) c = (sb_iir(1, channel, *buffer) * cd) / 3.9; @@ -343,19 +345,19 @@ sbpro_filter_cd_audio(int channel, double *buffer, void *p) } static void -sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) +sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; - int dsp_rec_pos = sb->dsp.record_pos_write; - int c_emu8k; - int c_record; - int32_t in_l; - int32_t in_r; - double out_l = 0.0; - double out_r = 0.0; - double bass_treble; - int32_t *opl_buf = NULL; + sb_t *sb = (sb_t *) priv; + const sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; + int dsp_rec_pos = sb->dsp.record_pos_write; + int c_emu8k = 0; + int c_record; + int32_t in_l; + int32_t in_r; + double out_l = 0.0; + double out_r = 0.0; + double bass_treble; + const int32_t *opl_buf = NULL; if (sb->opl_enabled) opl_buf = sb->opl.update(sb->opl.priv); @@ -477,17 +479,17 @@ sb_get_buffer_sb16_awe32(int32_t *buffer, int len, void *p) } void -sb16_awe32_filter_cd_audio(int channel, double *buffer, void *p) +sb16_awe32_filter_cd_audio(int channel, double *buffer, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; - double c; - double cd = channel ? mixer->cd_r : mixer->cd_l /* / 3.0 */; - double master = channel ? mixer->master_r : mixer->master_l; - int32_t bass = channel ? mixer->bass_r : mixer->bass_l; - int32_t treble = channel ? mixer->treble_r : mixer->treble_l; - double bass_treble; - double output_gain = (channel ? mixer->output_gain_R : mixer->output_gain_L); + const sb_t *sb = (sb_t *) priv; + const sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; + double c; + double cd = channel ? mixer->cd_r : mixer->cd_l /* / 3.0 */; + double master = channel ? mixer->master_r : mixer->master_l; + int32_t bass = channel ? mixer->bass_r : mixer->bass_l; + int32_t treble = channel ? mixer->treble_r : mixer->treble_l; + double bass_treble; + double output_gain = (channel ? mixer->output_gain_R : mixer->output_gain_L); if (mixer->output_filter) c = (low_fir_sb16(1, channel, *buffer) * cd) / 3.0; @@ -519,9 +521,9 @@ sb16_awe32_filter_cd_audio(int channel, double *buffer, void *p) } void -sb_ct1335_mixer_write(uint16_t addr, uint8_t val, void *p) +sb_ct1335_mixer_write(uint16_t addr, uint8_t val, void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; if (!(addr & 1)) { @@ -558,10 +560,10 @@ sb_ct1335_mixer_write(uint16_t addr, uint8_t val, void *p) } uint8_t -sb_ct1335_mixer_read(uint16_t addr, void *p) +sb_ct1335_mixer_read(uint16_t addr, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; + const sb_t *sb = (sb_t *) priv; + const sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; if (!(addr & 1)) return mixer->index; @@ -589,9 +591,9 @@ sb_ct1335_mixer_reset(sb_t *sb) } void -sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *p) +sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; if (!(addr & 1)) { @@ -685,10 +687,10 @@ sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *p) } uint8_t -sb_ct1345_mixer_read(uint16_t addr, void *p) +sb_ct1345_mixer_read(uint16_t addr, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; + const sb_t *sb = (sb_t *) priv; + const sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; if (!(addr & 1)) return mixer->index; @@ -727,9 +729,9 @@ sb_ct1345_mixer_reset(sb_t *sb) } void -sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *p) +sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; if (!(addr & 1)) @@ -861,6 +863,9 @@ sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *p) mpu401_change_addr(sb->mpu, 0); } break; + + default: + break; } mixer->output_selector = mixer->regs[0x3c]; @@ -897,12 +902,12 @@ sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *p) } uint8_t -sb_ct1745_mixer_read(uint16_t addr, void *p) +sb_ct1745_mixer_read(uint16_t addr, void *priv) { - sb_t *sb = (sb_t *) p; - sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; - uint8_t temp; - uint8_t ret = 0xff; + const sb_t *sb = (sb_t *) priv; + const sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; + uint8_t temp; + uint8_t ret = 0xff; if (!(addr & 1)) ret = mixer->index; @@ -974,6 +979,9 @@ sb_ct1745_mixer_read(uint16_t addr, void *p) case 10: ret = 8; break; + + default: + break; } break; @@ -996,6 +1004,9 @@ sb_ct1745_mixer_read(uint16_t addr, void *p) case 3: ret |= 8; break; + + default: + break; } switch (sb->dsp.sb_16_dmanum) { case 5: @@ -1007,6 +1018,9 @@ sb_ct1745_mixer_read(uint16_t addr, void *p) case 7: ret |= 0x80; break; + + default: + break; } break; @@ -1078,9 +1092,9 @@ sb_ct1745_mixer_reset(sb_t *sb) } uint8_t -sb_mcv_read(int port, void *p) +sb_mcv_read(int port, void *priv) { - sb_t *sb = (sb_t *) p; + const sb_t *sb = (sb_t *) priv; sb_log("sb_mcv_read: port=%04x\n", port); @@ -1088,10 +1102,10 @@ sb_mcv_read(int port, void *p) } void -sb_mcv_write(int port, uint8_t val, void *p) +sb_mcv_write(int port, uint8_t val, void *priv) { uint16_t addr; - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; if (port < 0x102) return; @@ -1133,18 +1147,18 @@ sb_mcv_write(int port, uint8_t val, void *p) } uint8_t -sb_mcv_feedb(void *p) +sb_mcv_feedb(void *priv) { - sb_t *sb = (sb_t *) p; + const sb_t *sb = (sb_t *) priv; return (sb->pos_regs[2] & 1); } static uint8_t -sb_pro_mcv_read(int port, void *p) +sb_pro_mcv_read(int port, void *priv) { - sb_t *sb = (sb_t *) p; - uint8_t ret = sb->pos_regs[port & 7]; + const sb_t *sb = (sb_t *) priv; + uint8_t ret = sb->pos_regs[port & 7]; sb_log("sb_pro_mcv_read: port=%04x ret=%02x\n", port, ret); @@ -1152,10 +1166,10 @@ sb_pro_mcv_read(int port, void *p) } static void -sb_pro_mcv_write(int port, uint8_t val, void *p) +sb_pro_mcv_write(int port, uint8_t val, void *priv) { uint16_t addr; - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; if (port < 0x102) return; @@ -1212,10 +1226,10 @@ sb_pro_mcv_write(int port, uint8_t val, void *p) } static uint8_t -sb_16_reply_mca_read(int port, void *p) +sb_16_reply_mca_read(int port, void *priv) { - sb_t *sb = (sb_t *) p; - uint8_t ret = sb->pos_regs[port & 7]; + const sb_t *sb = (sb_t *) priv; + uint8_t ret = sb->pos_regs[port & 7]; sb_log("sb_16_reply_mca_read: port=%04x ret=%02x\n", port, ret); @@ -1223,13 +1237,13 @@ sb_16_reply_mca_read(int port, void *p) } static void -sb_16_reply_mca_write(int port, uint8_t val, void *p) +sb_16_reply_mca_write(int port, uint8_t val, void *priv) { uint16_t addr; uint16_t mpu401_addr; int low_dma; int high_dma; - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; if (port < 0x102) return; @@ -1347,6 +1361,9 @@ sb_16_reply_mca_write(int port, uint8_t val, void *p) case 0x60: sb_dsp_setirq(&sb->dsp, 10); break; + + default: + break; } low_dma = sb->pos_regs[3] & 3; @@ -1458,6 +1475,9 @@ sb_16_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv) case 4: /* StereoEnhance (32) */ break; + + default: + break; } } @@ -1476,6 +1496,9 @@ sb_awe32_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *pr case 3: /* WaveTable */ sb_16_pnp_config_changed(ld ^ 1, config, sb); break; + + default: + break; } } @@ -1493,11 +1516,14 @@ sb_awe64_gold_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, voi case 1: /* Game */ sb_16_pnp_config_changed(3, config, sb); break; + + default: + break; } } void * -sb_1_init(const device_t *info) +sb_1_init(UNUSED(const device_t *info)) { /* SB1/2 port mappings, 210h to 260h in 10h steps 2x0 to 2x3 -> CMS chip @@ -1545,7 +1571,7 @@ sb_1_init(const device_t *info) } void * -sb_15_init(const device_t *info) +sb_15_init(UNUSED(const device_t *info)) { /* SB1/2 port mappings, 210h to 260h in 10h steps 2x0 to 2x3 -> CMS chip @@ -1595,7 +1621,7 @@ sb_15_init(const device_t *info) } void * -sb_mcv_init(const device_t *info) +sb_mcv_init(UNUSED(const device_t *info)) { /* SB1/2 port mappings, 210h to 260h in 10h steps 2x6, 2xA, 2xC, 2xE -> DSP chip @@ -1628,7 +1654,7 @@ sb_mcv_init(const device_t *info) } void * -sb_2_init(const device_t *info) +sb_2_init(UNUSED(const device_t *info)) { /* SB2 port mappings, 220h or 240h. 2x0 to 2x3 -> CMS chip @@ -1724,7 +1750,7 @@ sb_pro_v1_opl_write(uint16_t port, uint8_t val, void *priv) } static void * -sb_pro_v1_init(const device_t *info) +sb_pro_v1_init(UNUSED(const device_t *info)) { /* SB Pro port mappings, 220h or 240h. 2x0 to 2x3 -> FM chip, Left and Right (9*2 voices) @@ -1784,7 +1810,7 @@ sb_pro_v1_init(const device_t *info) } static void * -sb_pro_v2_init(const device_t *info) +sb_pro_v2_init(UNUSED(const device_t *info)) { /* SB Pro 2 port mappings, 220h or 240h. 2x0 to 2x3 -> FM chip (18 voices) @@ -1836,7 +1862,7 @@ sb_pro_v2_init(const device_t *info) } static void * -sb_pro_mcv_init(const device_t *info) +sb_pro_mcv_init(UNUSED(const device_t *info)) { /* SB Pro MCV port mappings, 220h or 240h. 2x0 to 2x3 -> FM chip, Left and Right (18 voices) @@ -1868,7 +1894,7 @@ sb_pro_mcv_init(const device_t *info) } static void * -sb_pro_compat_init(const device_t *info) +sb_pro_compat_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0, sizeof(sb_t)); @@ -1890,7 +1916,7 @@ sb_pro_compat_init(const device_t *info) } static void * -sb_16_init(const device_t *info) +sb_16_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -1946,7 +1972,7 @@ sb_16_init(const device_t *info) } static void * -sb_16_reply_mca_init(const device_t *info) +sb_16_reply_mca_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0x00, sizeof(sb_t)); @@ -1981,7 +2007,7 @@ sb_16_reply_mca_init(const device_t *info) } static void * -sb_16_pnp_init(const device_t *info) +sb_16_pnp_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); memset(sb, 0x00, sizeof(sb_t)); @@ -2083,7 +2109,7 @@ sb_awe64_gold_available(void) } static void * -sb_awe32_init(const device_t *info) +sb_awe32_init(UNUSED(const device_t *info)) { sb_t *sb = malloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -2176,7 +2202,7 @@ sb_awe32_pnp_init(const device_t *info) if ((info->local != 2) && (info->local != 3) && (info->local != 4)) device_add(&ide_ter_pnp_device); - char *pnp_rom_file = NULL; + const char *pnp_rom_file = NULL; switch (info->local) { case 0: pnp_rom_file = "roms/sound/CT3600 PnP.BIN"; @@ -2194,6 +2220,9 @@ sb_awe32_pnp_init(const device_t *info) case 4: pnp_rom_file = "roms/sound/CT4540 PnP.BIN"; break; + + default: + break; } uint8_t *pnp_rom = NULL; @@ -2220,6 +2249,9 @@ sb_awe32_pnp_init(const device_t *info) case 4: isapnp_add_card(pnp_rom, sizeof(sb->pnp_rom), sb_awe64_gold_pnp_config_changed, NULL, NULL, NULL, sb); break; + + default: + break; } sb_dsp_setaddr(&sb->dsp, 0); @@ -2238,18 +2270,18 @@ sb_awe32_pnp_init(const device_t *info) } void -sb_close(void *p) +sb_close(void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_dsp_close(&sb->dsp); free(sb); } static void -sb_awe32_close(void *p) +sb_awe32_close(void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; emu8k_close(&sb->emu8k); @@ -2257,9 +2289,9 @@ sb_awe32_close(void *p) } void -sb_speed_changed(void *p) +sb_speed_changed(void *priv) { - sb_t *sb = (sb_t *) p; + sb_t *sb = (sb_t *) priv; sb_dsp_speed_changed(&sb->dsp); } diff --git a/src/sound/snd_sb_dsp.c b/src/sound/snd_sb_dsp.c index 5b9637a81..d4dcd5a79 100644 --- a/src/sound/snd_sb_dsp.c +++ b/src/sound/snd_sb_dsp.c @@ -25,6 +25,8 @@ #include <86box/sound.h> #include <86box/timer.h> #include <86box/snd_sb.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #define ADPCM_4 1 #define ADPCM_26 2 @@ -33,8 +35,8 @@ /*The recording safety margin is intended for uneven "len" calls to the get_buffer mixer calls on sound_sb*/ #define SB_DSP_REC_SAFEFTY_MARGIN 4096 -void pollsb(void *p); -void sb_poll_i(void *p); +void pollsb(void *priv); +void sb_poll_i(void *priv); static int sbe2dat[4][9] = { {0x01, -0x02, -0x04, 0x08, -0x10, 0x20, 0x40, -0x80, -106}, @@ -173,7 +175,7 @@ recalc_sb16_filter(int c, int playback_freq) static void sb_irq_update_pic(void *priv, int set) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; if (set) picint(1 << dsp->sb_irqnum); else @@ -205,8 +207,8 @@ sb_update_status(sb_dsp_t *dsp, int bit, int set) int masked = 0; switch (bit) { - case 0: default: + case 0: dsp->sb_irq8 = set; masked = dsp->sb_irqm8; break; @@ -249,7 +251,7 @@ sb_dsp_irq_update(void *priv, int set) static int sb_dsp_irq_pending(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; return dsp->sb_irq401; } @@ -408,28 +410,32 @@ sb_start_dma_i(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len) int sb_8_read_dma(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; + return dma_channel_read(dsp->sb_8_dmanum); } int sb_8_write_dma(void *priv, uint8_t val) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; + return dma_channel_write(dsp->sb_8_dmanum, val) == DMA_NODATA; } int sb_16_read_dma(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; + return dma_channel_read(dsp->sb_16_dmanum); } int sb_16_write_dma(void *priv, uint16_t val) { - sb_dsp_t *dsp = (sb_dsp_t *) priv; + const sb_dsp_t *dsp = (sb_dsp_t *) priv; + return dma_channel_write(dsp->sb_16_dmanum, val) == DMA_NODATA; } @@ -595,7 +601,9 @@ sb_exec_command(sb_dsp_t *dsp) case 0x75: /* 4-bit ADPCM output with reference */ dsp->sbref = dsp->dma_readb(dsp->dma_priv); dsp->sbstep = 0; - /* Fall through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x74: /* 4-bit ADPCM output */ sb_start_dma(dsp, 1, 0, ADPCM_4, dsp->sb_data[0] + (dsp->sb_data[1] << 8)); dsp->sbdat2 = dsp->dma_readb(dsp->dma_priv); @@ -917,6 +925,9 @@ sb_exec_command(sb_dsp_t *dsp) * 0FCh DSP Auxiliary Status SB16 * 0FDh DSP Command Status SB16 */ + + default: + break; } /* Update 8051 ram with the last DSP command. @@ -1046,6 +1057,9 @@ sb_read(uint16_t a, void *priv) sb_dsp_log("SB 16-bit ACK read 0xFF\n"); ret = 0xff; break; + + default: + break; } return ret; @@ -1192,9 +1206,9 @@ sb_dsp_dma_attach(sb_dsp_t *dsp, } void -pollsb(void *p) +pollsb(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) p; + sb_dsp_t *dsp = (sb_dsp_t *) priv; int tempi; int ref; int data[2]; @@ -1378,6 +1392,9 @@ pollsb(void *p) } else dsp->sbdatl = dsp->sbdatr = dsp->sbdat; break; + + default: + break; } if (dsp->sb_8_length < 0) { @@ -1426,6 +1443,9 @@ pollsb(void *p) dsp->sbdatr = data[1]; dsp->sb_16_length -= 2; break; + + default: + break; } if (dsp->sb_16_length < 0) { @@ -1451,9 +1471,9 @@ pollsb(void *p) } void -sb_poll_i(void *p) +sb_poll_i(void *priv) { - sb_dsp_t *dsp = (sb_dsp_t *) p; + sb_dsp_t *dsp = (sb_dsp_t *) priv; int processed = 0; timer_advance_u64(&dsp->input_timer, dsp->sblatchi); @@ -1486,6 +1506,9 @@ sb_poll_i(void *p) dsp->record_pos_read += 2; dsp->record_pos_read &= 0xFFFF; break; + + default: + break; } if (dsp->sb_8_length < 0) { @@ -1531,6 +1554,9 @@ sb_poll_i(void *p) dsp->record_pos_read += 2; dsp->record_pos_read &= 0xFFFF; break; + + default: + break; } if (dsp->sb_16_length < 0) { @@ -1565,6 +1591,7 @@ sb_dsp_update(sb_dsp_t *dsp) } void -sb_dsp_close(sb_dsp_t *dsp) +sb_dsp_close(UNUSED(sb_dsp_t *dsp)) { + // } diff --git a/src/sound/snd_sn76489.c b/src/sound/snd_sn76489.c index 56b3538d8..519219934 100644 --- a/src/sound/snd_sn76489.c +++ b/src/sound/snd_sn76489.c @@ -10,6 +10,7 @@ #include <86box/io.h> #include <86box/sound.h> #include <86box/snd_sn76489.h> +#include <86box/plat_unused.h> int sn76489_mute; @@ -33,7 +34,7 @@ sn76489_update(sn76489_t *sn76489) result += (int16_t) (volslog[sn76489->vol[c]] * 127); sn76489->count[c] -= (256 * sn76489->psgconst); - while ((int) sn76489->count[c] < 0) { + while (sn76489->count[c] < 0) { sn76489->count[c] += sn76489->latch[c]; sn76489->stat[c] = -sn76489->stat[c]; } @@ -41,7 +42,7 @@ sn76489_update(sn76489_t *sn76489) result += (((sn76489->shift & 1) ^ 1) * 127 * volslog[sn76489->vol[0]] * 2); sn76489->count[0] -= (512 * sn76489->psgconst); - while ((int) sn76489->count[0] < 0 && sn76489->latch[0]) { + while (sn76489->count[0] < 0 && sn76489->latch[0]) { sn76489->count[0] += (sn76489->latch[0] * 4); if (!(sn76489->noise & 4)) { if (sn76489->shift & 1) @@ -59,9 +60,9 @@ sn76489_update(sn76489_t *sn76489) } void -sn76489_get_buffer(int32_t *buffer, int len, void *p) +sn76489_get_buffer(int32_t *buffer, int len, void *priv) { - sn76489_t *sn76489 = (sn76489_t *) p; + sn76489_t *sn76489 = (sn76489_t *) priv; sn76489_update(sn76489); @@ -74,9 +75,9 @@ sn76489_get_buffer(int32_t *buffer, int len, void *p) } void -sn76489_write(uint16_t addr, uint8_t data, void *p) +sn76489_write(UNUSED(uint16_t addr), uint8_t data, void *priv) { - sn76489_t *sn76489 = (sn76489_t *) p; + sn76489_t *sn76489 = (sn76489_t *) priv; int freq; sn76489_update(sn76489); @@ -140,6 +141,9 @@ sn76489_write(uint16_t addr, uint8_t data, void *p) data &= 0xf; sn76489->vol[0] = 0xf - data; break; + + default: + break; } } else { if ((sn76489->firstdat & 0x70) == 0x60 && (sn76489->type == SN76496)) { @@ -197,7 +201,7 @@ sn76489_init(sn76489_t *sn76489, uint16_t base, uint16_t size, int type, int fre } void * -sn76489_device_init(const device_t *info) +sn76489_device_init(UNUSED(const device_t *info)) { sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); @@ -208,7 +212,7 @@ sn76489_device_init(const device_t *info) } void * -ncr8496_device_init(const device_t *info) +ncr8496_device_init(UNUSED(const device_t *info)) { sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); @@ -219,7 +223,7 @@ ncr8496_device_init(const device_t *info) } void * -tndy_device_init(const device_t *info) +tndy_device_init(UNUSED(const device_t *info)) { sn76489_t *sn76489 = malloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); @@ -232,9 +236,9 @@ tndy_device_init(const device_t *info) } void -sn76489_device_close(void *p) +sn76489_device_close(void *priv) { - sn76489_t *sn76489 = (sn76489_t *) p; + sn76489_t *sn76489 = (sn76489_t *) priv; free(sn76489); } diff --git a/src/sound/snd_speaker.c b/src/sound/snd_speaker.c index babc8aee1..693c3afc3 100644 --- a/src/sound/snd_speaker.c +++ b/src/sound/snd_speaker.c @@ -26,6 +26,7 @@ #include <86box/pit.h> #include <86box/snd_speaker.h> #include <86box/sound.h> +#include <86box/plat_unused.h> int speaker_mute = 0; int speaker_gated = 0; @@ -85,7 +86,7 @@ speaker_update(void) } void -speaker_get_buffer(int32_t *buffer, int len, void *p) +speaker_get_buffer(int32_t *buffer, int len, UNUSED(void *priv)) { int32_t val; diff --git a/src/sound/snd_ssi2001.c b/src/sound/snd_ssi2001.c index 7c2a18f5a..1f3c294ce 100644 --- a/src/sound/snd_ssi2001.c +++ b/src/sound/snd_ssi2001.c @@ -12,6 +12,7 @@ #include <86box/io.h> #include <86box/snd_resid.h> #include <86box/sound.h> +#include <86box/plat_unused.h> typedef struct ssi2001_t { void *psid; @@ -31,9 +32,9 @@ ssi2001_update(ssi2001_t *ssi2001) } static void -ssi2001_get_buffer(int32_t *buffer, int len, void *p) +ssi2001_get_buffer(int32_t *buffer, int len, void *priv) { - ssi2001_t *ssi2001 = (ssi2001_t *) p; + ssi2001_t *ssi2001 = (ssi2001_t *) priv; ssi2001_update(ssi2001); @@ -44,26 +45,26 @@ ssi2001_get_buffer(int32_t *buffer, int len, void *p) } static uint8_t -ssi2001_read(uint16_t addr, void *p) +ssi2001_read(uint16_t addr, void *priv) { - ssi2001_t *ssi2001 = (ssi2001_t *) p; + ssi2001_t *ssi2001 = (ssi2001_t *) priv; ssi2001_update(ssi2001); - return sid_read(addr, p); + return sid_read(addr, priv); } static void -ssi2001_write(uint16_t addr, uint8_t val, void *p) +ssi2001_write(uint16_t addr, uint8_t val, void *priv) { - ssi2001_t *ssi2001 = (ssi2001_t *) p; + ssi2001_t *ssi2001 = (ssi2001_t *) priv; ssi2001_update(ssi2001); - sid_write(addr, val, p); + sid_write(addr, val, priv); } void * -ssi2001_init(const device_t *info) +ssi2001_init(UNUSED(const device_t *info)) { ssi2001_t *ssi2001 = malloc(sizeof(ssi2001_t)); memset(ssi2001, 0, sizeof(ssi2001_t)); @@ -80,9 +81,9 @@ ssi2001_init(const device_t *info) } void -ssi2001_close(void *p) +ssi2001_close(void *priv) { - ssi2001_t *ssi2001 = (ssi2001_t *) p; + ssi2001_t *ssi2001 = (ssi2001_t *) priv; sid_close(ssi2001->psid); diff --git a/src/sound/snd_wss.c b/src/sound/snd_wss.c index a3a748374..a69d746da 100644 --- a/src/sound/snd_wss.c +++ b/src/sound/snd_wss.c @@ -33,6 +33,7 @@ #include <86box/timer.h> #include <86box/snd_ad1848.h> #include <86box/snd_opl.h> +#include <86box/plat_unused.h> /* 530, 11, 3 - 530=23 * 530, 11, 1 - 530=22 @@ -59,14 +60,14 @@ typedef struct wss_t { } wss_t; uint8_t -wss_read(uint16_t addr, void *priv) +wss_read(UNUSED(uint16_t addr), void *priv) { - wss_t *wss = (wss_t *) priv; + const wss_t *wss = (wss_t *) priv; return 4 | (wss->config & 0x40); } void -wss_write(uint16_t addr, uint8_t val, void *priv) +wss_write(UNUSED(uint16_t addr), uint8_t val, void *priv) { wss_t *wss = (wss_t *) priv; @@ -79,20 +80,25 @@ static void wss_get_buffer(int32_t *buffer, int len, void *priv) { wss_t *wss = (wss_t *) priv; + const int32_t *opl_buf = NULL; + + if (wss->opl_enabled) + opl_buf = wss->opl.update(wss->opl.priv); - int32_t *opl_buf = wss->opl.update(wss->opl.priv); ad1848_update(&wss->ad1848); for (int c = 0; c < len * 2; c++) { - buffer[c] += opl_buf[c]; + if (opl_buf) + buffer[c] += opl_buf[c]; buffer[c] += wss->ad1848.buffer[c] / 2; } - wss->opl.reset_buffer(wss->opl.priv); + if (wss->opl_enabled) + wss->opl.reset_buffer(wss->opl.priv); wss->ad1848.pos = 0; } void * -wss_init(const device_t *info) +wss_init(UNUSED(const device_t *info)) { wss_t *wss = malloc(sizeof(wss_t)); memset(wss, 0, sizeof(wss_t)); @@ -131,7 +137,7 @@ wss_init(const device_t *info) static uint8_t ncr_audio_mca_read(int port, void *priv) { - wss_t *wss = (wss_t *) priv; + const wss_t *wss = (wss_t *) priv; return wss->pos_regs[port & 7]; } @@ -186,12 +192,12 @@ ncr_audio_mca_write(int port, uint8_t val, void *priv) static uint8_t ncr_audio_mca_feedb(void *priv) { - wss_t *wss = (wss_t *) priv; + const wss_t *wss = (wss_t *) priv; return (wss->pos_regs[2] & 1); } void * -ncr_audio_init(const device_t *info) +ncr_audio_init(UNUSED(const device_t *info)) { wss_t *wss = malloc(sizeof(wss_t)); memset(wss, 0, sizeof(wss_t)); diff --git a/src/sound/snd_ym7128.c b/src/sound/snd_ym7128.c index e7cf37b2a..59e5691e9 100644 --- a/src/sound/snd_ym7128.c +++ b/src/sound/snd_ym7128.c @@ -5,12 +5,13 @@ #include <86box/86box.h> #include <86box/snd_ym7128.h> +#include <86box/plat_unused.h> static int attenuation[32]; static int tap_position[32]; void -ym7128_init(ym7128_t *ym7128) +ym7128_init(UNUSED(ym7128_t *ym7128)) { int c; double out = 65536.0; @@ -97,6 +98,9 @@ ym7128_write(ym7128_t *ym7128, uint8_t val) case 0x1e: ym7128->t[ym7128->reg_sel - 0x16] = tap_position[ym7128->dat & 0x1f]; break; + + default: + break; } ym7128->regs[ym7128->reg_sel] = ym7128->dat; } @@ -137,8 +141,8 @@ ym7128_apply(ym7128_t *ym7128, int16_t *buffer, int len) samp_l = (samp_l * ym7128->vl * 2) >> 16; samp_r = (samp_r * ym7128->vr * 2) >> 16; - buffer[c] += ((int32_t) samp_l + (int32_t) ym7128->prev_l) / 2; - buffer[c + 1] += ((int32_t) samp_r + (int32_t) ym7128->prev_r) / 2; + buffer[c] += (samp_l + (int32_t) ym7128->prev_l) / 2; + buffer[c + 1] += (samp_r + (int32_t) ym7128->prev_r) / 2; buffer[c + 2] += samp_l; buffer[c + 3] += samp_r; diff --git a/src/sound/sound.c b/src/sound/sound.c index 94fbad394..542528ccb 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -47,7 +47,7 @@ typedef struct { } SOUND_CARD; typedef struct { - void (*get_buffer)(int32_t *buffer, int len, void *p); + void (*get_buffer)(int32_t *buffer, int len, void *priv); void *priv; } sound_handler_t; @@ -76,7 +76,7 @@ static int cd_buf_update = CD_BUFLEN / SOUNDBUFLEN; static volatile int cdaudioon = 0; static int cd_thread_enable = 0; -static void (*filter_cd_audio)(int channel, double *buffer, void *p) = NULL; +static void (*filter_cd_audio)(int channel, double *buffer, void *priv) = NULL; static void *filter_cd_audio_p = NULL; static const device_t sound_none_device = { @@ -208,7 +208,7 @@ sound_card_get_from_internal_name(const char *s) int c = 0; while (sound_cards[c].device != NULL) { - if (!strcmp((char *) sound_cards[c].device->internal_name, s)) + if (!strcmp(sound_cards[c].device->internal_name, s)) return c; c++; } @@ -246,7 +246,7 @@ sound_cd_clean_buffers(void) } static void -sound_cd_thread(void *param) +sound_cd_thread(UNUSED(void *param)) { uint32_t lba; int r; @@ -425,24 +425,24 @@ sound_init(void) } void -sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *p), void *p) +sound_add_handler(void (*get_buffer)(int32_t *buffer, int len, void *priv), void *priv) { sound_handlers[sound_handlers_num].get_buffer = get_buffer; - sound_handlers[sound_handlers_num].priv = p; + sound_handlers[sound_handlers_num].priv = priv; sound_handlers_num++; } void -sound_set_cd_audio_filter(void (*filter)(int channel, double *buffer, void *p), void *p) +sound_set_cd_audio_filter(void (*filter)(int channel, double *buffer, void *priv), void *priv) { if ((filter_cd_audio == NULL) || (filter == NULL)) { filter_cd_audio = filter; - filter_cd_audio_p = p; + filter_cd_audio_p = priv; } } void -sound_poll(void *priv) +sound_poll(UNUSED(void *priv)) { timer_advance_u64(&sound_poll_timer, sound_poll_latch); @@ -459,7 +459,7 @@ sound_poll(void *priv) for (c = 0; c < SOUNDBUFLEN * 2; c++) { if (sound_is_float) - outbuffer_ex[c] = ((float) outbuffer[c]) / 32768.0; + outbuffer_ex[c] = ((float) outbuffer[c]) / (float) 32768.0; else { if (outbuffer[c] > 32767) outbuffer[c] = 32767; diff --git a/src/sound/xaudio2.c b/src/sound/xaudio2.c index 9f26fe517..0d9e7d909 100644 --- a/src/sound/xaudio2.c +++ b/src/sound/xaudio2.c @@ -33,6 +33,7 @@ #include <86box/midi.h> #include <86box/plat_dynld.h> #include <86box/sound.h> +#include <86box/plat_unused.h> #if defined(_WIN32) && !defined(USE_FAUDIO) static void *xaudio2_handle = NULL; @@ -57,32 +58,38 @@ static IXAudio2SourceVoice *srcvoicecd = NULL; #define BUFLEN SOUNDBUFLEN static void WINAPI -OnVoiceProcessingPassStart(IXAudio2VoiceCallback *callback, uint32_t bytesRequired) +OnVoiceProcessingPassStart(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(uint32_t bytesRequired)) { + // } static void WINAPI -OnVoiceProcessingPassEnd(IXAudio2VoiceCallback *callback) +OnVoiceProcessingPassEnd(UNUSED(IXAudio2VoiceCallback *callback)) { + // } static void WINAPI -OnStreamEnd(IXAudio2VoiceCallback *callback) +OnStreamEnd(UNUSED(IXAudio2VoiceCallback *callback)) { + // } static void WINAPI -OnBufferStart(IXAudio2VoiceCallback *callback, void *pBufferContext) +OnBufferStart(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(void *pBufferContext)) { + // } static void WINAPI -OnLoopEnd(IXAudio2VoiceCallback *callback, void *pBufferContext) +OnLoopEnd(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(void *pBufferContext)) { + // } static void WINAPI -OnVoiceError(IXAudio2VoiceCallback *callback, void *pBufferContext, HRESULT error) +OnVoiceError(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(void *pBufferContext), UNUSED(HRESULT error)) { + // } static void WINAPI -OnBufferEnd(IXAudio2VoiceCallback *callback, void *pBufferContext) +OnBufferEnd(UNUSED(IXAudio2VoiceCallback *callback), UNUSED(void *pBufferContext)) { free(pBufferContext); } @@ -167,7 +174,7 @@ inital(void) IXAudio2SourceVoice_Start(srcvoice, 0, XAUDIO2_COMMIT_NOW); IXAudio2SourceVoice_Start(srcvoicecd, 0, XAUDIO2_COMMIT_NOW); - char *mdn = midi_out_device_get_internal_name(midi_output_device_current); + const char *mdn = midi_out_device_get_internal_name(midi_output_device_current); if (strcmp(mdn, "none") && strcmp(mdn, SYSTEM_MIDI_INTERNAL_NAME)) { fmt.nSamplesPerSec = midi_freq; diff --git a/src/timer.c b/src/timer.c index dde6fbdbc..e863c2f21 100644 --- a/src/timer.c +++ b/src/timer.c @@ -123,7 +123,7 @@ timer_process(void) if (timer->flags & TIMER_SPLIT) timer_advance_ex(timer, 0); /* We're splitting a > 1 s period into multiple <= 1 s periods. */ else if (timer->callback != NULL) /* Make sure it's no NULL, so that we can have a NULL callback when no operation is needed. */ - timer->callback(timer->p); + timer->callback(timer->priv); } timer_target = timer_head->ts.ts32.integer; @@ -159,12 +159,12 @@ timer_init(void) } void -timer_add(pc_timer_t *timer, void (*callback)(void *p), void *priv, int start_timer) +timer_add(pc_timer_t *timer, void (*callback)(void *priv), void *priv, int start_timer) { memset(timer, 0, sizeof(pc_timer_t)); timer->callback = callback; - timer->p = priv; + timer->priv = priv; timer->flags = 0; timer->prev = timer->next = NULL; if (start_timer) diff --git a/src/unix/unix.c b/src/unix/unix.c index c9be5d80f..b56022474 100644 --- a/src/unix/unix.c +++ b/src/unix/unix.c @@ -247,8 +247,6 @@ plat_get_string(int i) return L"Press CTRL-END to release mouse"; case IDS_2079: return L"Press CTRL-END or middle button to release mouse"; - case IDS_2080: - return L"Failed to initialize FluidSynth"; case IDS_2131: return L"Invalid configuration"; case IDS_4099: @@ -259,16 +257,10 @@ plat_get_string(int i) return L"No PCap devices found"; case IDS_2096: return L"Invalid PCap device"; - case IDS_2111: - return L"Unable to initialize FreeType"; case IDS_2112: return L"Unable to initialize SDL, libsdl2 is required"; - case IDS_2132: - return L"libfreetype is required for ESC/P printer emulation."; case IDS_2133: return L"libgs is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files."; - case IDS_2134: - return L"libfluidsynth is required for FluidSynth MIDI output."; case IDS_2130: return L"Make sure libpcap is installed and that you are on a libpcap-compatible network connection."; case IDS_2115: diff --git a/src/upi42.c b/src/upi42.c index 79f4ec9c2..8348b32e4 100644 --- a/src/upi42.c +++ b/src/upi42.c @@ -972,7 +972,7 @@ upi42_dbb_write(UNUSED(uint16_t port), uint8_t val, void *priv) uint8_t upi42_sts_read(UNUSED(uint16_t port), void *priv) { - upi42_t *upi42 = (upi42_t *) priv; + const upi42_t *upi42 = (upi42_t *) priv; uint8_t ret = upi42->sts; upi42_log("UPI42: sts_read(%04X) = %02X\n", port, ret); diff --git a/src/usb.c b/src/usb.c index e715268af..0ed98fc12 100644 --- a/src/usb.c +++ b/src/usb.c @@ -146,9 +146,9 @@ usb_interrupt_ohci(usb_t *dev, uint32_t level) static uint8_t uhci_reg_read(uint16_t addr, void *priv) { - usb_t *dev = (usb_t *) priv; - uint8_t ret; - uint8_t *regs = dev->uhci_io; + const usb_t *dev = (usb_t *) priv; + uint8_t ret; + const uint8_t *regs = dev->uhci_io; addr &= 0x0000001f; @@ -262,8 +262,8 @@ typedef struct static uint8_t ohci_mmio_read(uint32_t addr, void *priv) { - usb_t *dev = (usb_t *) priv; - uint8_t ret = 0x00; + const usb_t *dev = (usb_t *) priv; + uint8_t ret = 0x00; #ifdef ENABLE_USB_LOG uint32_t old_addr = addr; #endif diff --git a/src/video/agpgart.c b/src/video/agpgart.c index 523fcc996..b8ae2bdc8 100644 --- a/src/video/agpgart.c +++ b/src/video/agpgart.c @@ -24,6 +24,7 @@ #include <86box/device.h> #include <86box/mem.h> #include <86box/agpgart.h> +#include <86box/plat_unused.h> #ifdef ENABLE_AGPGART_LOG int agpgart_do_log = ENABLE_AGPGART_LOG; @@ -129,7 +130,7 @@ agpgart_aperture_writel(uint32_t addr, uint32_t val, void *priv) } static void * -agpgart_init(const device_t *info) +agpgart_init(UNUSED(const device_t *info)) { agpgart_t *dev = malloc(sizeof(agpgart_t)); memset(dev, 0, sizeof(agpgart_t)); diff --git a/src/video/vid_8514a.c b/src/video/vid_8514a.c index 115105d7a..b4719a539 100644 --- a/src/video/vid_8514a.c +++ b/src/video/vid_8514a.c @@ -38,10 +38,10 @@ #include <86box/vid_svga_render.h> #include "cpu.h" -static void ibm8514_accel_outb(uint16_t port, uint8_t val, void *p); -static void ibm8514_accel_outw(uint16_t port, uint16_t val, void *p); -static uint8_t ibm8514_accel_inb(uint16_t port, void *p); -static uint16_t ibm8514_accel_inw(uint16_t port, void *p); +static void ibm8514_accel_outb(uint16_t port, uint8_t val, void *priv); +static void ibm8514_accel_outw(uint16_t port, uint16_t val, void *priv); +static uint8_t ibm8514_accel_inb(uint16_t port, void *priv); +static uint16_t ibm8514_accel_inw(uint16_t port, void *priv); #ifdef ENABLE_IBM8514_LOG int ibm8514_do_log = ENABLE_IBM8514_LOG; @@ -212,7 +212,7 @@ int ibm8514_has_vga = 0; int ibm8514_cpu_src(svga_t *svga) { - ibm8514_t *dev = &svga->dev8514; + const ibm8514_t *dev = &svga->dev8514; if (!(dev->accel.cmd & 0x100)) return 0; @@ -226,7 +226,7 @@ ibm8514_cpu_src(svga_t *svga) int ibm8514_cpu_dest(svga_t *svga) { - ibm8514_t *dev = &svga->dev8514; + const ibm8514_t *dev = &svga->dev8514; if (!(dev->accel.cmd & 0x100)) return 0; @@ -238,18 +238,18 @@ ibm8514_cpu_dest(svga_t *svga) } void -ibm8514_accel_out_pixtrans(svga_t *svga, uint16_t port, uint16_t val, int len) +ibm8514_accel_out_pixtrans(svga_t *svga, UNUSED(uint16_t port), uint16_t val, int len) { - ibm8514_t *dev = &svga->dev8514; - uint8_t nibble = 0; - uint32_t pixelxfer = 0; - uint32_t monoxfer = 0xffffffff; - int pixcnt = 0; - int pixcntl = (dev->accel.multifunc[0x0a] >> 6) & 3; - int frgd_mix = (dev->accel.frgd_mix >> 5) & 3; - int bkgd_mix = (dev->accel.bkgd_mix >> 5) & 3; - int cmd = dev->accel.cmd >> 13; - int and3 = dev->accel.cur_x & 3; + ibm8514_t *dev = &svga->dev8514; + uint8_t nibble = 0; + uint32_t pixelxfer = 0; + uint32_t monoxfer = 0xffffffff; + int pixcnt = 0; + int pixcntl = (dev->accel.multifunc[0x0a] >> 6) & 3; + int frgd_mix = (dev->accel.frgd_mix >> 5) & 3; + int bkgd_mix = (dev->accel.bkgd_mix >> 5) & 3; + int cmd = dev->accel.cmd >> 13; + int and3 = dev->accel.cur_x & 3; if (dev->accel.cmd & 0x100) { if (len != 1) { @@ -536,6 +536,9 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) case 0x92e8: if (len != 1) dev->test = val; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xd2e8: if (len == 1) dev->accel.err_term = (dev->accel.err_term & 0x3f00) | val; @@ -778,21 +781,24 @@ ibm8514_accel_out_fifo(svga_t *svga, uint16_t port, uint32_t val, int len) dev->accel.cmd_back = 0; } break; + + default: + break; } } void -ibm8514_ramdac_out(uint16_t port, uint8_t val, void *p) +ibm8514_ramdac_out(uint16_t port, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; svga_out(port, val, svga); } uint8_t -ibm8514_ramdac_in(uint16_t port, void *p) +ibm8514_ramdac_in(uint16_t port, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; uint8_t ret; ret = svga_in(port, svga); @@ -975,26 +981,29 @@ ibm8514_accel_out(uint16_t port, uint32_t val, svga_t *svga, int len) if (!val) break; dev->accel.advfunc_cntl = val & 7; - ibm8514_on = (dev->accel.advfunc_cntl & 1); - vga_on = !ibm8514_on; + ibm8514_on = (dev->accel.advfunc_cntl & 1); + vga_on = !ibm8514_on; ibm8514_log("IBM 8514/A: VGA ON = %i, val = %02x\n", vga_on, val); svga_recalctimings(svga); break; + + default: + break; } } } static void -ibm8514_accel_outb(uint16_t port, uint8_t val, void *p) +ibm8514_accel_outb(uint16_t port, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; ibm8514_accel_out(port, val, svga, 1); } static void -ibm8514_accel_outw(uint16_t port, uint16_t val, void *p) +ibm8514_accel_outw(uint16_t port, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; ibm8514_accel_out(port, val, svga, 2); } @@ -1004,8 +1013,8 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) ibm8514_t *dev = &svga->dev8514; uint32_t temp = 0; int cmd; - int vpos = dev->displine + svga->y_add; - int vblankend = svga->vblankstart + svga->crtc[0x16]; + int vpos = dev->displine + svga->y_add; + int vblankend = svga->vblankstart + svga->crtc[0x16]; switch (port) { case 0x2e8: @@ -1015,7 +1024,7 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) if (vpos >= svga->vblankstart || vpos <= vblankend) temp |= 2; } else { - if (vpos >= svga->vblankstart && vpos <= vblankend) + if (vpos >= svga->vblankstart && vpos <= vblankend) temp |= 2; } break; @@ -1050,7 +1059,7 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) if (vpos >= svga->vblankstart || vpos <= vblankend) dev->subsys_stat |= 1; } else { - if (vpos >= svga->vblankstart && vpos <= vblankend) + if (vpos >= svga->vblankstart && vpos <= vblankend) dev->subsys_stat |= 1; } if (len != 1) { @@ -1120,21 +1129,26 @@ ibm8514_accel_in(uint16_t port, svga_t *svga, int len) } } break; + + default: + break; } return temp; } static uint8_t -ibm8514_accel_inb(uint16_t port, void *p) +ibm8514_accel_inb(uint16_t port, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; + return ibm8514_accel_in(port, svga, 1); } static uint16_t -ibm8514_accel_inw(uint16_t port, void *p) +ibm8514_accel_inw(uint16_t port, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; + return ibm8514_accel_in(port, svga, 2); } @@ -1157,27 +1171,30 @@ ibm8514_short_stroke_start(int count, int cpu_input, uint32_t mix_dat, uint32_t } void -ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, int len) +ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, svga_t *svga, UNUSED(int len)) { - ibm8514_t *dev = &svga->dev8514; - uint16_t *vram_w = (uint16_t *)svga->vram; - uint16_t src_dat = 0, dest_dat, old_dest_dat; - int frgd_mix, bkgd_mix; - uint16_t clip_b = dev->accel.multifunc[3]; - uint16_t clip_r = dev->accel.multifunc[4]; - int pixcntl = (dev->accel.multifunc[0x0a] >> 6) & 3; - uint16_t mix_mask = ((svga->bpp == 8) || (svga->bpp == 24)) ? 0x80 : 0x8000; - uint16_t compare = dev->accel.color_cmp; - int compare_mode = dev->accel.multifunc[0x0a] & 0x38; - int cmd = dev->accel.cmd >> 13; - uint16_t wrt_mask = dev->accel.wrt_mask; - uint16_t rd_mask = dev->accel.rd_mask; - uint16_t rd_mask_polygon = dev->accel.rd_mask; - uint16_t frgd_color = dev->accel.frgd_color; - uint16_t bkgd_color = dev->accel.bkgd_color; - uint32_t old_mix_dat; - int and3 = dev->accel.cur_x & 3; - uint16_t poly_src = 0; + ibm8514_t *dev = &svga->dev8514; + uint16_t *vram_w = (uint16_t *) svga->vram; + uint16_t src_dat = 0; + uint16_t dest_dat; + uint16_t old_dest_dat; + int frgd_mix; + int bkgd_mix; + uint16_t clip_b = dev->accel.multifunc[3]; + uint16_t clip_r = dev->accel.multifunc[4]; + int pixcntl = (dev->accel.multifunc[0x0a] >> 6) & 3; + uint16_t mix_mask = ((svga->bpp == 8) || (svga->bpp == 24)) ? 0x80 : 0x8000; + uint16_t compare = dev->accel.color_cmp; + int compare_mode = dev->accel.multifunc[0x0a] & 0x38; + int cmd = dev->accel.cmd >> 13; + uint16_t wrt_mask = dev->accel.wrt_mask; + uint16_t rd_mask = dev->accel.rd_mask; + uint16_t rd_mask_polygon = dev->accel.rd_mask; + uint16_t frgd_color = dev->accel.frgd_color; + uint16_t bkgd_color = dev->accel.bkgd_color; + uint32_t old_mix_dat; + int and3 = dev->accel.cur_x & 3; + uint16_t poly_src = 0; if ((svga->bpp == 8) || (svga->bpp == 24)) { compare &= 0xff; @@ -1210,7 +1227,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat count >>= 3; } - if (((svga->bpp == 15) || (svga->bpp == 16))) { + if ((svga->bpp == 15) || (svga->bpp == 16)) { if ((dev->accel.cmd & 0x200) && (count == 2)) count >>= 1; } @@ -1318,13 +1335,16 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 3: src_dat = 0; break; + + default: + break; } READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); if ((compare_mode == 0) || ((compare_mode == 0x10) && (dest_dat >= compare)) || ((compare_mode == 0x18) && (dest_dat < compare)) || ((compare_mode == 0x20) && (dest_dat != compare)) || ((compare_mode == 0x28) && (dest_dat == compare)) || ((compare_mode == 0x30) && (dest_dat <= compare)) || ((compare_mode == 0x38) && (dest_dat > compare))) { - old_dest_dat = dest_dat; + 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); + dest_dat = (dest_dat & wrt_mask) | (old_dest_dat & ~wrt_mask); if (dev->accel.ssv_draw) { if ((dev->accel.cmd & 4) && dev->accel.ssv_len) { @@ -1375,13 +1395,17 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.cx++; dev->accel.cy++; break; + + default: + break; } dev->accel.ssv_len--; } } else { while (count-- && (dev->accel.ssv_len >= 0)) { - if ((dev->accel.cx >= dev->accel.clip_left && dev->accel.cx <= clip_r && dev->accel.cy >= dev->accel.clip_top && dev->accel.cy <= clip_b)) { + if ((dev->accel.cx >= dev->accel.clip_left) && (dev->accel.cx <= clip_r) && + (dev->accel.cy >= dev->accel.clip_top) && (dev->accel.cy <= clip_b)) { switch ((mix_dat & mix_mask) ? frgd_mix : bkgd_mix) { case 0: src_dat = bkgd_color; @@ -1395,6 +1419,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 3: src_dat = 0; break; + + default: + break; } READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); @@ -1452,6 +1479,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cx++; break; + + default: + break; } } else dev->accel.err_term += dev->accel.desty_axstp; @@ -1482,6 +1512,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cy++; break; + + default: + break; } dev->accel.ssv_len--; @@ -1579,6 +1612,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 3: src_dat = 0; break; + + default: + break; } READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); @@ -1697,6 +1733,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.cx++; dev->accel.cy++; break; + + default: + break; } dev->accel.sy--; @@ -1728,6 +1767,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 3: src_dat = 0; break; + + default: + break; } READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); @@ -1783,6 +1825,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cx++; break; + + default: + break; } } else dev->accel.err_term += dev->accel.desty_axstp; @@ -1813,6 +1858,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cy++; break; + + default: + break; } dev->accel.sy--; @@ -1847,6 +1895,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 3: src_dat = 0; break; + + default: + break; } READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); @@ -1902,6 +1953,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cx++; break; + + default: + break; } } else dev->accel.err_term += dev->accel.desty_axstp; @@ -1932,6 +1986,9 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat case 0xe0: dev->accel.cy++; break; + + default: + break; } dev->accel.sy--; @@ -1966,10 +2023,10 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat dev->accel.cy |= ~0x5ff; if (dev->local && dev->accel.ge_offset && (svga->bpp == 24)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); else - dev->accel.dest = dev->accel.cy * dev->pitch; - + dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.fill_state = 0; if (cmd == 4) @@ -2016,7 +2073,7 @@ ibm8514_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat } else { if (!(dev->accel.cmd & 0x40) && (frgd_mix == 2) && (bkgd_mix == 2) && (pixcntl == 0) && (cmd == 2)) { if (!(dev->accel.sx & 1)) { - dev->accel.output = 1; + dev->accel.output = 1; if (dev->local && dev->accel.ge_offset && (svga->bpp == 24)) dev->accel.newdest_out = (dev->accel.ge_offset << 2) + ((dev->accel.cy + 1) * dev->pitch); else @@ -2067,6 +2124,9 @@ rect_fill_pix: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2161,6 +2221,9 @@ rect_fill_pix: case 0xe0: dev->accel.cx++; break; + + default: + break; } dev->accel.sx--; @@ -2200,6 +2263,9 @@ rect_fill_pix: case 0xe0: dev->accel.cy++; break; + + default: + break; } dev->accel.dest = dev->accel.cy * dev->pitch; @@ -2239,6 +2305,9 @@ rect_fill_pix: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2282,9 +2351,9 @@ rect_fill_pix: dev->accel.cy--; if (dev->local && dev->accel.ge_offset && (svga->bpp == 24)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); else - dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.dest = dev->accel.cy * dev->pitch; dev->accel.sy--; return; @@ -2320,6 +2389,9 @@ rect_fill_pix: case 3: src_dat = 0; break; + + default: + break; } } @@ -2371,9 +2443,9 @@ rect_fill_pix: dev->accel.cy--; if (dev->local && dev->accel.ge_offset && (svga->bpp == 24)) - dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); + dev->accel.dest = (dev->accel.ge_offset << 2) + (dev->accel.cy * dev->pitch); else - dev->accel.dest = dev->accel.cy * dev->pitch; + dev->accel.dest = dev->accel.cy * dev->pitch; dev->accel.sy--; return; @@ -2556,6 +2628,9 @@ rect_fill_pix: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2632,6 +2707,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2699,6 +2777,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2762,6 +2843,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, poly_src); @@ -2838,6 +2922,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + dev->accel.cx, dest_dat); @@ -2890,15 +2977,15 @@ rect_fill: case 5: /*Draw Polygon Boundary Line*/ if (!cpu_input) { - dev->accel.cx = dev->accel.cur_x; - dev->accel.cy = dev->accel.cur_y; + dev->accel.cx = dev->accel.cur_x; + dev->accel.cy = dev->accel.cur_y; if (dev->accel.cur_x >= 0x600) dev->accel.cx |= ~0x5ff; if (dev->accel.cur_y >= 0x600) dev->accel.cy |= ~0x5ff; dev->accel.oldcy = dev->accel.cy; - dev->accel.sy = 0; + dev->accel.sy = 0; if (ibm8514_cpu_src(svga)) { dev->data_available = 0; @@ -2926,6 +3013,9 @@ rect_fill: case 3: src_dat = 0; break; + + default: + break; } READ((dev->accel.cy * dev->pitch) + dev->accel.cx, dest_dat); @@ -2989,6 +3079,9 @@ rect_fill: case 0xe0: dev->accel.cx++; break; + + default: + break; } } else dev->accel.err_term += dev->accel.desty_axstp; @@ -3023,6 +3116,9 @@ rect_fill: dev->accel.oldcy = dev->accel.cy; dev->accel.cy++; break; + + default: + break; } dev->accel.sy++; @@ -3111,6 +3207,9 @@ bitblt_pix: } } break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3162,7 +3261,7 @@ bitblt_pix: dev->accel.cy--; } - dev->accel.src = dev->accel.cy * dev->pitch; + dev->accel.src = dev->accel.cy * dev->pitch; dev->accel.dest = dev->accel.dy * dev->pitch; dev->accel.sy--; return; @@ -3200,6 +3299,9 @@ bitblt_pix: } } break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3307,6 +3409,9 @@ bitblt_pix: } } break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3385,6 +3490,9 @@ bitblt: case 3: READ(dev->accel.src + dev->accel.cx, src_dat); break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3459,6 +3567,9 @@ bitblt: case 3: READ(dev->accel.src + dev->accel.cx, src_dat); break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3514,13 +3625,15 @@ bitblt: } } else { if ((svga->bpp == 24) && dev->local && (dev->accel.cmd == 0xc2b5)) { - int64_t x, cx, dx; + int64_t cx; + int64_t dx; - cx = (int64_t)dev->accel.cx; - dx = (int64_t)dev->accel.dx; + cx = (int64_t) dev->accel.cx; + dx = (int64_t) dev->accel.dx; while (1) { - if (((dx) >= (((int64_t)dev->accel.clip_left) * 3) && (dx) <= (((uint64_t)clip_r) * 3) && dev->accel.dy >= (dev->accel.clip_top << 1) && dev->accel.dy <= (clip_b << 1))) { + if ((dx >= (((int64_t)dev->accel.clip_left) * 3)) && (dx <= (((uint64_t)clip_r) * 3)) && + (dev->accel.dy >= (dev->accel.clip_top << 1)) && (dev->accel.dy <= (clip_b << 1))) { READ(dev->accel.src + (dev->accel.ge_offset << 2) + cx, src_dat); READ(dev->accel.dest + (dev->accel.ge_offset << 2) + dx, dest_dat); @@ -3540,7 +3653,8 @@ bitblt: } while (count-- && dev->accel.sy >= 0) { - if (dev->accel.dx >= dev->accel.clip_left && dev->accel.dx <= clip_r && dev->accel.dy >= dev->accel.clip_top && dev->accel.dy <= clip_b) { + if ((dev->accel.dx >= dev->accel.clip_left) && (dev->accel.dx <= clip_r) && + (dev->accel.dy >= dev->accel.clip_top) && (dev->accel.dy <= clip_b)) { if (pixcntl == 3) { if (!(dev->accel.cmd & 0x10) && ((frgd_mix != 3) || (bkgd_mix != 3))) { READ(dev->accel.src + dev->accel.cx, mix_dat); @@ -3570,6 +3684,9 @@ bitblt: } } break; + + default: + break; } READ(dev->accel.dest + dev->accel.dx, dest_dat); @@ -3632,6 +3749,9 @@ bitblt: } } break; + + default: + break; } } @@ -3746,7 +3866,7 @@ ibm8514_poll(ibm8514_t *dev, svga_t *svga) dev->linepos = 0; if (dev->dispon) { if (dev->sc == dev->rowcount) { - dev->sc = 0; + dev->sc = 0; dev->maback += (dev->rowoffset << 3); if (dev->interlace) dev->maback += (dev->rowoffset << 3); @@ -3822,13 +3942,13 @@ ibm8514_recalctimings(svga_t *svga) ibm8514_t *dev = &svga->dev8514; if (ibm8514_on) { - dev->h_disp = (dev->hdisp + 1) << 3; - dev->pitch = (dev->accel.advfunc_cntl & 4) ? 1024 : 640; - dev->h_total = (dev->htotal + 1); - dev->v_total = (dev->vtotal + 1); - dev->v_syncstart = (dev->vsyncstart + 1); - dev->rowcount = !!(dev->disp_cntl & 0x08); - dev->dispend = ((dev->vdisp >> 1) + 1); + dev->h_disp = (dev->hdisp + 1) << 3; + dev->pitch = (dev->accel.advfunc_cntl & 4) ? 1024 : 640; + dev->h_total = (dev->htotal + 1); + dev->v_total = (dev->vtotal + 1); + dev->v_syncstart = (dev->vsyncstart + 1); + dev->rowcount = !!(dev->disp_cntl & 0x08); + dev->dispend = ((dev->vdisp >> 1) + 1); if (dev->dispend == 766) dev->dispend = 768; @@ -3838,9 +3958,9 @@ ibm8514_recalctimings(svga_t *svga) if (dev->accel.advfunc_cntl & 4) { if (!vga_on && dev->ibm_mode) { if (dev->h_disp == 8) { - dev->h_disp = 1024; - dev->dispend = 768; - dev->v_total = 1536; + dev->h_disp = 1024; + dev->dispend = 768; + dev->v_total = 1536; dev->v_syncstart = 1536; } } @@ -3858,7 +3978,7 @@ ibm8514_recalctimings(svga_t *svga) } if (ibm8514_has_vga) { - dev->pitch = dev->ext_pitch; + dev->pitch = dev->ext_pitch; dev->rowoffset = dev->ext_crt_pitch; } else dev->rowoffset = 128; @@ -3868,7 +3988,7 @@ ibm8514_recalctimings(svga_t *svga) } else { if (!vga_on && dev->ibm_mode) { if (dev->h_disp == 1024) { - dev->h_disp = 640; + dev->h_disp = 640; dev->dispend = 480; } } @@ -3883,7 +4003,7 @@ ibm8514_recalctimings(svga_t *svga) } if (ibm8514_has_vga) { - dev->pitch = dev->ext_pitch; + dev->pitch = dev->ext_pitch; dev->rowoffset = dev->ext_crt_pitch; } else dev->rowoffset = 128; @@ -3899,8 +4019,8 @@ ibm8514_recalctimings(svga_t *svga) static uint8_t ibm8514_mca_read(int port, void *priv) { - svga_t *svga = (svga_t *) priv; - ibm8514_t *dev = &svga->dev8514; + const svga_t *svga = (svga_t *) priv; + const ibm8514_t *dev = &svga->dev8514; return (dev->pos_regs[port & 7]); } @@ -3922,15 +4042,14 @@ ibm8514_mca_write(int port, uint8_t val, void *priv) static uint8_t ibm8514_mca_feedb(void *priv) { - svga_t *svga = (svga_t *) priv; - ibm8514_t *dev = &svga->dev8514; + const svga_t *svga = (svga_t *) priv; + const ibm8514_t *dev = &svga->dev8514; return dev->pos_regs[2] & 1; } -static void - * - ibm8514_init(const device_t *info) +static void * +ibm8514_init(const device_t *info) { if (svga_get_pri() == NULL) return NULL; @@ -3944,9 +4063,9 @@ static void dev->vram_mask = dev->vram_size - 1; dev->map8 = svga->pallook; - dev->type = info->flags; + dev->type = info->flags; dev->ibm_mode = 1; - dev->bpp = 8; + dev->bpp = 8; ibm8514_io_set(svga); @@ -3960,9 +4079,9 @@ static void } static void -ibm8514_close(void *p) +ibm8514_close(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; ibm8514_t *dev = &svga->dev8514; if (dev) { @@ -3972,17 +4091,17 @@ ibm8514_close(void *p) } static void -ibm8514_speed_changed(void *p) +ibm8514_speed_changed(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; svga_recalctimings(svga); } static void -ibm8514_force_redraw(void *p) +ibm8514_force_redraw(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; svga->fullchange = changeframecount; } diff --git a/src/video/vid_ati18800.c b/src/video/vid_ati18800.c index 2b37eb6fd..5847faa39 100644 --- a/src/video/vid_ati18800.c +++ b/src/video/vid_ati18800.c @@ -62,9 +62,9 @@ typedef struct ati18800_t { static video_timings_t timing_ati18800 = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; static void -ati18800_out(uint16_t addr, uint8_t val, void *p) +ati18800_out(uint16_t addr, uint8_t val, void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; svga_t *svga = &ati18800->svga; uint8_t old; @@ -93,6 +93,9 @@ ati18800_out(uint16_t addr, uint8_t val, void *p) case 0xb3: ati_eeprom_write(&ati18800->eeprom, val & 8, val & 2, val & 1); break; + + default: + break; } break; @@ -118,14 +121,17 @@ ati18800_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } static uint8_t -ati18800_in(uint16_t addr, void *p) +ati18800_in(uint16_t addr, void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; svga_t *svga = &ati18800->svga; uint8_t temp = 0xff; @@ -165,7 +171,7 @@ ati18800_in(uint16_t addr, void *p) static void ati18800_recalctimings(svga_t *svga) { - ati18800_t *ati18800 = (ati18800_t *) svga->p; + const ati18800_t *ati18800 = (ati18800_t *) svga->priv; if (svga->crtc[0x17] & 4) { svga->vtotal <<= 1; @@ -193,11 +199,9 @@ ati18800_init(const device_t *info) video_inform(VIDEO_FLAG_TYPE_SPECIAL, &timing_ati18800); switch (info->local) { -#if defined(DEV_BRANCH) && defined(USE_VGAWONDER) - case ATI18800_WONDER: -#endif default: #if defined(DEV_BRANCH) && defined(USE_VGAWONDER) + case ATI18800_WONDER: rom_init(&ati18800->bios_rom, BIOS_ROM_PATH_WONDER, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); break; #endif @@ -254,9 +258,9 @@ ati18800_available(void) } static void -ati18800_close(void *p) +ati18800_close(void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; svga_close(&ati18800->svga); @@ -264,17 +268,17 @@ ati18800_close(void *p) } static void -ati18800_speed_changed(void *p) +ati18800_speed_changed(void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; svga_recalctimings(&ati18800->svga); } static void -ati18800_force_redraw(void *p) +ati18800_force_redraw(void *priv) { - ati18800_t *ati18800 = (ati18800_t *) p; + ati18800_t *ati18800 = (ati18800_t *) priv; ati18800->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ati28800.c b/src/video/vid_ati28800.c index b41e1ca82..aa5800d1c 100644 --- a/src/video/vid_ati28800.c +++ b/src/video/vid_ati28800.c @@ -108,9 +108,9 @@ ati28800_log(const char *fmt, ...) static void ati28800_recalctimings(svga_t *svga); static void -ati28800_out(uint16_t addr, uint8_t val, void *p) +ati28800_out(uint16_t addr, uint8_t val, void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; + ati28800_t *ati28800 = (ati28800_t *) priv; svga_t *svga = &ati28800->svga; uint8_t old; @@ -169,6 +169,9 @@ ati28800_out(uint16_t addr, uint8_t val, void *p) if ((old ^ val) & 2) svga_recalctimings(svga); break; + + default: + break; } break; @@ -205,14 +208,17 @@ ati28800_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } static void -ati28800k_out(uint16_t addr, uint8_t val, void *p) +ati28800k_out(uint16_t addr, uint8_t val, void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; + ati28800_t *ati28800 = (ati28800_t *) priv; svga_t *svga = &ati28800->svga; uint16_t oldaddr = addr; @@ -225,7 +231,7 @@ ati28800k_out(uint16_t addr, uint8_t val, void *p) ati28800->ksc5601_mode_enabled = val & 0x20; svga_recalctimings(svga); } - ati28800_out(oldaddr, val, p); + ati28800_out(oldaddr, val, priv); break; case 0x3DD: ati28800->port_03dd_val = val; @@ -259,20 +265,23 @@ ati28800k_out(uint16_t addr, uint8_t val, void *p) if (val & 2) ati28800->in_get_korean_font_kind_set = 1; break; + + default: + break; } break; } break; default: - ati28800_out(oldaddr, val, p); + ati28800_out(oldaddr, val, priv); break; } } static uint8_t -ati28800_in(uint16_t addr, void *p) +ati28800_in(uint16_t addr, void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; + ati28800_t *ati28800 = (ati28800_t *) priv; svga_t *svga = &ati28800->svga; uint8_t temp; @@ -346,12 +355,12 @@ ati28800_in(uint16_t addr, void *p) } static uint8_t -ati28800k_in(uint16_t addr, void *p) +ati28800k_in(uint16_t addr, void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; - svga_t *svga = &ati28800->svga; - uint16_t oldaddr = addr; - uint8_t temp = 0xFF; + ati28800_t *ati28800 = (ati28800_t *) priv; + const svga_t *svga = &ati28800->svga; + uint16_t oldaddr = addr; + uint8_t temp = 0xFF; if (addr != 0x3da) ati28800_log("ati28800k_in : %04X ", addr); @@ -380,7 +389,7 @@ ati28800k_in(uint16_t addr, void *p) } break; default: - temp = ati28800_in(oldaddr, p); + temp = ati28800_in(oldaddr, priv); break; } if (addr != 0x3da) @@ -391,7 +400,7 @@ ati28800k_in(uint16_t addr, void *p) static void ati28800_recalctimings(svga_t *svga) { - ati28800_t *ati28800 = (ati28800_t *) svga->p; + const ati28800_t *ati28800 = (ati28800_t *) svga->priv; if (ati28800->regs[0xa3] & 0x10) svga->ma_latch |= 0x10000; @@ -507,8 +516,14 @@ ati28800_recalctimings(svga_t *svga) svga->ma_latch <<= 1; } break; + + default: + break; } break; + + default: + break; } } } @@ -517,7 +532,7 @@ ati28800_recalctimings(svga_t *svga) static void ati28800k_recalctimings(svga_t *svga) { - ati28800_t *ati28800 = (ati28800_t *) svga->p; + const ati28800_t *ati28800 = (ati28800_t *) svga->priv; ati28800_recalctimings(svga); @@ -550,8 +565,8 @@ ati28800k_init(const device_t *info) ati28800->ksc5601_mode_enabled = 0; switch (ati28800->type_korean) { - case 0: default: + case 0: rom_init(&ati28800->bios_rom, BIOS_ATIKOR_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); loadfont(FONT_ATIKOR_PATH, 6); break; @@ -705,9 +720,9 @@ ati28800_close(void *priv) } static void -ati28800_speed_changed(void *p) +ati28800_speed_changed(void *priv) { - ati28800_t *ati28800 = (ati28800_t *) p; + ati28800_t *ati28800 = (ati28800_t *) priv; svga_recalctimings(&ati28800->svga); } diff --git a/src/video/vid_ati68860_ramdac.c b/src/video/vid_ati68860_ramdac.c index 107b63039..5a8de5455 100644 --- a/src/video/vid_ati68860_ramdac.c +++ b/src/video/vid_ati68860_ramdac.c @@ -48,13 +48,16 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/plat_unused.h> typedef struct ati68860_ramdac_t { uint8_t regs[16]; void (*render)(struct svga_t *svga); - int dac_addr, dac_pos; - int dac_r, dac_g; + int dac_addr; + int dac_pos; + int dac_r; + int dac_g; PALETTE pal; uint32_t pallook[2]; @@ -113,6 +116,9 @@ ati68860_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga) ramdac->dac_pos = 0; ramdac->dac_addr = (ramdac->dac_addr + 1) & 255; break; + + default: + break; } break; case 0xb: @@ -153,6 +159,9 @@ ati68860_ramdac_out(uint16_t addr, uint8_t val, void *p, svga_t *svga) case 0xc: svga_set_ramdac_type(svga, (val & 1) ? RAMDAC_6BIT : RAMDAC_8BIT); break; + + default: + break; } break; } @@ -217,7 +226,7 @@ ati68860_set_ramdac_type(void *p, int type) } static void * -ati68860_ramdac_init(const device_t *info) +ati68860_ramdac_init(UNUSED(const device_t *info)) { ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) malloc(sizeof(ati68860_ramdac_t)); memset(ramdac, 0, sizeof(ati68860_ramdac_t)); diff --git a/src/video/vid_ati_eeprom.c b/src/video/vid_ati_eeprom.c index 10b37212d..2f4746e86 100644 --- a/src/video/vid_ati_eeprom.c +++ b/src/video/vid_ati_eeprom.c @@ -26,53 +26,54 @@ #include <86box/timer.h> #include <86box/nvr.h> #include <86box/vid_ati_eeprom.h> +#include <86box/plat_fallthrough.h> void ati_eeprom_load(ati_eeprom_t *eeprom, char *fn, int type) { - FILE *f; + FILE *fp; int size; eeprom->type = type; strncpy(eeprom->fn, fn, sizeof(eeprom->fn) - 1); - f = nvr_fopen(eeprom->fn, "rb"); + fp = nvr_fopen(eeprom->fn, "rb"); size = eeprom->type ? 512 : 128; - if (!f) { + if (!fp) { memset(eeprom->data, 0xff, size); return; } - if (fread(eeprom->data, 1, size, f) != size) + if (fread(eeprom->data, 1, size, fp) != size) memset(eeprom->data, 0, size); - fclose(f); + fclose(fp); } void ati_eeprom_load_mach8(ati_eeprom_t *eeprom, char *fn) { - FILE *f; + FILE *fp; int size; eeprom->type = 0; strncpy(eeprom->fn, fn, sizeof(eeprom->fn) - 1); - f = nvr_fopen(eeprom->fn, "rb"); + fp = nvr_fopen(eeprom->fn, "rb"); size = 128; - if (!f) { /*The ATI Graphics Ultra bios expects an immediate write to nvram if none is present at boot time otherwise + if (!fp) { /*The ATI Graphics Ultra bios expects an immediate write to nvram if none is present at boot time otherwise it would hang the machine.*/ memset(eeprom->data, 0, size); - f = nvr_fopen(eeprom->fn, "wb"); - fwrite(eeprom->data, 1, size, f); + fp = nvr_fopen(eeprom->fn, "wb"); + fwrite(eeprom->data, 1, size, fp); } - if (fread(eeprom->data, 1, size, f) != size) + if (fread(eeprom->data, 1, size, fp) != size) memset(eeprom->data, 0, size); - fclose(f); + fclose(fp); } void ati_eeprom_save(ati_eeprom_t *eeprom) { - FILE *f = nvr_fopen(eeprom->fn, "wb"); - if (!f) + FILE *fp = nvr_fopen(eeprom->fn, "wb"); + if (!fp) return; - fwrite(eeprom->data, 1, eeprom->type ? 512 : 128, f); - fclose(f); + fwrite(eeprom->data, 1, eeprom->type ? 512 : 128, fp); + fclose(fp); } void @@ -93,7 +94,9 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) if (!dat) break; eeprom->state = EEPROM_OPCODE; - /* fall through */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case EEPROM_OPCODE: eeprom->opcode = (eeprom->opcode << 1) | (dat ? 1 : 0); eeprom->count--; @@ -119,6 +122,9 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) eeprom->state = EEPROM_INPUT; eeprom->dat = 0; break; + + default: + break; } } break; @@ -160,6 +166,9 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) case EEPROM_OP_EWEN: eeprom->wp = 0; break; + + default: + break; } eeprom->state = EEPROM_IDLE; eeprom->out = 1; @@ -183,9 +192,15 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) eeprom->state = EEPROM_IDLE; eeprom->out = 1; break; + + default: + break; } } break; + + default: + break; } } eeprom->oldena = ena; @@ -200,6 +215,9 @@ ati_eeprom_write(ati_eeprom_t *eeprom, int ena, int clk, int dat) eeprom->state = EEPROM_IDLE; } break; + + default: + break; } } } diff --git a/src/video/vid_ati_mach64.c b/src/video/vid_ati_mach64.c index 8c32929ce..c28d4c0aa 100644 --- a/src/video/vid_ati_mach64.c +++ b/src/video/vid_ati_mach64.c @@ -67,8 +67,7 @@ enum { FIFO_WRITE_DWORD = (0x03 << 24) }; -typedef struct -{ +typedef struct fifo_entry_t { uint32_t addr_type; uint32_t val; } fifo_entry_t; @@ -92,7 +91,8 @@ typedef struct mach64_t { uint8_t regs[256]; int index; - int type, pci; + int type; + int pci; uint8_t pci_regs[256]; uint8_t int_line; @@ -157,17 +157,21 @@ typedef struct mach64_t { uint32_t ovr_wid_top_bottom; uint32_t pat_cntl; - uint32_t pat_reg0, pat_reg1; + uint32_t pat_reg0; + uint32_t pat_reg1; - uint32_t sc_left_right, sc_top_bottom; + uint32_t sc_left_right; + uint32_t sc_top_bottom; - uint32_t scratch_reg0, scratch_reg1; + uint32_t scratch_reg0; + uint32_t scratch_reg1; uint32_t src_cntl; uint32_t src_off_pitch; uint32_t src_y_x; uint32_t src_y_x_start; - uint32_t src_height1_width1, src_height2_width2; + uint32_t src_height1_width1; + uint32_t src_height2_width2; uint32_t write_mask; uint32_t chain_mask; @@ -175,33 +179,54 @@ typedef struct mach64_t { uint32_t linear_base; uint32_t io_base; - struct - { + struct { int op; - int dst_x, dst_y; - int dst_x_start, dst_y_start; - int src_x, src_y; - int src_x_start, src_y_start; - int xinc, yinc; - int x_count, y_count; + int dst_x; + int dst_y; + int dst_x_start; + int dst_y_start; + int src_x; + int src_y; + int src_x_start; + int src_y_start; + int xinc; + int yinc; + int x_count; + int y_count; int xx_count; - int src_x_count, src_y_count; - int src_width1, src_height1; - int src_width2, src_height2; - uint32_t src_offset, src_pitch; - uint32_t dst_offset, dst_pitch; - int mix_bg, mix_fg; - int source_bg, source_fg, source_mix; + int src_x_count; + int src_y_count; + int src_width1; + int src_height1; + int src_width2; + int src_height2; + uint32_t src_offset; + uint32_t src_pitch; + uint32_t dst_offset; + uint32_t dst_pitch; + int mix_bg; + int mix_fg; + int source_bg; + int source_fg; + int source_mix; int source_host; - int dst_width, dst_height; + int dst_width; + int dst_height; int busy; int pattern[8][8]; uint8_t pattern_clr4x2[2][4]; uint8_t pattern_clr8x1[8]; - int sc_left, sc_right, sc_top, sc_bottom; - int dst_pix_width, src_pix_width, host_pix_width; - int dst_size, src_size, host_size; + int sc_left; + int sc_right; + int sc_top; + int sc_bottom; + int dst_pix_width; + int src_pix_width; + int host_pix_width; + int dst_size; + int src_size; + int host_size; uint32_t dp_bkgd_clr; uint32_t dp_frgd_clr; @@ -217,7 +242,8 @@ typedef struct mach64_t { } accel; fifo_entry_t fifo[FIFO_SIZE]; - atomic_int fifo_read_idx, fifo_write_idx; + atomic_int fifo_read_idx; + atomic_int fifo_write_idx; thread_t *fifo_thread; event_t *wake_fifo_thread; @@ -238,26 +264,32 @@ typedef struct mach64_t { uint32_t config_stat0; - uint32_t cur_clr0, cur_clr1; + uint32_t cur_clr0; + uint32_t cur_clr1; uint32_t overlay_dat[1024]; - uint32_t overlay_graphics_key_clr, overlay_graphics_key_msk; - uint32_t overlay_video_key_clr, overlay_video_key_msk; + uint32_t overlay_graphics_key_clr; + uint32_t overlay_graphics_key_msk; + uint32_t overlay_video_key_clr; + uint32_t overlay_video_key_msk; uint32_t overlay_key_cntl; uint32_t overlay_scale_inc; uint32_t overlay_scale_cntl; - uint32_t overlay_y_x_start, overlay_y_x_end; + uint32_t overlay_y_x_start; + uint32_t overlay_y_x_end; uint32_t scaler_height_width; int scaler_format; int scaler_update; - uint32_t buf_offset[2], buf_pitch[2]; + uint32_t buf_offset[2]; + uint32_t buf_pitch[2]; int overlay_v_acc; uint8_t thread_run; - void *i2c, *ddc; + void *i2c; + void *ddc; } mach64_t; static video_timings_t timing_mach64_isa = { .type = VIDEO_ISA, .write_b = 3, .write_w = 3, .write_l = 6, .read_b = 5, .read_w = 5, .read_l = 10 }; @@ -362,9 +394,9 @@ mach64_log(const char *fmt, ...) #endif void -mach64_out(uint16_t addr, uint8_t val, void *p) +mach64_out(uint16_t addr, uint8_t val, void *priv) { - mach64_t *mach64 = p; + mach64_t *mach64 = priv; svga_t *svga = &mach64->svga; uint8_t old; @@ -426,14 +458,17 @@ mach64_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } uint8_t -mach64_in(uint16_t addr, void *p) +mach64_in(uint16_t addr, void *priv) { - mach64_t *mach64 = p; + mach64_t *mach64 = priv; svga_t *svga = &mach64->svga; if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) @@ -459,6 +494,9 @@ mach64_in(uint16_t addr, void *p) if (svga->crtcreg > 0x18) return 0xff; return svga->crtc[svga->crtcreg]; + + default: + break; } return svga_in(addr, svga); } @@ -466,7 +504,7 @@ mach64_in(uint16_t addr, void *p) void mach64_recalctimings(svga_t *svga) { - mach64_t *mach64 = (mach64_t *) svga->p; + const mach64_t *mach64 = (mach64_t *) svga->priv; if (((mach64->crtc_gen_cntl >> 24) & 3) == 3) { svga->vtotal = (mach64->crtc_v_total_disp & 2047) + 1; @@ -518,6 +556,9 @@ mach64_recalctimings(svga_t *svga) svga->hdisp <<= 3; svga->rowoffset <<= 1; break; + + default: + break; } svga->vram_display_mask = mach64->vram_mask; @@ -568,6 +609,9 @@ mach64_updatemapping(mach64_t *mach64) mem_mapping_set_addr(&svga->mapping, 0xb8000, 0x08000); svga->banked_mask = 0x7fff; break; + + default: + break; } mach64_log("Mach64 linear aperture = %08x.\n", mach64->linear_base); @@ -577,27 +621,16 @@ mach64_updatemapping(mach64_t *mach64) /*8 MB aperture*/ mem_mapping_set_addr(&mach64->linear_mapping, mach64->linear_base, (8 << 20) - 0x4000); mem_mapping_set_addr(&mach64->mmio_linear_mapping, mach64->linear_base + ((8 << 20) - 0x4000), 0x4000); - } else if ((mach64->config_cntl & 3) == 1) { + } else { /*4 MB aperture*/ mem_mapping_set_addr(&mach64->linear_mapping, mach64->linear_base, (4 << 20) - 0x4000); mem_mapping_set_addr(&mach64->mmio_linear_mapping, mach64->linear_base + ((4 << 20) - 0x4000), 0x4000); - } else { - /*Disable aperture on reserved values*/ - mem_mapping_disable(&mach64->linear_mapping); - mem_mapping_disable(&mach64->mmio_linear_mapping); } } else { - if ((mach64->config_cntl & 3) == 2) { - /*2*8 MB aperture*/ - mem_mapping_set_addr(&mach64->linear_mapping, mach64->linear_base, (8 << 20) - 0x4000); - mem_mapping_set_addr(&mach64->mmio_linear_mapping, mach64->linear_base + ((8 << 20) - 0x4000), 0x4000); - mem_mapping_set_addr(&mach64->mmio_linear_mapping_2, mach64->linear_base + ((16 << 20) - 0x4000), 0x4000); - } else { - /*Disable aperture on reserved values*/ - mem_mapping_disable(&mach64->linear_mapping); - mem_mapping_disable(&mach64->mmio_linear_mapping); - mem_mapping_disable(&mach64->mmio_linear_mapping_2); - } + /*2*8 MB aperture*/ + mem_mapping_set_addr(&mach64->linear_mapping, mach64->linear_base, (8 << 20) - 0x4000); + mem_mapping_set_addr(&mach64->mmio_linear_mapping, mach64->linear_base + ((8 << 20) - 0x4000), 0x4000); + mem_mapping_set_addr(&mach64->mmio_linear_mapping_2, mach64->linear_base + ((16 << 20) - 0x4000), 0x4000); } } else { mem_mapping_disable(&mach64->linear_mapping); @@ -635,7 +668,7 @@ mach64_wait_fifo_idle(mach64_t *mach64) } #define READ8(addr, var) \ - switch ((addr) & 3) { \ + switch ((addr) &3) { \ case 0: \ ret = (var) &0xff; \ break; \ @@ -651,7 +684,7 @@ mach64_wait_fifo_idle(mach64_t *mach64) } #define WRITE8(addr, var, val) \ - switch ((addr) & 3) { \ + switch ((addr) &3) { \ case 0: \ var = (var & 0xffffff00) | (val); \ break; \ @@ -705,7 +738,9 @@ mach64_accel_write_fifo(mach64_t *mach64, uint32_t addr, uint8_t val) case 0x11e: case 0x11f: WRITE8(addr, mach64->dst_height_width, val); - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x113: if (((addr & 0x3ff) == 0x11b || (addr & 0x3ff) == 0x11f || (addr & 0x3ff) == 0x113) && !(val & 0x80)) { mach64_start_fill(mach64); @@ -928,7 +963,9 @@ mach64_accel_write_fifo(mach64_t *mach64, uint32_t addr, uint8_t val) case 0x2a4: case 0x2a5: addr += 2; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x2aa: case 0x2ab: WRITE8(addr, mach64->sc_left_right, val); @@ -943,7 +980,9 @@ mach64_accel_write_fifo(mach64_t *mach64, uint32_t addr, uint8_t val) case 0x2b0: case 0x2b1: addr += 2; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x2b6: case 0x2b7: WRITE8(addr, mach64->sc_top_bottom, val); @@ -1033,6 +1072,9 @@ mach64_accel_write_fifo(mach64_t *mach64, uint32_t addr, uint8_t val) else mach64->host_cntl &= ~HOST_BYTE_ALIGN; break; + + default: + break; } } static void @@ -1193,11 +1235,11 @@ mach64_queue(mach64_t *mach64, uint32_t addr, uint32_t val, uint32_t type) void mach64_start_fill(mach64_t *mach64) { - mach64->accel.dst_x = 0; - mach64->accel.dst_y = 0; + mach64->accel.dst_x = 0; + mach64->accel.dst_y = 0; mach64->accel.dst_x_start = (mach64->dst_y_x >> 16) & 0xfff; - if (((mach64->dst_y_x >> 16) & 0x1000)) + if ((mach64->dst_y_x >> 16) & 0x1000) mach64->accel.dst_x_start |= ~0xfff; mach64->accel.dst_y_start = mach64->dst_y_x & 0x3fff; if (mach64->dst_y_x & 0x4000) @@ -1211,14 +1253,14 @@ mach64_start_fill(mach64_t *mach64) mach64->accel.dst_width = (mach64->accel.dst_width & ~7) + 8; } - mach64->accel.x_count = mach64->accel.dst_width; + mach64->accel.x_count = mach64->accel.dst_width; mach64->accel.xx_count = 0; - mach64->accel.src_x = 0; - mach64->accel.src_y = 0; + mach64->accel.src_x = 0; + mach64->accel.src_y = 0; mach64->accel.src_x_start = (mach64->src_y_x >> 16) & 0xfff; - if (((mach64->src_y_x >> 16) & 0x1000)) + if ((mach64->src_y_x >> 16) & 0x1000) mach64->accel.src_x_start |= ~0xfff; mach64->accel.src_y_start = mach64->src_y_x & 0x3fff; if (mach64->src_y_x & 0x4000) @@ -1334,14 +1376,14 @@ void mach64_start_line(mach64_t *mach64) { mach64->accel.dst_x = (mach64->dst_y_x >> 16) & 0xfff; - if (((mach64->dst_y_x >> 16) & 0x1000)) + if ((mach64->dst_y_x >> 16) & 0x1000) mach64->accel.dst_x |= ~0xfff; mach64->accel.dst_y = mach64->dst_y_x & 0x3fff; if (mach64->dst_y_x & 0x4000) mach64->accel.dst_y |= ~0x3fff; mach64->accel.src_x = (mach64->src_y_x >> 16) & 0xfff; - if (((mach64->src_y_x >> 16) & 0x1000)) + if ((mach64->src_y_x >> 16) & 0x1000) mach64->accel.src_x |= ~0xfff; mach64->accel.src_y = mach64->src_y_x & 0x3fff; if (mach64->src_y_x & 0x4000) @@ -1519,12 +1561,12 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) switch (mach64->accel.op) { case OP_RECT: while (count) { - uint8_t write_mask = 0; - uint32_t src_dat = 0; + uint8_t write_mask = 0; + uint32_t src_dat = 0; uint32_t dest_dat; uint32_t host_dat = 0; uint32_t old_dest_dat; - int mix = 0; + int mix = 0; int dst_x; int dst_y; int src_x; @@ -1554,6 +1596,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 2: count -= 32; break; + + default: + break; } } else count--; @@ -1581,9 +1626,12 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) READ(mach64->accel.src_offset + (src_y * mach64->accel.src_pitch) + src_x, mix, WIDTH_1BIT); } break; + + default: + break; } - if ((dst_x) >= mach64->accel.sc_left && (dst_x) <= mach64->accel.sc_right && (dst_y) >= mach64->accel.sc_top && (dst_y) <= mach64->accel.sc_bottom) { + if (dst_x >= mach64->accel.sc_left && dst_x <= mach64->accel.sc_right && dst_y >= mach64->accel.sc_top && dst_y <= mach64->accel.sc_bottom) { switch (mix ? mach64->accel.source_fg : mach64->accel.source_bg) { case SRC_HOST: src_dat = host_dat; @@ -1652,7 +1700,7 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) } if (!(mach64->dst_cntl & DST_POLYGON_EN) || mach64->accel.poly_draw) { - READ(mach64->accel.dst_offset + ((dst_y) * mach64->accel.dst_pitch) + (dst_x), dest_dat, mach64->accel.dst_size); + READ(mach64->accel.dst_offset + ((dst_y) *mach64->accel.dst_pitch) + (dst_x), dest_dat, mach64->accel.dst_size); switch (mach64->accel.clr_cmp_fn) { case 1: /*TRUE*/ @@ -1664,6 +1712,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 5: /*DST_CLR == CLR_CMP_CLR*/ cmp_clr = (((mach64->accel.clr_cmp_src) ? src_dat : dest_dat) & mach64->accel.clr_cmp_mask) == mach64->accel.clr_cmp_clr; break; + + default: + break; } if (!cmp_clr) { @@ -1716,8 +1767,8 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) mach64->accel.x_count--; if (mach64->accel.x_count <= 0) { mach64->accel.xx_count = 0; - mach64->accel.x_count = mach64->accel.dst_width; - mach64->accel.dst_x = 0; + mach64->accel.x_count = mach64->accel.dst_width; + mach64->accel.dst_x = 0; mach64->accel.dst_y += mach64->accel.yinc; mach64->accel.src_x_start = (mach64->src_y_x >> 16) & 0xfff; mach64->accel.src_x_count = mach64->accel.src_width1; @@ -1769,7 +1820,7 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) { int x = 0; while (count) { - uint32_t src_dat = 0; + uint32_t src_dat = 0; uint32_t dest_dat; uint32_t host_dat = 0; int mix = 0; @@ -1788,6 +1839,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 2: count -= 32; break; + + default: + break; } } else count--; @@ -1811,6 +1865,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case MONO_SRC_BLITSRC: READ(mach64->accel.src_offset + (mach64->accel.src_y * mach64->accel.src_pitch) + mach64->accel.src_x, mix, WIDTH_1BIT); break; + + default: + break; } if ((mach64->accel.dst_x >= mach64->accel.sc_left) && (mach64->accel.dst_x <= mach64->accel.sc_right) && (mach64->accel.dst_y >= mach64->accel.sc_top) && (mach64->accel.dst_y <= mach64->accel.sc_bottom)) { @@ -1852,6 +1909,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 5: /*DST_CLR == CLR_CMP_CLR*/ cmp_clr = (((mach64->accel.clr_cmp_src) ? src_dat : dest_dat) & mach64->accel.clr_cmp_mask) == mach64->accel.clr_cmp_clr; break; + + default: + break; } if (!cmp_clr) @@ -1895,7 +1955,7 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) } } else { while (count) { - uint32_t src_dat = 0; + uint32_t src_dat = 0; uint32_t dest_dat; uint32_t host_dat = 0; int mix = 0; @@ -1915,6 +1975,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 2: count -= 32; break; + + default: + break; } } else count--; @@ -1976,6 +2039,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) case 5: /*DST_CLR == CLR_CMP_CLR*/ cmp_clr = (((mach64->accel.clr_cmp_src) ? src_dat : dest_dat) & mach64->accel.clr_cmp_mask) == mach64->accel.clr_cmp_clr; break; + + default: + break; } if (!cmp_clr) @@ -2013,6 +2079,9 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) mach64->accel.src_y++; mach64->accel.dst_y++; break; + + default: + break; } mach64_log("x %i y %i err %i inc %i dec %i\n", mach64->accel.dst_x, mach64->accel.dst_y, mach64->accel.err, mach64->dst_bres_inc, mach64->dst_bres_dec); if (mach64->accel.err >= 0) { @@ -2039,12 +2108,18 @@ mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64) mach64->accel.src_x++; mach64->accel.dst_x++; break; + + default: + break; } } else mach64->accel.err += mach64->dst_bres_inc; } } break; + + default: + break; } } @@ -2144,6 +2219,9 @@ pll_write(mach64_t *mach64, uint32_t addr, uint8_t val) mach64_log(" %g\n", mach64->pll_freq[c]); } break; + + default: + break; } } @@ -2151,7 +2229,7 @@ pll_write(mach64_t *mach64, uint32_t addr, uint8_t val) static void mach64_vblank_start(svga_t *svga) { - mach64_t *mach64 = (mach64_t *) svga->p; + mach64_t *mach64 = (mach64_t *) svga->priv; int overlay_cmp_mix = (mach64->overlay_key_cntl >> 8) & 0xf; mach64->crtc_int_cntl |= 4; @@ -2173,9 +2251,9 @@ mach64_vblank_start(svga_t *svga) } uint8_t -mach64_ext_readb(uint32_t addr, void *p) +mach64_ext_readb(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; uint8_t ret = 0xff; if (!(addr & 0x400)) { @@ -2789,10 +2867,11 @@ mach64_ext_readb(uint32_t addr, void *p) return ret; } uint16_t -mach64_ext_readw(uint32_t addr, void *p) +mach64_ext_readw(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + const mach64_t *mach64 = (mach64_t *) priv; uint16_t ret; + if (!(addr & 0x400)) { mach64_log("nmach64_ext_readw: addr=%04x\n", addr); ret = 0xffff; @@ -2808,8 +2887,8 @@ mach64_ext_readw(uint32_t addr, void *p) break; default: - ret = mach64_ext_readb(addr, p); - ret |= mach64_ext_readb(addr + 1, p) << 8; + ret = mach64_ext_readb(addr, priv); + ret |= mach64_ext_readb(addr + 1, priv) << 8; break; } if ((addr & 0x3fc) != 0x018) @@ -2817,10 +2896,11 @@ mach64_ext_readw(uint32_t addr, void *p) return ret; } uint32_t -mach64_ext_readl(uint32_t addr, void *p) +mach64_ext_readl(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; - uint32_t ret; + const mach64_t *mach64 = (mach64_t *) priv; + uint32_t ret; + if (!(addr & 0x400)) { mach64_log("nmach64_ext_readl: addr=%04x\n", addr); ret = 0xffffffff; @@ -2840,8 +2920,8 @@ mach64_ext_readl(uint32_t addr, void *p) break; default: - ret = mach64_ext_readw(addr, p); - ret |= mach64_ext_readw(addr + 2, p) << 16; + ret = mach64_ext_readw(addr, priv); + ret |= mach64_ext_readw(addr + 2, priv) << 16; break; } if ((addr & 0x3fc) != 0x018) @@ -2850,9 +2930,9 @@ mach64_ext_readl(uint32_t addr, void *p) } void -mach64_ext_writeb(uint32_t addr, uint8_t val, void *p) +mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; mach64_log("mach64_ext_writeb : addr %08X val %02X\n", addr, val); @@ -2952,6 +3032,9 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *p) case 0xa7: WRITE8(addr, mach64->buf_pitch[1], val); break; + + default: + break; } mach64_log("nmach64_ext_writeb: addr=%04x val=%02x\n", addr, val); @@ -3169,18 +3252,21 @@ mach64_ext_writeb(uint32_t addr, uint8_t val, void *p) if (mach64->type != MACH64_GX) WRITE8(addr, mach64->config_stat0, val); break; + + default: + break; } } void -mach64_ext_writew(uint32_t addr, uint16_t val, void *p) +mach64_ext_writew(uint32_t addr, uint16_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_ext_writew : addr %08X val %04X\n", addr, val); if (!(addr & 0x400)) { mach64_log("mach64_ext_writew: addr=%04x val=%04x\n", addr, val); - mach64_ext_writeb(addr, val, p); - mach64_ext_writeb(addr + 1, val >> 8, p); + mach64_ext_writeb(addr, val, priv); + mach64_ext_writeb(addr + 1, val >> 8, priv); } else if (addr & 0x300) { if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) mach64_accel_write_fifo_w(mach64, addr & 0x3fe, val); @@ -3189,22 +3275,22 @@ mach64_ext_writew(uint32_t addr, uint16_t val, void *p) } else switch (addr & 0x3fe) { default: - mach64_ext_writeb(addr, val, p); - mach64_ext_writeb(addr + 1, val >> 8, p); + mach64_ext_writeb(addr, val, priv); + mach64_ext_writeb(addr + 1, val >> 8, priv); break; } } void -mach64_ext_writel(uint32_t addr, uint32_t val, void *p) +mach64_ext_writel(uint32_t addr, uint32_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; if ((addr & 0x3c0) != 0x200) mach64_log("mach64_ext_writel : addr %08X val %08X\n", addr, val); if (!(addr & 0x400)) { mach64_log("mach64_ext_writel: addr=%04x val=%08x\n", addr, val); - mach64_ext_writew(addr, val, p); - mach64_ext_writew(addr + 2, val >> 16, p); + mach64_ext_writew(addr, val, priv); + mach64_ext_writew(addr + 2, val >> 16, priv); } else if (addr & 0x300) { if (((mach64->crtc_gen_cntl >> 8) & 7) == BPP_24) mach64_accel_write_fifo_l(mach64, addr & 0x3fc, val); @@ -3213,17 +3299,17 @@ mach64_ext_writel(uint32_t addr, uint32_t val, void *p) } else switch (addr & 0x3fc) { default: - mach64_ext_writew(addr, val, p); - mach64_ext_writew(addr + 2, val >> 16, p); + mach64_ext_writew(addr, val, priv); + mach64_ext_writew(addr + 2, val >> 16, priv); break; } } uint8_t -mach64_ext_inb(uint16_t port, void *p) +mach64_ext_inb(uint16_t port, void *priv) { - mach64_t *mach64 = (mach64_t *) p; - uint8_t ret; + mach64_t *mach64 = (mach64_t *) priv; + uint8_t ret = 0xff; switch (port) { case 0x02ec: @@ -3234,135 +3320,135 @@ mach64_ext_inb(uint16_t port, void *p) case 0x7eed: case 0x7eee: case 0x7eef: - ret = mach64_ext_readb(0x400 | 0x00 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x00 | (port & 3), priv); break; case 0x0aec: case 0x0aed: case 0x0aee: case 0x0aef: - ret = mach64_ext_readb(0x400 | 0x08 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x08 | (port & 3), priv); break; case 0x0eec: case 0x0eed: case 0x0eee: case 0x0eef: - ret = mach64_ext_readb(0x400 | 0x0c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x0c | (port & 3), priv); break; case 0x12ec: case 0x12ed: case 0x12ee: case 0x12ef: - ret = mach64_ext_readb(0x400 | 0x10 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x10 | (port & 3), priv); break; case 0x16ec: case 0x16ed: case 0x16ee: case 0x16ef: - ret = mach64_ext_readb(0x400 | 0x14 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x14 | (port & 3), priv); break; case 0x1aec: - ret = mach64_ext_readb(0x400 | 0x18, p); + ret = mach64_ext_readb(0x400 | 0x18, priv); break; case 0x1eec: case 0x1eed: case 0x1eee: case 0x1eef: - ret = mach64_ext_readb(0x400 | 0x1c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x1c | (port & 3), priv); break; case 0x22ec: case 0x22ed: case 0x22ee: case 0x22ef: - ret = mach64_ext_readb(0x400 | 0x40 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x40 | (port & 3), priv); break; case 0x26ec: case 0x26ed: case 0x26ee: case 0x26ef: - ret = mach64_ext_readb(0x400 | 0x44 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x44 | (port & 3), priv); break; case 0x2aec: case 0x2aed: case 0x2aee: case 0x2aef: - ret = mach64_ext_readb(0x400 | 0x48 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x48 | (port & 3), priv); break; case 0x2eec: case 0x2eed: case 0x2eee: case 0x2eef: - ret = mach64_ext_readb(0x400 | 0x60 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x60 | (port & 3), priv); break; case 0x32ec: case 0x32ed: case 0x32ee: case 0x32ef: - ret = mach64_ext_readb(0x400 | 0x64 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x64 | (port & 3), priv); break; case 0x36ec: case 0x36ed: case 0x36ee: case 0x36ef: - ret = mach64_ext_readb(0x400 | 0x68 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x68 | (port & 3), priv); break; case 0x3aec: case 0x3aed: case 0x3aee: case 0x3aef: - ret = mach64_ext_readb(0x400 | 0x6c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x6c | (port & 3), priv); break; case 0x3eec: case 0x3eed: case 0x3eee: case 0x3eef: - ret = mach64_ext_readb(0x400 | 0x70 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x70 | (port & 3), priv); break; case 0x42ec: case 0x42ed: case 0x42ee: case 0x42ef: - ret = mach64_ext_readb(0x400 | 0x80 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x80 | (port & 3), priv); break; case 0x46ec: case 0x46ed: case 0x46ee: case 0x46ef: - ret = mach64_ext_readb(0x400 | 0x84 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x84 | (port & 3), priv); break; case 0x4aec: case 0x4aed: case 0x4aee: case 0x4aef: - ret = mach64_ext_readb(0x400 | 0x90 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x90 | (port & 3), priv); break; case 0x52ec: case 0x52ed: case 0x52ee: case 0x52ef: - ret = mach64_ext_readb(0x400 | 0xb0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xb0 | (port & 3), priv); break; case 0x56ec: - ret = mach64_ext_readb(0x400 | 0xb4, p); + ret = mach64_ext_readb(0x400 | 0xb4, priv); break; case 0x56ed: case 0x56ee: - ret = mach64_ext_readb(0x400 | 0xb5, p); + ret = mach64_ext_readb(0x400 | 0xb5, priv); break; case 0x5aec: - ret = mach64_ext_readb(0x400 | 0xb8, p); + ret = mach64_ext_readb(0x400 | 0xb8, priv); break; case 0x5aed: case 0x5aee: - ret = mach64_ext_readb(0x400 | 0xb9, p); + ret = mach64_ext_readb(0x400 | 0xb9, priv); break; case 0x5eec: @@ -3379,14 +3465,14 @@ mach64_ext_inb(uint16_t port, void *p) case 0x62ed: case 0x62ee: case 0x62ef: - ret = mach64_ext_readb(0x400 | 0xc4 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xc4 | (port & 3), priv); break; case 0x66ec: case 0x66ed: case 0x66ee: case 0x66ef: - ret = mach64_ext_readb(0x400 | 0xd0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xd0 | (port & 3), priv); break; case 0x6aec: @@ -3401,14 +3487,14 @@ mach64_ext_inb(uint16_t port, void *p) case 0x6eed: case 0x6eee: case 0x6eef: - ret = mach64_ext_readb(0x400 | 0xe0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xe0 | (port & 3), priv); break; case 0x72ec: case 0x72ed: case 0x72ee: case 0x72ef: - ret = mach64_ext_readb(0x400 | 0xe4 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xe4 | (port & 3), priv); break; default: @@ -3419,33 +3505,33 @@ mach64_ext_inb(uint16_t port, void *p) return ret; } uint16_t -mach64_ext_inw(uint16_t port, void *p) +mach64_ext_inw(uint16_t port, void *priv) { uint16_t ret; switch (port) { default: - ret = mach64_ext_inb(port, p); - ret |= (mach64_ext_inb(port + 1, p) << 8); + ret = mach64_ext_inb(port, priv); + ret |= (mach64_ext_inb(port + 1, priv) << 8); break; } mach64_log("mach64_ext_inw : port %04X ret %04X\n", port, ret); return ret; } uint32_t -mach64_ext_inl(uint16_t port, void *p) +mach64_ext_inl(uint16_t port, void *priv) { uint32_t ret; switch (port) { case 0x56ec: - ret = mach64_ext_readl(0x400 | 0xb4, p); + ret = mach64_ext_readl(0x400 | 0xb4, priv); break; case 0x5aec: - ret = mach64_ext_readl(0x400 | 0xb8, p); + ret = mach64_ext_readl(0x400 | 0xb8, priv); break; default: - ret = mach64_ext_inw(port, p); - ret |= (mach64_ext_inw(port + 2, p) << 16); + ret = mach64_ext_inw(port, priv); + ret |= (mach64_ext_inw(port + 2, priv) << 16); break; } mach64_log("mach64_ext_inl : port %04X ret %08X\n", port, ret); @@ -3453,9 +3539,9 @@ mach64_ext_inl(uint16_t port, void *p) } void -mach64_ext_outb(uint16_t port, uint8_t val, void *p) +mach64_ext_outb(uint16_t port, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_ext_outb : port %04X val %02X\n", port, val); switch (port) { @@ -3467,128 +3553,128 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *p) case 0x7eed: case 0x7eee: case 0x7eef: - mach64_ext_writeb(0x400 | 0x00 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x00 | (port & 3), val, priv); break; case 0x0aec: case 0x0aed: case 0x0aee: case 0x0aef: - mach64_ext_writeb(0x400 | 0x08 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x08 | (port & 3), val, priv); break; case 0x0eec: case 0x0eed: case 0x0eee: case 0x0eef: - mach64_ext_writeb(0x400 | 0x0c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x0c | (port & 3), val, priv); break; case 0x16ec: case 0x16ed: case 0x16ee: case 0x16ef: - mach64_ext_writeb(0x400 | 0x14 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x14 | (port & 3), val, priv); break; case 0x1aec: - mach64_ext_writeb(0x400 | 0x18, val, p); + mach64_ext_writeb(0x400 | 0x18, val, priv); break; case 0x1eec: case 0x1eed: case 0x1eee: case 0x1eef: - mach64_ext_writeb(0x400 | 0x1c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x1c | (port & 3), val, priv); break; case 0x22ec: case 0x22ed: case 0x22ee: case 0x22ef: - mach64_ext_writeb(0x400 | 0x40 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x40 | (port & 3), val, priv); break; case 0x26ec: case 0x26ed: case 0x26ee: case 0x26ef: - mach64_ext_writeb(0x400 | 0x44 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x44 | (port & 3), val, priv); break; case 0x2aec: case 0x2aed: case 0x2aee: case 0x2aef: - mach64_ext_writeb(0x400 | 0x48 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x48 | (port & 3), val, priv); break; case 0x2eec: case 0x2eed: case 0x2eee: case 0x2eef: - mach64_ext_writeb(0x400 | 0x60 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x60 | (port & 3), val, priv); break; case 0x32ec: case 0x32ed: case 0x32ee: case 0x32ef: - mach64_ext_writeb(0x400 | 0x64 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x64 | (port & 3), val, priv); break; case 0x36ec: case 0x36ed: case 0x36ee: case 0x36ef: - mach64_ext_writeb(0x400 | 0x68 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x68 | (port & 3), val, priv); break; case 0x3aec: case 0x3aed: case 0x3aee: case 0x3aef: - mach64_ext_writeb(0x400 | 0x6c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x6c | (port & 3), val, priv); break; case 0x3eec: case 0x3eed: case 0x3eee: case 0x3eef: - mach64_ext_writeb(0x400 | 0x70 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x70 | (port & 3), val, priv); break; case 0x42ec: case 0x42ed: case 0x42ee: case 0x42ef: - mach64_ext_writeb(0x400 | 0x80 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x80 | (port & 3), val, priv); break; case 0x46ec: case 0x46ed: case 0x46ee: case 0x46ef: - mach64_ext_writeb(0x400 | 0x84 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x84 | (port & 3), val, priv); break; case 0x4aec: case 0x4aed: case 0x4aee: case 0x4aef: - mach64_ext_writeb(0x400 | 0x90 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x90 | (port & 3), val, priv); break; case 0x52ec: case 0x52ed: case 0x52ee: case 0x52ef: - mach64_ext_writeb(0x400 | 0xb0 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xb0 | (port & 3), val, priv); break; case 0x56ec: - mach64_ext_writeb(0x400 | 0xb4, val, p); + mach64_ext_writeb(0x400 | 0xb4, val, priv); break; case 0x56ed: case 0x56ee: - mach64_ext_writeb(0x400 | 0xb5, val, p); + mach64_ext_writeb(0x400 | 0xb5, val, priv); break; case 0x5aec: - mach64_ext_writeb(0x400 | 0xb8, val, p); + mach64_ext_writeb(0x400 | 0xb8, val, priv); break; case 0x5aed: case 0x5aee: - mach64_ext_writeb(0x400 | 0xb9, val, p); + mach64_ext_writeb(0x400 | 0xb9, val, priv); break; case 0x5eec: @@ -3605,14 +3691,14 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *p) case 0x62ed: case 0x62ee: case 0x62ef: - mach64_ext_writeb(0x400 | 0xc4 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xc4 | (port & 3), val, priv); break; case 0x66ec: case 0x66ed: case 0x66ee: case 0x66ef: - mach64_ext_writeb(0x400 | 0xd0 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xd0 | (port & 3), val, priv); break; case 0x6aec: @@ -3625,32 +3711,32 @@ mach64_ext_outb(uint16_t port, uint8_t val, void *p) } } void -mach64_ext_outw(uint16_t port, uint16_t val, void *p) +mach64_ext_outw(uint16_t port, uint16_t val, void *priv) { mach64_log("mach64_ext_outw : port %04X val %04X\n", port, val); switch (port) { default: - mach64_ext_outb(port, val, p); - mach64_ext_outb(port + 1, val >> 8, p); + mach64_ext_outb(port, val, priv); + mach64_ext_outb(port + 1, val >> 8, priv); break; } } void -mach64_ext_outl(uint16_t port, uint32_t val, void *p) +mach64_ext_outl(uint16_t port, uint32_t val, void *priv) { mach64_log("mach64_ext_outl : port %04X val %08X\n", port, val); switch (port) { default: - mach64_ext_outw(port, val, p); - mach64_ext_outw(port + 2, val >> 16, p); + mach64_ext_outw(port, val, priv); + mach64_ext_outw(port + 2, val >> 16, priv); break; } } static uint8_t -mach64_block_inb(uint16_t port, void *p) +mach64_block_inb(uint16_t port, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; uint8_t ret; ret = mach64_ext_readb(0x400 | (port & 0x3ff), mach64); @@ -3658,9 +3744,9 @@ mach64_block_inb(uint16_t port, void *p) return ret; } static uint16_t -mach64_block_inw(uint16_t port, void *p) +mach64_block_inw(uint16_t port, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; uint16_t ret; ret = mach64_ext_readw(0x400 | (port & 0x3ff), mach64); @@ -3668,9 +3754,9 @@ mach64_block_inw(uint16_t port, void *p) return ret; } static uint32_t -mach64_block_inl(uint16_t port, void *p) +mach64_block_inl(uint16_t port, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; uint32_t ret; ret = mach64_ext_readl(0x400 | (port & 0x3ff), mach64); @@ -3679,51 +3765,51 @@ mach64_block_inl(uint16_t port, void *p) } static void -mach64_block_outb(uint16_t port, uint8_t val, void *p) +mach64_block_outb(uint16_t port, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_block_outb : port %04X val %02X\n ", port, val); mach64_ext_writeb(0x400 | (port & 0x3ff), val, mach64); } static void -mach64_block_outw(uint16_t port, uint16_t val, void *p) +mach64_block_outw(uint16_t port, uint16_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_block_outw : port %04X val %04X\n ", port, val); mach64_ext_writew(0x400 | (port & 0x3ff), val, mach64); } static void -mach64_block_outl(uint16_t port, uint32_t val, void *p) +mach64_block_outl(uint16_t port, uint32_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64_log("mach64_block_outl : port %04X val %08X\n ", port, val); mach64_ext_writel(0x400 | (port & 0x3ff), val, mach64); } void -mach64_write(uint32_t addr, uint8_t val, void *p) +mach64_write(uint32_t addr, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; svga_write_linear(addr, val, svga); } void -mach64_writew(uint32_t addr, uint16_t val, void *p) +mach64_writew(uint32_t addr, uint16_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; svga_writew_linear(addr, val, svga); } void -mach64_writel(uint32_t addr, uint32_t val, void *p) +mach64_writel(uint32_t addr, uint32_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; @@ -3731,9 +3817,9 @@ mach64_writel(uint32_t addr, uint32_t val, void *p) } uint8_t -mach64_read(uint32_t addr, void *p) +mach64_read(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; uint8_t ret; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; @@ -3741,18 +3827,18 @@ mach64_read(uint32_t addr, void *p) return ret; } uint16_t -mach64_readw(uint32_t addr, void *p) +mach64_readw(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; return svga_readw_linear(addr, svga); } uint32_t -mach64_readl(uint32_t addr, void *p) +mach64_readl(uint32_t addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; @@ -3886,7 +3972,7 @@ mach64_readl(uint32_t addr, void *p) void mach64_overlay_draw(svga_t *svga, int displine) { - mach64_t *mach64 = (mach64_t *) svga->p; + mach64_t *mach64 = (mach64_t *) svga->priv; int x; int h_acc = 0; int h_max = (mach64->scaler_height_width >> 16) & 0x3ff; @@ -3942,9 +4028,9 @@ mach64_overlay_draw(svga_t *svga, int displine) } } else { for (x = 0; x < mach64->svga.overlay_latch.cur_xsize; x++) { - int h = h_acc >> 12; - int gr_cmp = 0; - int vid_cmp = 0; + int h = h_acc >> 12; + int gr_cmp = 0; + int vid_cmp = 0; int use_video = 0; switch (video_key_fn) { @@ -3960,6 +4046,9 @@ mach64_overlay_draw(svga_t *svga, int displine) case 5: vid_cmp = !((mach64->overlay_dat[h] ^ mach64->overlay_video_key_clr) & mach64->overlay_video_key_msk); break; + + default: + break; } switch (graphics_key_fn) { case 0: @@ -3974,6 +4063,9 @@ mach64_overlay_draw(svga_t *svga, int displine) case 5: gr_cmp = !(((p[x]) ^ mach64->overlay_graphics_key_clr) & mach64->overlay_graphics_key_msk & 0xffffff); break; + + default: + break; } vid_cmp = vid_cmp ? -1 : 0; gr_cmp = gr_cmp ? -1 : 0; @@ -4027,6 +4119,9 @@ mach64_overlay_draw(svga_t *svga, int displine) case 0xf: use_video = ~gr_cmp & ~vid_cmp; break; + + default: + break; } if (use_video) @@ -4058,8 +4153,8 @@ mach64_io_remove(mach64_t *mach64) uint16_t io_base = 0x02ec; switch (mach64->io_base) { - case 0: default: + case 0: io_base = 0x02ec; break; case 1: @@ -4111,9 +4206,9 @@ mach64_io_set(mach64_t *mach64) } uint8_t -mach64_pci_read(int func, int addr, void *p) +mach64_pci_read(UNUSED(int func), int addr, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + const mach64_t *mach64 = (mach64_t *) priv; switch (addr) { case 0x00: @@ -4187,14 +4282,17 @@ mach64_pci_read(int func, int addr, void *p) case 0x40: return mach64->use_block_decoded_io | mach64->io_base; + + default: + break; } return 0; } void -mach64_pci_write(int func, int addr, uint8_t val, void *p) +mach64_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; switch (addr) { case PCI_REG_COMMAND: @@ -4272,6 +4370,9 @@ mach64_pci_write(int func, int addr, uint8_t val, void *p) if (mach64->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_IO) mach64_io_set(mach64); break; + + default: + break; } } @@ -4339,7 +4440,7 @@ mach64gx_init(const device_t *info) mach64->type = MACH64_GX; mach64->pci = !!(info->flags & DEVICE_PCI); - mach64->pci_id = (int) 'X' | ((int) 'G' << 8); + mach64->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*/ @@ -4413,9 +4514,9 @@ mach64vt2_available(void) } void -mach64_close(void *p) +mach64_close(void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64->thread_run = 0; thread_set_event(mach64->wake_fifo_thread); @@ -4432,17 +4533,17 @@ mach64_close(void *p) } void -mach64_speed_changed(void *p) +mach64_speed_changed(void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; svga_recalctimings(&mach64->svga); } void -mach64_force_redraw(void *p) +mach64_force_redraw(void *priv) { - mach64_t *mach64 = (mach64_t *) p; + mach64_t *mach64 = (mach64_t *) priv; mach64->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ati_mach8.c b/src/video/vid_ati_mach8.c index 9c0cbb616..1aa55bd6b 100644 --- a/src/video/vid_ati_mach8.c +++ b/src/video/vid_ati_mach8.c @@ -40,21 +40,21 @@ #include <86box/vid_svga_render.h> #include <86box/vid_ati_eeprom.h> -#define BIOS_MACH8_ROM_PATH "roms/video/mach8/BIOS.BIN" -#define BIOS_MACH32_ISA_ROM_PATH "roms/video/mach32/MACH32ISA.VBI" -#define BIOS_MACH32_VLB_ROM_PATH "roms/video/mach32/MACH32VLB.VBI" -#define BIOS_MACH32_PCI_ROM_PATH "roms/video/mach32/MACH32PCI.BIN" +#define BIOS_MACH8_ROM_PATH "roms/video/mach8/BIOS.BIN" +#define BIOS_MACH32_ISA_ROM_PATH "roms/video/mach32/MACH32ISA.VBI" +#define BIOS_MACH32_VLB_ROM_PATH "roms/video/mach32/MACH32VLB.VBI" +#define BIOS_MACH32_PCI_ROM_PATH "roms/video/mach32/MACH32PCI.BIN" typedef struct mach_t { ati_eeprom_t eeprom; svga_t svga; - rom_t bios_rom; + rom_t bios_rom; mem_mapping_t mmio_linear_mapping; - int mca_bus; - int pci_bus; - int vlb_bus; + int mca_bus; + int pci_bus; + int vlb_bus; uint8_t regs[256]; uint8_t pci_regs[256]; uint8_t int_line; @@ -66,33 +66,40 @@ typedef struct mach_t { uint16_t config1; uint16_t config2; - uint8_t pos_regs[8]; - uint8_t cursor_col_0, cursor_col_1; - uint8_t ext_cur_col_0_r, ext_cur_col_1_r; - uint8_t ext_cur_col_0_g, ext_cur_col_1_g; - uint16_t cursor_offset_lo, cursor_offset_hi; - uint16_t cursor_x, cursor_y; + uint8_t pos_regs[8]; + uint8_t cursor_col_0; + uint8_t cursor_col_1; + uint8_t ext_cur_col_0_r; + uint8_t ext_cur_col_1_r; + uint8_t ext_cur_col_0_g; + uint8_t ext_cur_col_1_g; + uint16_t cursor_offset_lo; + uint16_t cursor_offset_hi; + uint16_t cursor_x; + uint16_t cursor_y; uint16_t misc; uint16_t memory_aperture; uint16_t local_cntl; uint32_t linear_base; - uint8_t ap_size; - uint8_t bank_w, bank_r; + uint8_t ap_size; + uint8_t bank_w; + uint8_t bank_r; struct { - uint8_t line_idx; - int16_t line_array[6]; - uint8_t patt_idx; - uint8_t patt_len; - uint8_t pix_trans[2]; - uint8_t eeprom_control; + uint8_t line_idx; + int16_t line_array[6]; + uint8_t patt_idx; + uint8_t patt_len; + uint8_t pix_trans[2]; + uint8_t eeprom_control; uint16_t dest_x_end; uint16_t dest_x_start; uint16_t dest_y_end; uint16_t src_x_end; uint16_t src_x_start; - uint16_t src_x, src_y; - int16_t bres_count; + uint16_t src_x; + uint16_t src_y; + int16_t bres_count; uint16_t clock_sel; uint16_t crt_offset_lo; uint16_t crt_offset_hi; @@ -103,54 +110,72 @@ typedef struct mach_t { uint16_t ge_offset_hi; uint16_t linedraw_opt; uint16_t max_waitstates; - uint8_t patt_data_idx; - uint8_t patt_data[0x18]; + uint8_t patt_data_idx; + uint8_t patt_data[0x18]; uint16_t scan_to_x; uint16_t scratch0; uint16_t scratch1; uint16_t test; uint16_t pattern; - uint8_t test2[2], test3[2]; - int src_y_dir; - int cmd_type; - int block_write_mono_pattern_enable; - int mono_pattern_enable; - int16_t cx_end_line, cy_end_line; - int16_t cx, cx_end, cy_end, dx, dx_end, dy_end; - int16_t dx_start, dy_start; - int16_t cy, sx_start, sx_end; - int16_t sx, x_count, xx_count, xxx_count; - int16_t sy, y_count; - int16_t err; - int16_t width, src_width; - int16_t height; - int poly_src, temp_cnt; - int stepx, stepy, src_stepx; - uint8_t color_pattern[16]; - uint8_t color_pattern_full[32]; + uint8_t test2[2]; + uint8_t test3[2]; + int src_y_dir; + int cmd_type; + int block_write_mono_pattern_enable; + int mono_pattern_enable; + int16_t cx_end_line; + int16_t cy_end_line; + int16_t cx; + int16_t cx_end; + int16_t cy_end; + int16_t dx; + int16_t dx_end; + int16_t dy_end; + int16_t dx_start; + int16_t dy_start; + int16_t cy; + int16_t sx_start; + int16_t sx_end; + int16_t sx; + int16_t x_count; + int16_t xx_count; + int16_t xxx_count; + int16_t sy; + int16_t y_count; + int16_t err; + int16_t width; + int16_t src_width; + int16_t height; + int poly_src; + int temp_cnt; + int stepx; + int stepy; + int src_stepx; + uint8_t color_pattern[16]; + uint8_t color_pattern_full[32]; uint16_t color_pattern_word[8]; - int mono_pattern[8][8]; + int mono_pattern[8][8]; uint32_t ge_offset; uint32_t crt_offset; uint32_t patt_len_reg; - int poly_fill; + int poly_fill; uint16_t dst_clr_cmp_mask; - int clip_overrun; - int color_pattern_idx; + int clip_overrun; + int color_pattern_idx; } accel; - atomic_int force_busy, force_busy2; + atomic_int force_busy; + atomic_int force_busy2; } mach_t; static video_timings_t timing_gfxultra_isa = { .type = VIDEO_ISA, .write_b = 3, .write_w = 3, .write_l = 6, .read_b = 5, .read_w = 5, .read_l = 10 }; -static video_timings_t timing_mach32_vlb = { .type = VIDEO_BUS, .write_b = 2, .write_w = 2, .write_l = 1, .read_b = 20, .read_w = 20, .read_l = 21 }; -static video_timings_t timing_mach32_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 1, .read_b = 20, .read_w = 20, .read_l = 21 }; +static video_timings_t timing_mach32_vlb = { .type = VIDEO_BUS, .write_b = 2, .write_w = 2, .write_l = 1, .read_b = 20, .read_w = 20, .read_l = 21 }; +static video_timings_t timing_mach32_pci = { .type = VIDEO_PCI, .write_b = 2, .write_w = 2, .write_l = 1, .read_b = 20, .read_w = 20, .read_l = 21 }; - -static void mach_accel_outb(uint16_t port, uint8_t val, void *p); -static void mach_accel_outw(uint16_t port, uint16_t val, void *p); -static uint8_t mach_accel_inb(uint16_t port, void *p); -static uint16_t mach_accel_inw(uint16_t port, void *p); +static void mach_accel_outb(uint16_t port, uint8_t val, void *priv); +static void mach_accel_outw(uint16_t port, uint16_t val, void *priv); +static uint8_t mach_accel_inb(uint16_t port, void *priv); +static uint16_t mach_accel_inw(uint16_t port, void *priv); static void mach32_updatemapping(mach_t *mach); @@ -348,7 +373,6 @@ mach_log(const char *fmt, ...) svga->changedvram[(((addr)) & (svga->vram_mask >> 1)) >> 11] = changeframecount; \ } - static int mach_pixel_write(mach_t *mach) { @@ -368,25 +392,29 @@ 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, mach_t *mach, ibm8514_t *dev, int len) +mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint32_t cpu_dat, mach_t *mach, ibm8514_t *dev, UNUSED(int len)) { - svga_t *svga = &mach->svga; - int compare_mode; - int poly_src = 0; - uint16_t rd_mask = dev->accel.rd_mask; - uint16_t wrt_mask = dev->accel.wrt_mask; - uint16_t dest_cmp_clr = dev->accel.color_cmp; - int frgd_sel, bkgd_sel, mono_src; - int compare = 0; - uint16_t src_dat = 0, dest_dat = 0; - uint16_t old_dest_dat; - uint16_t *vram_w = (uint16_t *) svga->vram; - uint16_t mix = 0; - int16_t clip_l = dev->accel.clip_left & 0x7ff; - int16_t clip_t = dev->accel.clip_top & 0x7ff; - int16_t clip_r = dev->accel.multifunc[4] & 0x7ff; - int16_t clip_b = dev->accel.multifunc[3] & 0x7ff; - uint32_t mono_dat0 = 0, mono_dat1 = 0; + svga_t *svga = &mach->svga; + int compare_mode; + int poly_src = 0; + uint16_t rd_mask = dev->accel.rd_mask; + uint16_t wrt_mask = dev->accel.wrt_mask; + uint16_t dest_cmp_clr = dev->accel.color_cmp; + int frgd_sel; + int bkgd_sel; + int mono_src; + int compare = 0; + uint16_t src_dat = 0; + uint16_t dest_dat = 0; + uint16_t old_dest_dat; + uint16_t *vram_w = (uint16_t *) svga->vram; + uint16_t mix = 0; + int16_t clip_l = dev->accel.clip_left & 0x7ff; + int16_t clip_t = dev->accel.clip_top & 0x7ff; + int16_t clip_r = dev->accel.multifunc[4] & 0x7ff; + int16_t clip_b = dev->accel.multifunc[3] & 0x7ff; + uint32_t mono_dat0 = 0; + uint32_t mono_dat1 = 0; if ((svga->bpp == 8) || (svga->bpp == 24)) { rd_mask &= 0xff; @@ -394,17 +422,17 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } compare_mode = (mach->accel.dest_cmp_fn >> 3) & 7; - frgd_sel = (mach->accel.dp_config >> 13) & 7; - bkgd_sel = (mach->accel.dp_config >> 7) & 3; - mono_src = (mach->accel.dp_config >> 5) & 3; + frgd_sel = (mach->accel.dp_config >> 13) & 7; + bkgd_sel = (mach->accel.dp_config >> 7) & 3; + mono_src = (mach->accel.dp_config >> 5) & 3; mach->accel.ge_offset = (mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16)); if ((mono_src == 2) || (bkgd_sel == 2) || (frgd_sel == 2) || mach_pixel_read(mach)) { - mach->force_busy = 1; + mach->force_busy = 1; mach->force_busy2 = 1; - dev->force_busy = 1; - dev->force_busy2 = 1; + dev->force_busy = 1; + dev->force_busy2 = 1; } if (cpu_input) { @@ -439,8 +467,8 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (dev->accel.desty_axstp >= 0x600) dev->accel.cy |= ~0x5ff; - mach->accel.width = mach->accel.bres_count; - dev->accel.sx = 0; + mach->accel.width = mach->accel.bres_count; + dev->accel.sx = 0; mach->accel.poly_fill = 0; mach->accel.color_pattern_idx = ((dev->accel.cx + (dev->accel.cy << 3)) & mach->accel.patt_len); @@ -452,11 +480,11 @@ 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 (mach_pixel_write(mach)) { - dev->data_available = 0; + dev->data_available = 0; dev->data_available2 = 0; return; } else if (mach_pixel_read(mach)) { - dev->data_available = 1; + dev->data_available = 1; dev->data_available2 = 1; return; } @@ -474,8 +502,8 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } if (mono_src == 1) { - count = mach->accel.width; - mix_dat = mach->accel.patt_data[0x10]; + count = mach->accel.width; + mix_dat = mach->accel.patt_data[0x10]; dev->accel.temp_cnt = 8; } @@ -518,9 +546,12 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } mix = (mix & rd_mask) == rd_mask; break; + + default: + break; } - if ((((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b))) { + if (((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b)) { if (mach->accel.linedraw_opt & 0x02) { if ((svga->bpp == 15) || (svga->bpp == 16)) { READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src, dev->local); @@ -563,6 +594,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } else src_dat = 0; break; + + default: + break; } if ((svga->bpp == 15) || (svga->bpp == 16)) { @@ -577,22 +611,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 compare = 1; break; case 2: - compare = ((dest_dat) >= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; break; case 3: - compare = ((dest_dat) < dest_cmp_clr) ? 0 : 1; + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; break; case 4: - compare = ((dest_dat) != dest_cmp_clr) ? 0 : 1; + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; break; case 5: - compare = ((dest_dat) == dest_cmp_clr) ? 0 : 1; + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; break; case 6: - compare = ((dest_dat) <= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; break; case 7: - compare = ((dest_dat) > dest_cmp_clr) ? 0 : 1; + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: break; } @@ -674,6 +711,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 dev->accel.cy++; dev->accel.dy++; break; + + default: + break; } dev->accel.sx++; @@ -717,9 +757,12 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } mix = (mix & rd_mask) == rd_mask; break; + + default: + break; } - if ((((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b))) { + if (((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b)) { if (mach->accel.linedraw_opt & 0x02) { if ((svga->bpp == 15) || (svga->bpp == 16)) { READ((mach->accel.ge_offset << 1) + ((dev->accel.cy) * (dev->pitch)) + (dev->accel.cx), poly_src, dev->local); @@ -762,6 +805,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } else src_dat = 0; break; + + default: + break; } if ((svga->bpp == 15) || (svga->bpp == 16)) { @@ -776,22 +822,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 compare = 1; break; case 2: - compare = ((dest_dat) >= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; break; case 3: - compare = ((dest_dat) < dest_cmp_clr) ? 0 : 1; + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; break; case 4: - compare = ((dest_dat) != dest_cmp_clr) ? 0 : 1; + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; break; case 5: - compare = ((dest_dat) == dest_cmp_clr) ? 0 : 1; + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; break; case 6: - compare = ((dest_dat) <= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; break; case 7: - compare = ((dest_dat) > dest_cmp_clr) ? 0 : 1; + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: break; } @@ -907,8 +956,8 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 mach_log("BitBLT: Dst Indeterminate X, dpconfig = %04x, destxend = %d, destxstart = %d.\n", mach->accel.dp_config, mach->accel.dest_x_end, mach->accel.dest_x_start); } - dev->accel.sx = 0; - mach->accel.poly_fill = 0; + dev->accel.sx = 0; + mach->accel.poly_fill = 0; mach->accel.color_pattern_idx = ((dev->accel.dx + (dev->accel.dy << 3)) & mach->accel.patt_len); if ((svga->bpp == 24) && (mono_src != 1)) { if (mach->accel.color_pattern_idx == mach->accel.patt_len) @@ -926,13 +975,13 @@ 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->accel.height = (mach->accel.dy_end - mach->accel.dy_start); - mach->accel.stepy = 1; + mach->accel.stepy = 1; } else if (mach->accel.dy_end < mach->accel.dy_start) { mach->accel.height = (mach->accel.dy_start - mach->accel.dy_end); - mach->accel.stepy = -1; + mach->accel.stepy = -1; } else { mach->accel.height = 0; - mach->accel.stepy = 1; + mach->accel.stepy = 1; } dev->accel.sy = 0; @@ -999,7 +1048,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 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; + uint32_t temp = (y & 4) ? mono_dat1 : mono_dat0; mach->accel.mono_pattern[y][7 - x] = (temp >> (x + ((y & 3) << 3))) & 1; } } @@ -1008,11 +1057,11 @@ 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 (mach_pixel_write(mach)) { - dev->data_available = 0; + dev->data_available = 0; dev->data_available2 = 0; return; } else if (mach_pixel_read(mach)) { - dev->data_available = 1; + dev->data_available = 1; dev->data_available2 = 1; return; } @@ -1021,8 +1070,8 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 if (mono_src == 1) { if (!mach->accel.mono_pattern_enable && !(mach->accel.patt_len_reg & 0x4000)) { - count = mach->accel.width; - mix_dat = mach->accel.patt_data[0x10] ^ ((mach->accel.patt_idx & 1) ? 0xff : 0); + count = mach->accel.width; + mix_dat = mach->accel.patt_data[0x10] ^ ((mach->accel.patt_idx & 1) ? 0xff : 0); dev->accel.temp_cnt = 8; } } @@ -1051,7 +1100,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 mach->accel.color_pattern_idx = mach->accel.patt_idx; } - if ((mach->accel.dy_end == mach->accel.dy_start)) { + if (mach->accel.dy_end == mach->accel.dy_start) { mach_log("No DEST.\n"); return; } @@ -1112,10 +1161,12 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 READ(dev->accel.src + ((dev->accel.cx)), mix, dev->local); mix = (mix & rd_mask) == rd_mask; break; + + default: + break; } - if (((dev->accel.dx) >= (clip_l) && (dev->accel.dx) <= (clip_r) && - (dev->accel.dy) >= (clip_t) && (dev->accel.dy) <= (clip_b))) { + if (((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b)) { if (mach->accel.dp_config & 0x02) { READ(dev->accel.src + (dev->accel.cx), poly_src, dev->local); poly_src = ((poly_src & rd_mask) == rd_mask); @@ -1154,6 +1205,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } else src_dat = 0; break; + + default: + break; } } @@ -1172,22 +1226,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 compare = 1; break; case 2: - compare = ((dest_dat) >= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; break; case 3: - compare = ((dest_dat) < dest_cmp_clr) ? 0 : 1; + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; break; case 4: - compare = ((dest_dat) != dest_cmp_clr) ? 0 : 1; + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; break; case 5: - compare = ((dest_dat) == dest_cmp_clr) ? 0 : 1; + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; break; case 6: - compare = ((dest_dat) <= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; break; case 7: - compare = ((dest_dat) > dest_cmp_clr) ? 0 : 1; + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: break; } @@ -1263,7 +1320,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) { mach->accel.poly_fill = 0; - dev->accel.sx = 0; + dev->accel.sx = 0; if (mach->accel.stepx == -1) dev->accel.dx += mach->accel.width; else @@ -1329,11 +1386,11 @@ 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 (mach_pixel_write(mach)) { - dev->data_available = 0; + dev->data_available = 0; dev->data_available2 = 0; return; } else if (mach_pixel_read(mach)) { - dev->data_available = 1; + dev->data_available = 1; dev->data_available2 = 1; return; } @@ -1347,11 +1404,11 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } if (mono_src == 1) { - mix_dat = mach->accel.patt_data[0x10]; + mix_dat = mach->accel.patt_data[0x10]; dev->accel.temp_cnt = 8; } - count = (dev->accel.dx > dev->accel.dy) ? (dev->accel.dx >> 1) : (dev->accel.dy >> 1); + count = (dev->accel.dx > dev->accel.dy) ? (dev->accel.dx >> 1) : (dev->accel.dy >> 1); mach->accel.width = count; if (dev->accel.dx > dev->accel.dy) { @@ -1367,7 +1424,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 mix_dat <<= 1; mix_dat |= 1; - if ((((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b))) { + if (((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b)) { mach->accel.clip_overrun = 0; switch (mix ? frgd_sel : bkgd_sel) { case 0: @@ -1392,6 +1449,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } else src_dat = 0; break; + + default: + break; } if ((svga->bpp == 15) || (svga->bpp == 16)) { @@ -1405,22 +1465,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 compare = 1; break; case 2: - compare = ((dest_dat) >= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; break; case 3: - compare = ((dest_dat) < dest_cmp_clr) ? 0 : 1; + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; break; case 4: - compare = ((dest_dat) != dest_cmp_clr) ? 0 : 1; + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; break; case 5: - compare = ((dest_dat) == dest_cmp_clr) ? 0 : 1; + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; break; case 6: - compare = ((dest_dat) <= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; break; case 7: - compare = ((dest_dat) > dest_cmp_clr) ? 0 : 1; + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: break; } @@ -1478,9 +1541,12 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } } break; + + default: + break; } - if ((((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b))) { + if (((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b)) { mach->accel.clip_overrun = 0; switch (mix ? frgd_sel : bkgd_sel) { case 0: @@ -1505,6 +1571,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } else src_dat = 0; break; + + default: + break; } if ((svga->bpp == 15) || (svga->bpp == 16)) { @@ -1518,22 +1587,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 compare = 1; break; case 2: - compare = ((dest_dat) >= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; break; case 3: - compare = ((dest_dat) < dest_cmp_clr) ? 0 : 1; + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; break; case 4: - compare = ((dest_dat) != dest_cmp_clr) ? 0 : 1; + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; break; case 5: - compare = ((dest_dat) == dest_cmp_clr) ? 0 : 1; + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; break; case 6: - compare = ((dest_dat) <= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; break; case 7: - compare = ((dest_dat) > dest_cmp_clr) ? 0 : 1; + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: break; } @@ -1596,7 +1668,7 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 mix_dat <<= 1; mix_dat |= 1; - if ((((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b))) { + if (((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b)) { mach->accel.clip_overrun = 0; switch (mix ? frgd_sel : bkgd_sel) { case 0: @@ -1621,6 +1693,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } else src_dat = 0; break; + + default: + break; } if ((svga->bpp == 15) || (svga->bpp == 16)) { @@ -1633,22 +1708,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 compare = 1; break; case 2: - compare = ((dest_dat) >= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; break; case 3: - compare = ((dest_dat) < dest_cmp_clr) ? 0 : 1; + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; break; case 4: - compare = ((dest_dat) != dest_cmp_clr) ? 0 : 1; + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; break; case 5: - compare = ((dest_dat) == dest_cmp_clr) ? 0 : 1; + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; break; case 6: - compare = ((dest_dat) <= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; break; case 7: - compare = ((dest_dat) > dest_cmp_clr) ? 0 : 1; + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: break; } @@ -1707,9 +1785,12 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } } break; + + default: + break; } - if ((((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b))) { + if (((dev->accel.cx) >= clip_l) && ((dev->accel.cx) <= clip_r) && ((dev->accel.cy) >= clip_t) && ((dev->accel.cy) <= clip_b)) { mach->accel.clip_overrun = 0; switch (mix ? frgd_sel : bkgd_sel) { case 0: @@ -1734,6 +1815,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } else src_dat = 0; break; + + default: + break; } if ((svga->bpp == 15) || (svga->bpp == 16)) { @@ -1747,22 +1831,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 compare = 1; break; case 2: - compare = ((dest_dat) >= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; break; case 3: - compare = ((dest_dat) < dest_cmp_clr) ? 0 : 1; + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; break; case 4: - compare = ((dest_dat) != dest_cmp_clr) ? 0 : 1; + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; break; case 5: - compare = ((dest_dat) == dest_cmp_clr) ? 0 : 1; + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; break; case 6: - compare = ((dest_dat) <= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; break; case 7: - compare = ((dest_dat) > dest_cmp_clr) ? 0 : 1; + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: break; } @@ -1815,8 +1902,8 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } 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 = mach->accel.line_array[(cmd_type == 4) ? 4 : 0]; + dev->accel.cur_y = mach->accel.line_array[(cmd_type == 4) ? 5 : 1]; break; case 5: /*Horizontal Raster Draw from scan_to_x register (0xcaee)*/ @@ -1933,11 +2020,11 @@ 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 (mach_pixel_write(mach)) { - dev->data_available = 0; + dev->data_available = 0; dev->data_available2 = 0; return; } else if (mach_pixel_read(mach)) { - dev->data_available = 1; + dev->data_available = 1; dev->data_available2 = 1; return; } @@ -1945,8 +2032,8 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } if (mono_src == 1) { - count = mach->accel.width; - mix_dat = mach->accel.patt_data[0x10]; + count = mach->accel.width; + mix_dat = mach->accel.patt_data[0x10]; dev->accel.temp_cnt = 8; } @@ -2004,10 +2091,12 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 READ(dev->accel.src + (dev->accel.cx), mix, dev->local); mix = (mix & rd_mask) == rd_mask; break; + + default: + break; } - if ((dev->accel.dx) >= (clip_l) && (dev->accel.dx) <= (clip_r) && - (dev->accel.dy) >= (clip_t) && (dev->accel.dy) <= (clip_b)) { + if (((dev->accel.dx) >= clip_l) && ((dev->accel.dx) <= clip_r) && ((dev->accel.dy) >= clip_t) && ((dev->accel.dy) <= clip_b)) { switch (mix ? frgd_sel : bkgd_sel) { case 0: src_dat = dev->accel.bkgd_color; @@ -2040,6 +2129,9 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } else src_dat = 0; break; + + default: + break; } READ(dev->accel.dest + (dev->accel.dx), dest_dat, dev->local); @@ -2049,22 +2141,25 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 compare = 1; break; case 2: - compare = ((dest_dat) >= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat >= dest_cmp_clr) ? 0 : 1; break; case 3: - compare = ((dest_dat) < dest_cmp_clr) ? 0 : 1; + compare = (dest_dat < dest_cmp_clr) ? 0 : 1; break; case 4: - compare = ((dest_dat) != dest_cmp_clr) ? 0 : 1; + compare = (dest_dat != dest_cmp_clr) ? 0 : 1; break; case 5: - compare = ((dest_dat) == dest_cmp_clr) ? 0 : 1; + compare = (dest_dat == dest_cmp_clr) ? 0 : 1; break; case 6: - compare = ((dest_dat) <= dest_cmp_clr) ? 0 : 1; + compare = (dest_dat <= dest_cmp_clr) ? 0 : 1; break; case 7: - compare = ((dest_dat) > dest_cmp_clr) ? 0 : 1; + compare = (dest_dat > dest_cmp_clr) ? 0 : 1; + break; + + default: break; } @@ -2134,13 +2229,18 @@ mach_accel_start(int cmd_type, int cpu_input, int count, uint32_t mix_dat, uint3 } } break; + + default: + break; } } static void -mach_accel_out_pixtrans(mach_t *mach, ibm8514_t *dev, uint16_t port, uint16_t val, uint16_t len) +mach_accel_out_pixtrans(mach_t *mach, ibm8514_t *dev, UNUSED(uint16_t port), uint16_t val, uint16_t len) { - int frgd_sel, bkgd_sel, mono_src; + int frgd_sel; + int bkgd_sel; + int mono_src; frgd_sel = (mach->accel.dp_config >> 13) & 7; bkgd_sel = (mach->accel.dp_config >> 7) & 3; @@ -2152,7 +2252,7 @@ mach_accel_out_pixtrans(mach_t *mach, ibm8514_t *dev, uint16_t port, uint16_t va switch (mach->accel.dp_config & 0x200) { case 0x000: /*8-bit size*/ - if ((mono_src == 2)) { + if (mono_src == 2) { if ((frgd_sel != 2) && (bkgd_sel != 2)) { if ((mach->accel.dp_config & 0x1000) && dev->local) val = (val >> 8) | (val << 8); @@ -2163,7 +2263,7 @@ mach_accel_out_pixtrans(mach_t *mach, ibm8514_t *dev, uint16_t port, uint16_t va mach_accel_start(mach->accel.cmd_type, 1, 1, -1, val | (val << 16), mach, dev, len); break; case 0x200: /*16-bit size*/ - if ((mono_src == 2)) { + if (mono_src == 2) { if ((frgd_sel != 2) && (bkgd_sel != 2)) { if (mach->accel.dp_config & 0x1000) val = (val >> 8) | (val << 8); @@ -2175,17 +2275,20 @@ mach_accel_out_pixtrans(mach_t *mach, ibm8514_t *dev, uint16_t port, uint16_t va mach_accel_start(mach->accel.cmd_type, 1, 2, -1, val | (val << 16), mach, dev, len); } break; + + default: + break; } } static void -mach_out(uint16_t addr, uint8_t val, void *p) +mach_out(uint16_t addr, uint8_t val, void *priv) { - mach_t *mach = (mach_t *) p; - svga_t *svga = &mach->svga; - ibm8514_t *dev = &svga->dev8514; - uint8_t old; - uint8_t rs2; + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + const ibm8514_t *dev = &svga->dev8514; + uint8_t old; + uint8_t rs2; if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -2195,7 +2298,7 @@ mach_out(uint16_t addr, uint8_t val, void *p) mach->index = val; break; case 0x1cf: - old = mach->regs[mach->index]; + old = mach->regs[mach->index]; mach->regs[mach->index] = val; mach_log("ATI VGA write reg=0x%02X, val=0x%02X\n", mach->index, val); switch (mach->index) { @@ -2225,21 +2328,21 @@ mach_out(uint16_t addr, uint8_t val, void *p) mach->bank_r = (((mach->regs[0xb2] & 1) << 3) | ((mach->regs[0xb2] & 0xe0) >> 5)); mach->bank_w = ((mach->regs[0xb2] & 0x1e) >> 1); if (dev->local) { - mach->bank_r |= (((mach->regs[0xae] & 0x0c) << 2)); - mach->bank_w |= (((mach->regs[0xae] & 3) << 4)); + mach->bank_r |= ((mach->regs[0xae] & 0x0c) << 2); + mach->bank_w |= ((mach->regs[0xae] & 3) << 4); } if (ibm8514_on) mach_log("Separate B2Bank = %02x, AEbank = %02x.\n", mach->regs[0xb2], mach->regs[0xae]); } else { /* Single bank mode */ mach->bank_w = ((mach->regs[0xb2] & 0x1e) >> 1); if (dev->local) { - mach->bank_w |= (((mach->regs[0xae] & 3) << 4)); + mach->bank_w |= ((mach->regs[0xae] & 3) << 4); } mach->bank_r = mach->bank_w; if (ibm8514_on) mach_log("Single B2Bank = %02x, AEbank = %02x.\n", mach->regs[0xb2], mach->regs[0xae]); } - svga->read_bank = mach->bank_r << 16; + svga->read_bank = mach->bank_r << 16; svga->write_bank = mach->bank_w << 16; if (mach->index == 0xbe) { @@ -2272,6 +2375,9 @@ mach_out(uint16_t addr, uint8_t val, void *p) if ((old ^ val) & 2) svga_recalctimings(svga); break; + + default: + break; } break; @@ -2336,18 +2442,21 @@ mach_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } static uint8_t -mach_in(uint16_t addr, void *p) +mach_in(uint16_t addr, void *priv) { - mach_t *mach = (mach_t *) p; - svga_t *svga = &mach->svga; - ibm8514_t *dev = &svga->dev8514; - uint8_t temp; - uint8_t rs2; + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + const ibm8514_t *dev = &svga->dev8514; + uint8_t temp; + uint8_t rs2; if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -2436,59 +2545,60 @@ mach_in(uint16_t addr, void *p) static void mach_recalctimings(svga_t *svga) { - mach_t *mach = (mach_t *) svga->p; - ibm8514_t *dev = &svga->dev8514; + const mach_t *mach = (mach_t *) svga->priv; + ibm8514_t *dev = &svga->dev8514; if (vga_on && !ibm8514_on) { switch (((mach->regs[0xbe] & 0x10) >> 1) | ((mach->regs[0xb9] & 2) << 1) | ((svga->miscout & 0x0c) >> 2)) { case 0x00: - svga->clock = (cpuclock * (double) (1ull << 32)) / 42954000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 42954000.0; break; case 0x01: - svga->clock = (cpuclock * (double) (1ull << 32)) / 48771000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 48771000.0; break; case 0x02: mach_log("clock 2\n"); break; case 0x03: - svga->clock = (cpuclock * (double) (1ull << 32)) / 36000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 36000000.0; break; case 0x04: - svga->clock = (cpuclock * (double) (1ull << 32)) / 50350000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; break; case 0x05: - svga->clock = (cpuclock * (double) (1ull << 32)) / 56640000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 56640000.0; break; case 0x06: mach_log("clock 2\n"); break; case 0x07: - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; break; case 0x08: - svga->clock = (cpuclock * (double) (1ull << 32)) / 30240000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 30240000.0; break; case 0x09: - svga->clock = (cpuclock * (double) (1ull << 32)) / 32000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 32000000.0; break; case 0x0A: - svga->clock = (cpuclock * (double) (1ull << 32)) / 37500000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 37500000.0; break; case 0x0B: - svga->clock = (cpuclock * (double) (1ull << 32)) / 39000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 39000000.0; break; case 0x0C: - svga->clock = (cpuclock * (double) (1ull << 32)) / 50350000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 50350000.0; break; case 0x0D: - svga->clock = (cpuclock * (double) (1ull << 32)) / 56644000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 56644000.0; break; case 0x0E: - svga->clock = (cpuclock * (double) (1ull << 32)) / 75000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 75000000.0; break; case 0x0F: - svga->clock = (cpuclock * (double) (1ull << 32)) / 65000000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 65000000.0; break; + default: break; } @@ -2520,6 +2630,9 @@ mach_recalctimings(svga_t *svga) case 0xc0: svga->clock *= 4; break; + + default: + break; } } @@ -2567,40 +2680,45 @@ mach_recalctimings(svga_t *svga) } break; + default: + break; } break; + + default: + break; } } } } else if (dev->local) { if (ibm8514_on) { - svga->hdisp_time = svga->hdisp = (dev->hdisp + 1) << 3; - dev->pitch = (dev->accel.advfunc_cntl & 4) ? 1024 : 640; - svga->htotal = (dev->htotal + 1); - svga->vtotal = (dev->vtotal + 1); - svga->vsyncstart = (dev->vsyncstart + 1); - svga->rowcount = !!(dev->disp_cntl & 0x08); - svga->dispend = ((dev->vdisp >> 1) + 1); - svga->interlace = dev->interlace; + svga->hdisp_time = svga->hdisp = (dev->hdisp + 1) << 3; + dev->pitch = (dev->accel.advfunc_cntl & 4) ? 1024 : 640; + svga->htotal = (dev->htotal + 1); + svga->vtotal = (dev->vtotal + 1); + svga->vsyncstart = (dev->vsyncstart + 1); + svga->rowcount = !!(dev->disp_cntl & 0x08); + svga->dispend = ((dev->vdisp >> 1) + 1); + svga->interlace = dev->interlace; svga->split = 0xffffff; svga->vblankstart = svga->dispend; if (svga->dispend == 766) { - svga->dispend = 768; + svga->dispend = 768; svga->vblankstart = svga->dispend; } if (svga->dispend == 598) { - svga->dispend = 600; + svga->dispend = 600; svga->vblankstart = svga->dispend; } if (dev->accel.advfunc_cntl & 4) { if (dev->ibm_mode) { if (svga->hdisp == 8) { - svga->hdisp = 1024; - svga->dispend = 768; - svga->vtotal = 1536; + svga->hdisp = 1024; + svga->dispend = 768; + svga->vtotal = 1536; svga->vsyncstart = 1536; } } @@ -2614,14 +2732,14 @@ mach_recalctimings(svga_t *svga) svga->vtotal >>= 1; } - dev->pitch = dev->ext_pitch; + dev->pitch = dev->ext_pitch; svga->rowoffset = dev->ext_crt_pitch; - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; } else { if (dev->ibm_mode) { if ((svga->hdisp == 1024) && !dev->internal_pitch) { - svga->hdisp = 640; + svga->hdisp = 640; svga->dispend = 480; } } @@ -2635,14 +2753,14 @@ mach_recalctimings(svga_t *svga) svga->vtotal >>= 1; } - dev->pitch = dev->ext_pitch; + dev->pitch = dev->ext_pitch; svga->rowoffset = dev->ext_crt_pitch; - svga->clock = (cpuclock * (double) (1ull << 32)) / 25175000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 25175000.0; } switch (svga->bpp) { - case 8: default: + case 8: svga->render = svga_render_8bpp_highres; break; case 15: @@ -2664,7 +2782,10 @@ mach_recalctimings(svga_t *svga) static void mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, uint32_t val, int len) { - int frgd_sel, bkgd_sel, mono_src; + int frgd_sel; + int bkgd_sel; + int mono_src; + switch (port) { case 0x82e8: case 0xc2e8: @@ -2701,7 +2822,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u if (len == 1) dev->accel.desty_axstp = (dev->accel.desty_axstp & 0x3f00) | val; else { - mach->accel.src_y = val; + mach->accel.src_y = val; dev->accel.desty_axstp = val & 0x3fff; if (val & 0x2000) dev->accel.desty_axstp |= ~0x1fff; @@ -2721,7 +2842,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u if (len == 1) dev->accel.destx_distp = (dev->accel.destx_distp & 0x3f00) | val; else { - mach->accel.src_x = val; + mach->accel.src_x = val; dev->accel.destx_distp = val & 0x3fff; if (val & 0x2000) dev->accel.destx_distp |= ~0x1fff; @@ -2739,6 +2860,9 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u case 0x92e8: if (len != 1) dev->test = val; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0xd2e8: mach_log("92E8 = %04x\n", val); if (len == 1) @@ -2763,7 +2887,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u if (len == 1) dev->accel.maj_axis_pcnt = (dev->accel.maj_axis_pcnt & 0x0700) | val; else { - mach->accel.test = val & 0x1fff; + mach->accel.test = val & 0x1fff; dev->accel.maj_axis_pcnt = val & 0x07ff; } break; @@ -2903,9 +3027,9 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u 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; + 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*/ @@ -2929,6 +3053,9 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u } else mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); break; + + default: + break; } } } @@ -2985,9 +3112,9 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u 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; + 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*/ @@ -3011,6 +3138,9 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u } else mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); break; + + default: + break; } } } @@ -3124,7 +3254,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u } break; -/*ATI Mach8/32 specific registers*/ + /*ATI Mach8/32 specific registers*/ case 0x82ee: mach->accel.patt_data_idx = val & 0x1f; mach_log("Pattern Data Index = %d.\n", val & 0x1f); @@ -3134,7 +3264,7 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u if (len == 1) { mach->accel.patt_data[mach->accel.patt_data_idx] = val; } else { - mach->accel.patt_data[mach->accel.patt_data_idx] = val & 0xff; + mach->accel.patt_data[mach->accel.patt_data_idx] = val & 0xff; mach->accel.patt_data[mach->accel.patt_data_idx + 1] = (val >> 8) & 0xff; if (mach->accel.mono_pattern_enable) mach->accel.patt_data_idx = (mach->accel.patt_data_idx + 2) & 0x17; @@ -3149,7 +3279,6 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u mach->accel.patt_data_idx += 2; else mach->accel.patt_data_idx = (mach->accel.patt_data_idx + 2) & mach->accel.patt_len; - } mach_log("ExtCONFIG = %04x, Pattern Mono = %04x, selidx = %d, dataidx = %d, bit 0 = %02x len = %d.\n", mach->accel.ext_ge_config, val, mach->accel.patt_idx, mach->accel.patt_data_idx, val & 1, mach->accel.patt_len); } @@ -3255,9 +3384,9 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u case 0xaeef: if (len == 1) { mach->accel.dest_y_end = (mach->accel.dest_y_end & 0x0ff) | ((val & 0x07) << 8); - dev->data_available = 0; - dev->data_available2 = 0; - mach->accel.cmd_type = 2; /*Non-conforming BitBLT from dest_y_end register (0xaeee)*/ + dev->data_available = 0; + dev->data_available2 = 0; + mach->accel.cmd_type = 2; /*Non-conforming BitBLT from dest_y_end register (0xaeee)*/ mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); } break; @@ -3322,9 +3451,9 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u case 0xcaef: if (len == 1) { mach->accel.scan_to_x = (mach->accel.scan_to_x & 0x0ff) | ((val & 0x07) << 8); - dev->data_available = 0; - dev->data_available2 = 0; - mach->accel.cmd_type = 5; /*Horizontal Raster Draw from scan_to_x register (0xcaee)*/ + dev->data_available = 0; + dev->data_available2 = 0; + mach->accel.cmd_type = 5; /*Horizontal Raster Draw from scan_to_x register (0xcaee)*/ mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); } break; @@ -3443,10 +3572,10 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u mach_log("FEEE val = %d, lineidx = %d, DPCONFIG = %04x, CPUCX = %04x.\n", val, mach->accel.line_idx, mach->accel.dp_config, CX); if (len != 1) { mach->accel.line_array[mach->accel.line_idx] = val; - dev->accel.cur_x = mach->accel.line_array[(mach->accel.line_idx == 4) ? 4 : 0]; - dev->accel.cur_y = mach->accel.line_array[(mach->accel.line_idx == 5) ? 5 : 1]; - mach->accel.cx_end_line = mach->accel.line_array[2]; - mach->accel.cy_end_line = mach->accel.line_array[3]; + dev->accel.cur_x = mach->accel.line_array[(mach->accel.line_idx == 4) ? 4 : 0]; + dev->accel.cur_y = mach->accel.line_array[(mach->accel.line_idx == 5) ? 5 : 1]; + mach->accel.cx_end_line = mach->accel.line_array[2]; + mach->accel.cy_end_line = mach->accel.line_array[3]; if ((mach->accel.line_idx == 3) || (mach->accel.line_idx == 5)) { mach->accel.cmd_type = (mach->accel.line_idx == 5) ? 4 : 3; mach_accel_start(mach->accel.cmd_type, 0, -1, -1, 0, mach, dev, len); @@ -3456,14 +3585,17 @@ mach_accel_out_fifo(mach_t *mach, svga_t *svga, ibm8514_t *dev, uint16_t port, u mach->accel.line_idx++; } break; + + default: + break; } } static void mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) { - svga_t *svga = &mach->svga; - ibm8514_t *dev = &svga->dev8514; + svga_t *svga = &mach->svga; + ibm8514_t *dev = &svga->dev8514; mach_log("Port accel out = %04x, val = %04x, len = %d.\n", port, val, len); @@ -3587,9 +3719,9 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) if (!dev->local || !dev->ext_crt_pitch) dev->ext_crt_pitch = 128; dev->accel.advfunc_cntl = val & 7; - ibm8514_on = (dev->accel.advfunc_cntl & 1); - vga_on = !ibm8514_on; - dev->ibm_mode = 1; + ibm8514_on = (dev->accel.advfunc_cntl & 1); + vga_on = !ibm8514_on; + dev->ibm_mode = 1; if (ibm8514_on) svga->adv_flags |= FLAG_ATI; else @@ -3612,13 +3744,13 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) else { mach_log("AEE val=%02x.\n", val); mach->cursor_offset_lo = val; - svga->hwcursor.addr = mach->cursor_offset_lo << 2; + svga->hwcursor.addr = mach->cursor_offset_lo << 2; } break; case 0xaef: if (len == 1) { mach->cursor_offset_lo = (mach->cursor_offset_lo & 0x00ff) | (val << 8); - svga->hwcursor.addr = mach->cursor_offset_lo << 2; + svga->hwcursor.addr = mach->cursor_offset_lo << 2; } break; @@ -3626,14 +3758,14 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) mach->cursor_offset_hi = val & 0x0f; if (len != 1) { svga->hwcursor.addr = ((mach->cursor_offset_lo | (mach->cursor_offset_hi << 16))) << 2; - svga->hwcursor.ena = !!(val & 0x8000); + svga->hwcursor.ena = !!(val & 0x8000); } mach_log("EEE val=%08x.\n", svga->hwcursor.addr); break; case 0xeef: if (len == 1) { svga->hwcursor.addr = ((mach->cursor_offset_lo | (mach->cursor_offset_hi << 16))) << 2; - svga->hwcursor.ena = !!(val & 0x80); + svga->hwcursor.ena = !!(val & 0x80); } break; @@ -3714,7 +3846,7 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) case 0x26ee: mach_log("CRT Pitch = %d, original val = %d.\n", val << 3, val); - dev->ext_crt_pitch = val; + dev->ext_crt_pitch = val; dev->internal_pitch = val; if (svga->bpp > 8) { if (svga->bpp == 24) @@ -3807,9 +3939,9 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) mach->accel.clock_sel = (mach->accel.clock_sel & 0xff00) | val; else { mach->accel.clock_sel = val; - ibm8514_on = (mach->accel.clock_sel & 1); - vga_on = !ibm8514_on; - dev->ibm_mode = 0; + ibm8514_on = (mach->accel.clock_sel & 1); + vga_on = !ibm8514_on; + dev->ibm_mode = 0; if (ibm8514_on) svga->adv_flags |= FLAG_ATI; else @@ -3821,9 +3953,9 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) case 0x4aef: if (len == 1) { mach->accel.clock_sel = (mach->accel.clock_sel & 0x00ff) | (val << 8); - ibm8514_on = (mach->accel.clock_sel & 1); - vga_on = !ibm8514_on; - dev->ibm_mode = 0; + ibm8514_on = (mach->accel.clock_sel & 1); + vga_on = !ibm8514_on; + dev->ibm_mode = 0; if (ibm8514_on) svga->adv_flags |= FLAG_ATI; else @@ -3912,13 +4044,13 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) mach->accel.ge_offset_lo = (mach->accel.ge_offset_lo & 0xff00) | val; else { mach->accel.ge_offset_lo = val; - dev->accel.ge_offset = mach->accel.ge_offset_lo; + dev->accel.ge_offset = mach->accel.ge_offset_lo; } break; case 0x6eef: if (len == 1) { mach->accel.ge_offset_lo = (mach->accel.ge_offset_lo & 0x00ff) | (val << 8); - dev->accel.ge_offset = mach->accel.ge_offset_lo; + dev->accel.ge_offset = mach->accel.ge_offset_lo; } break; @@ -3928,13 +4060,13 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) mach->accel.ge_offset_hi = (mach->accel.ge_offset_hi & 0xff00) | val; else { mach->accel.ge_offset_hi = val; - dev->accel.ge_offset = mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16); + dev->accel.ge_offset = mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16); } break; case 0x72ef: if (len == 1) { mach->accel.ge_offset_hi = (mach->accel.ge_offset_hi & 0x00ff) | (val << 8); - dev->accel.ge_offset = mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16); + dev->accel.ge_offset = mach->accel.ge_offset_lo | (mach->accel.ge_offset_hi << 16); } break; @@ -3950,7 +4082,7 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) mach->accel.ext_ge_config = (mach->accel.ext_ge_config & 0xff00) | val; else { mach->accel.ext_ge_config = val; - dev->ext_crt_pitch = dev->internal_pitch; + dev->ext_crt_pitch = dev->internal_pitch; switch (mach->accel.ext_ge_config & 0x30) { case 0: case 0x10: @@ -3968,6 +4100,9 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) svga->bpp = 24; dev->ext_crt_pitch *= 3; break; + + default: + break; } if (mach->accel.ext_ge_config & 0x800) { svga_recalctimings(svga); @@ -3980,7 +4115,7 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) mach_log("7AEF write val = %02x.\n", val); if (len == 1) { mach->accel.ext_ge_config = (mach->accel.ext_ge_config & 0x00ff) | (val << 8); - dev->ext_crt_pitch = dev->internal_pitch; + dev->ext_crt_pitch = dev->internal_pitch; switch (mach->accel.ext_ge_config & 0x30) { case 0: case 0x10: @@ -3998,6 +4133,9 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) svga->bpp = 24; dev->ext_crt_pitch *= 3; break; + + default: + break; } if (mach->accel.ext_ge_config & 0x800) { svga_recalctimings(svga); @@ -4010,6 +4148,9 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) case 0x7eee: mach->accel.eeprom_control = val; break; + + default: + break; } } } @@ -4017,14 +4158,16 @@ mach_accel_out(uint16_t port, uint32_t val, mach_t *mach, int len) static uint32_t mach_accel_in(uint16_t port, mach_t *mach, int len) { - svga_t *svga = &mach->svga; - ibm8514_t *dev = &svga->dev8514; - uint16_t *vram_w = (uint16_t *) svga->vram; - uint16_t temp = 0; - int cmd; - int vpos = dev->displine + svga->y_add; - int vblankend = svga->vblankstart + svga->crtc[0x16]; - int frgd_sel, bkgd_sel, mono_src; + svga_t *svga = &mach->svga; + ibm8514_t *dev = &svga->dev8514; + const uint16_t *vram_w = (uint16_t *) svga->vram; + uint16_t temp = 0; + int cmd; + int vpos = dev->displine + svga->y_add; + int vblankend = svga->vblankstart + svga->crtc[0x16]; + int frgd_sel; + int bkgd_sel; + int mono_src; switch (port) { case 0x2e8: @@ -4035,7 +4178,7 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) if (vpos >= svga->vblankstart || vpos <= vblankend) temp |= 2; } else { - if (vpos >= svga->vblankstart && vpos <= vblankend) + if (vpos >= svga->vblankstart && vpos <= vblankend) temp |= 2; } } else { @@ -4045,7 +4188,7 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) if (vpos >= svga->vblankstart || vpos <= vblankend) temp |= 2; } else { - if (vpos >= svga->vblankstart && vpos <= vblankend) + if (vpos >= svga->vblankstart && vpos <= vblankend) temp |= 2; } } @@ -4082,7 +4225,7 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) if (vpos >= svga->vblankstart || vpos <= vblankend) dev->subsys_stat |= 1; } else { - if (vpos >= svga->vblankstart && vpos <= vblankend) + if (vpos >= svga->vblankstart && vpos <= vblankend) dev->subsys_stat |= 1; } } else { @@ -4092,7 +4235,7 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) if (vpos >= svga->vblankstart || vpos <= vblankend) dev->subsys_stat |= 1; } else { - if (vpos >= svga->vblankstart && vpos <= vblankend) + if (vpos >= svga->vblankstart && vpos <= vblankend) dev->subsys_stat |= 1; } } @@ -4237,7 +4380,7 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) temp |= (dev->vram[(dev->accel.newdest_in + dev->accel.cur_x) & dev->vram_mask] << 8); } if (dev->subsys_stat & 1) { - dev->force_busy = 1; + dev->force_busy = 1; dev->data_available = 1; } } @@ -4254,7 +4397,7 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) cmd = -1; READ_PIXTRANS_BYTE_IO(dev->accel.dx, 0, dev->local) - temp = mach->accel.pix_trans[0]; + temp = mach->accel.pix_trans[0]; frgd_sel = (mach->accel.dp_config >> 13) & 7; bkgd_sel = (mach->accel.dp_config >> 7) & 3; mono_src = (mach->accel.dp_config >> 5) & 3; @@ -4281,6 +4424,9 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) } else mach_accel_start(mach->accel.cmd_type, 1, 2, -1, mach->accel.pix_trans[0] | (mach->accel.pix_trans[1] << 8), mach, dev, len); break; + + default: + break; } } } @@ -4319,11 +4465,14 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) case 0x0a: temp = dev->accel.multifunc[0x0a]; break; + + default: + break; } } break; -/*ATI Mach8/32 specific registers*/ + /*ATI Mach8/32 specific registers*/ case 0x12ee: if (len == 1) temp = mach->config1 & 0xff; @@ -4662,6 +4811,9 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) temp = 0x22; } break; + + default: + break; } if (port != 0x9ae8 && port != 0x9ae9 && port != 0x62ee && port != 0x9aee) { mach_log("Port accel in = %04x, temp = %04x, len = %d, mode = %d.\n", port, temp, len, dev->ibm_mode); @@ -4670,40 +4822,40 @@ mach_accel_in(uint16_t port, mach_t *mach, int len) } static void -mach_accel_outb(uint16_t port, uint8_t val, void *p) +mach_accel_outb(uint16_t port, uint8_t val, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; mach_accel_out(port, val, mach, 1); } static void -mach_accel_outw(uint16_t port, uint16_t val, void *p) +mach_accel_outw(uint16_t port, uint16_t val, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; mach_accel_out(port, val, mach, 2); } static uint8_t -mach_accel_inb(uint16_t port, void *p) +mach_accel_inb(uint16_t port, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; return mach_accel_in(port, mach, 1); } static uint16_t -mach_accel_inw(uint16_t port, void *p) +mach_accel_inw(uint16_t port, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; return mach_accel_in(port, mach, 2); } static void -mach32_ap_writeb(uint32_t addr, uint8_t val, void *p) +mach32_ap_writeb(uint32_t addr, uint8_t val, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; uint8_t port_dword = addr & 0xfc; - if (((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { if (addr & 0x100) { mach_log("Port WORDB Write=%04x.\n", 0x02ee + (port_dword << 8)); mach_accel_outb(0x02ee + (addr & 1) + (port_dword << 8), val, mach); @@ -4718,12 +4870,12 @@ mach32_ap_writeb(uint32_t addr, uint8_t val, void *p) } static void -mach32_ap_writew(uint32_t addr, uint16_t val, void *p) +mach32_ap_writew(uint32_t addr, uint16_t val, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; uint8_t port_dword = addr & 0xfc; - if (((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { if (addr & 0x100) { mach_log("Port WORDW Write=%04x.\n", 0x02ee + (port_dword << 8)); mach_accel_outw(0x02ee + (port_dword << 8), val, mach); @@ -4738,12 +4890,12 @@ mach32_ap_writew(uint32_t addr, uint16_t val, void *p) } static void -mach32_ap_writel(uint32_t addr, uint32_t val, void *p) +mach32_ap_writel(uint32_t addr, uint32_t val, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; uint8_t port_dword = addr & 0xfc; - if (((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { if (addr & 0x100) { mach_log("Port WORDL Write=%04x.\n", 0x02ee + (port_dword << 8)); mach_accel_outw(0x02ee + (port_dword << 8), val & 0xffff, mach); @@ -4760,13 +4912,13 @@ mach32_ap_writel(uint32_t addr, uint32_t val, void *p) } static uint8_t -mach32_ap_readb(uint32_t addr, void *p) +mach32_ap_readb(uint32_t addr, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; uint8_t temp; uint8_t port_dword = addr & 0xfc; - if (((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { if (addr & 0x100) { temp = mach_accel_inb(0x02ee + (addr & 1) + (port_dword << 8), mach); } else { @@ -4779,13 +4931,13 @@ mach32_ap_readb(uint32_t addr, void *p) } static uint16_t -mach32_ap_readw(uint32_t addr, void *p) +mach32_ap_readw(uint32_t addr, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; uint16_t temp; - uint8_t port_dword = addr & 0xfc; + uint8_t port_dword = addr & 0xfc; - if (((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { if (addr & 0x100) { temp = mach_accel_inw(0x02ee + (port_dword << 8), mach); } else { @@ -4798,13 +4950,13 @@ mach32_ap_readw(uint32_t addr, void *p) } static uint32_t -mach32_ap_readl(uint32_t addr, void *p) +mach32_ap_readl(uint32_t addr, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; uint32_t temp; - uint8_t port_dword = addr & 0xfc; + uint8_t port_dword = addr & 0xfc; - if (((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20)))) { + if ((addr >= ((mach->ap_size << 20) - 0x200)) && (addr < (mach->ap_size << 20))) { if (addr & 0x100) { temp = mach_accel_inw(0x02ee + (port_dword << 8), mach); temp |= (mach_accel_inw(0x02ee + (port_dword << 8) + 4, mach) << 8); @@ -4823,7 +4975,7 @@ mach32_updatemapping(mach_t *mach) { svga_t *svga = &mach->svga; - if ((mach->pci_bus && (!(mach->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM)))) { + if (mach->pci_bus && (!(mach->pci_regs[PCI_REG_COMMAND] & PCI_COMMAND_MEM))) { mem_mapping_disable(&svga->mapping); mem_mapping_disable(&mach->mmio_linear_mapping); return; @@ -4851,6 +5003,9 @@ mach32_updatemapping(mach_t *mach) mem_mapping_set_addr(&svga->mapping, 0xb8000, 0x08000); svga->banked_mask = 0x7fff; break; + + default: + break; } } @@ -4882,11 +5037,12 @@ mach32_updatemapping(mach_t *mach) static void mach32_hwcursor_draw(svga_t *svga, int displine) { - mach_t *mach = (mach_t *) svga->p; - uint16_t dat; - int comb; - int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; - uint32_t color0, color1; + const mach_t *mach = (mach_t *) svga->priv; + uint16_t dat; + int comb; + int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; + uint32_t color0; + uint32_t color1; if (svga->bpp == 8) { color0 = svga->pallook[mach->cursor_col_0]; @@ -4916,13 +5072,16 @@ mach32_hwcursor_draw(svga_t *svga, int displine) if (offset >= svga->hwcursor_latch.x) { switch (comb) { case 0: - ((uint32_t *) svga->monitor->target_buffer->line[displine])[offset + svga->x_add] = color0; + (svga->monitor->target_buffer->line[displine])[offset + svga->x_add] = color0; break; case 1: - ((uint32_t *) svga->monitor->target_buffer->line[displine])[offset + svga->x_add] = color1; + (svga->monitor->target_buffer->line[displine])[offset + svga->x_add] = color1; break; case 3: - ((uint32_t *) svga->monitor->target_buffer->line[displine])[offset + svga->x_add] ^= 0xffffff; + (svga->monitor->target_buffer->line[displine])[offset + svga->x_add] ^= 0xffffff; + break; + + default: break; } } @@ -4938,11 +5097,11 @@ static void mach_io_remove(mach_t *mach) { io_removehandler(0x01ce, 2, - mach_in, NULL, NULL, - mach_out, NULL, NULL, mach); + mach_in, NULL, NULL, + mach_out, NULL, NULL, mach); io_removehandler(0x03c0, 32, - mach_in, NULL, NULL, - mach_out, NULL, NULL, mach); + mach_in, NULL, NULL, + mach_out, NULL, NULL, mach); io_removehandler(0x2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); io_removehandler(0x2ea, 0x0004, mach_in, NULL, NULL, mach_out, NULL, NULL, mach); @@ -5058,11 +5217,11 @@ static void mach_io_set(mach_t *mach) { io_sethandler(0x01ce, 2, - mach_in, NULL, NULL, - mach_out, NULL, NULL, mach); + mach_in, NULL, NULL, + mach_out, NULL, NULL, mach); io_sethandler(0x03c0, 32, - mach_in, NULL, NULL, - mach_out, NULL, NULL, mach); + mach_in, NULL, NULL, + mach_out, NULL, NULL, mach); io_sethandler(0x2e8, 0x0002, mach_accel_inb, mach_accel_inw, NULL, mach_accel_outb, mach_accel_outw, NULL, mach); io_sethandler(0x2ea, 0x0004, mach_in, NULL, NULL, mach_out, NULL, NULL, mach); @@ -5175,10 +5334,10 @@ mach_io_set(mach_t *mach) } static uint8_t -mach32_pci_read(int func, int addr, void *p) +mach32_pci_read(UNUSED(int func), int addr, void *priv) { - mach_t *mach = (mach_t *) p; - uint8_t ret = 0x00; + const mach_t *mach = (mach_t *) priv; + uint8_t ret = 0x00; switch (addr) { case 0x00: @@ -5242,15 +5401,18 @@ mach32_pci_read(int func, int addr, void *p) case 0x3d: ret = PCI_INTA; break; + + default: + break; } return ret; } static void -mach32_pci_write(int func, int addr, uint8_t val, void *p) +mach32_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; switch (addr) { case PCI_REG_COMMAND: @@ -5288,22 +5450,25 @@ mach32_pci_write(int func, int addr, uint8_t val, void *p) case 0x3c: mach->int_line = val; break; + + default: + break; } } static void * mach8_init(const device_t *info) { - mach_t *mach; - svga_t *svga; + mach_t *mach; + svga_t *svga; ibm8514_t *dev; - uint32_t memory; + uint32_t memory; mach = malloc(sizeof(mach_t)); memset(mach, 0x00, sizeof(mach_t)); svga = &mach->svga; - dev = &svga->dev8514; + dev = &svga->dev8514; mach->pci_bus = !!(info->flags & DEVICE_PCI); mach->vlb_bus = !!(info->flags & DEVICE_VLB); @@ -5339,10 +5504,10 @@ mach8_init(const device_t *info) } svga_init(info, svga, mach, dev->local ? (memory << 10) : (512 << 10), /*default: 512kB for Mach8, 2MB for Mach32*/ - mach_recalctimings, - mach_in, mach_out, - dev->local ? mach32_hwcursor_draw : NULL, - NULL); + mach_recalctimings, + mach_in, mach_out, + dev->local ? mach32_hwcursor_draw : NULL, + NULL); if (dev->local) { switch (memory) { @@ -5355,10 +5520,13 @@ mach8_init(const device_t *info) case 4096: mach->misc |= 0x0c; break; + + default: + break; } svga->hwcursor.cur_ysize = 64; - mach->config1 = 0x20; - mach->config2 = 0x08; + mach->config1 = 0x20; + mach->config2 = 0x08; /*Fake the RAMDAC to give the VLB/MCA variants full 24-bit support until said RAMDAC is implemented.*/ if (mach->vlb_bus) { video_inform(VIDEO_FLAG_TYPE_8514, &timing_mach32_vlb); @@ -5377,33 +5545,33 @@ mach8_init(const device_t *info) mem_mapping_disable(&mach->mmio_linear_mapping); } else { video_inform(VIDEO_FLAG_TYPE_8514, &timing_gfxultra_isa); - mach->config1 = 0x02 | 0x20 | 0x80; - mach->config2 = 0x02; + mach->config1 = 0x02 | 0x20 | 0x80; + mach->config2 = 0x02; dev->ext_pitch = 1024; } svga->force_old_addr = 1; - svga->miscout = 1; - svga->bpp = 8; - svga->packed_chain4 = 1; - ibm8514_enabled = 1; - ibm8514_has_vga = 1; - dev->ibm_mode = 1; - dev->rowoffset = 128; + svga->miscout = 1; + svga->bpp = 8; + svga->packed_chain4 = 1; + ibm8514_enabled = 1; + ibm8514_has_vga = 1; + dev->ibm_mode = 1; + dev->rowoffset = 128; mach_io_set(mach); if (dev->local) { - svga->decode_mask = (4 << 20) - 1; - mach->cursor_col_1 = 0xff; + svga->decode_mask = (4 << 20) - 1; + mach->cursor_col_1 = 0xff; mach->ext_cur_col_1_r = 0xff; mach->ext_cur_col_1_g = 0xff; - dev->ext_crt_pitch = 128; + dev->ext_crt_pitch = 128; if (mach->vlb_bus) ati_eeprom_load(&mach->eeprom, "mach32_vlb.nvr", 1); else if (mach->pci_bus) { ati_eeprom_load(&mach->eeprom, "mach32_pci.nvr", 1); mem_mapping_disable(&mach->bios_rom.mapping); - mach->card = pci_add_card(PCI_ADD_VIDEO, mach32_pci_read, mach32_pci_write, mach); + mach->card = pci_add_card(PCI_ADD_VIDEO, mach32_pci_read, mach32_pci_write, mach); mach->pci_regs[PCI_REG_COMMAND] = 0x83; mach->pci_regs[0x30] = 0x00; mach->pci_regs[0x32] = 0x0c; @@ -5414,7 +5582,7 @@ mach8_init(const device_t *info) ati_eeprom_load_mach8(&mach->eeprom, "mach8.nvr"); } - return (mach); + return mach; } static int @@ -5442,11 +5610,11 @@ mach32_pci_available(void) } static void -mach_close(void *p) +mach_close(void *priv) { - mach_t *mach = (mach_t *) p; - svga_t *svga = &mach->svga; - ibm8514_t *dev = &svga->dev8514; + mach_t *mach = (mach_t *) priv; + svga_t *svga = &mach->svga; + ibm8514_t *dev = &svga->dev8514; if (dev) { free(dev->vram); @@ -5458,18 +5626,18 @@ mach_close(void *p) } static void -mach_speed_changed(void *p) +mach_speed_changed(void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; svga_t *svga = &mach->svga; svga_recalctimings(svga); } static void -mach_force_redraw(void *p) +mach_force_redraw(void *priv) { - mach_t *mach = (mach_t *) p; + mach_t *mach = (mach_t *) priv; svga_t *svga = &mach->svga; svga->fullchange = changeframecount; diff --git a/src/video/vid_att20c49x_ramdac.c b/src/video/vid_att20c49x_ramdac.c index 1874afce9..3f995c56a 100644 --- a/src/video/vid_att20c49x_ramdac.c +++ b/src/video/vid_att20c49x_ramdac.c @@ -63,6 +63,9 @@ att49x_ramdac_control(uint8_t val, void *p, svga_t *svga) case 7: svga->bpp = 24; break; + + default: + break; } if (ramdac->type == ATT_490 || ramdac->type == ATT_491) svga_set_ramdac_type(svga, (val & 2) ? RAMDAC_8BIT : RAMDAC_6BIT); @@ -100,6 +103,9 @@ att49x_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga) att49x_ramdac_control(val, ramdac, svga); ramdac->state = 0; break; + + default: + break; } } @@ -143,6 +149,9 @@ att49x_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga) temp = ramdac->ctrl; ramdac->state = 0; break; + + default: + break; } return temp; diff --git a/src/video/vid_att2xc498_ramdac.c b/src/video/vid_att2xc498_ramdac.c index 2dab4b903..9919b7111 100644 --- a/src/video/vid_att2xc498_ramdac.c +++ b/src/video/vid_att2xc498_ramdac.c @@ -102,6 +102,9 @@ att498_ramdac_out(uint16_t addr, int rs2, uint8_t val, void *p, svga_t *svga) case 0x06: att498_ramdac_control(val, ramdac, svga); break; + + default: + break; } } @@ -147,6 +150,9 @@ att498_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga) temp = ramdac->ctrl; ramdac->state = 0; break; + + default: + break; } return temp; diff --git a/src/video/vid_av9194.c b/src/video/vid_av9194.c index f8ebc89de..e7cf75dee 100644 --- a/src/video/vid_av9194.c +++ b/src/video/vid_av9194.c @@ -27,9 +27,10 @@ #include <86box/timer.h> #include <86box/video.h> #include <86box/vid_svga.h> +#include <86box/plat_unused.h> float -av9194_getclock(int clock, void *p) +av9194_getclock(int clock, UNUSED(void *priv)) { float ret = 0.0; @@ -79,13 +80,16 @@ av9194_getclock(int clock, void *p) case 0xf: ret = 94500000.0; break; + + default: + break; } return ret; } static void * -av9194_init(const device_t *info) +av9194_init(UNUSED(const device_t *info)) { /* Return something non-NULL. */ return (void *) &av9194_device; diff --git a/src/video/vid_bt48x_ramdac.c b/src/video/vid_bt48x_ramdac.c index 9ef75b09e..bb276ece6 100644 --- a/src/video/vid_bt48x_ramdac.c +++ b/src/video/vid_bt48x_ramdac.c @@ -77,6 +77,9 @@ bt48x_set_bpp(bt48x_ramdac_t *ramdac, svga_t *svga) case 0x60: svga->bpp = 4; break; + + default: + break; } svga_recalctimings(svga); } @@ -104,7 +107,7 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * svga->dac_status = addr & 0x03; svga->dac_addr = val; if (ramdac->type >= BT485) - svga->dac_addr |= ((int) (ramdac->cmd_r3 & 0x03) << 8); + svga->dac_addr |= ((ramdac->cmd_r3 & 0x03) << 8); if (svga->dac_status) svga->dac_addr = (svga->dac_addr + 1) & da_mask; break; @@ -143,6 +146,9 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * svga->dac_addr = (svga->dac_addr + 1) & 0xff; svga->dac_pos = 0; break; + + default: + break; } break; case 0x06: /* Command Register 0 (RS value = 0110) */ @@ -183,6 +189,9 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * break; } break; + + default: + break; } } break; @@ -215,6 +224,9 @@ bt48x_ramdac_out(uint16_t addr, int rs2, int rs3, uint8_t val, void *p, svga_t * ramdac->hwc_y = (ramdac->hwc_y & 0x00ff) | ((val & 0x0f) << 8); svga->dac_hwcursor.y = ramdac->hwc_y - svga->dac_hwcursor.cur_ysize; break; + + default: + break; } return; @@ -271,6 +283,9 @@ bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga) else temp = ramdac->extpal[index].b & 0x3f; break; + + default: + break; } break; case 0x06: /* Command Register 0 (RS value = 0110) */ @@ -285,8 +300,8 @@ bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga) case 0x0a: if ((ramdac->type >= BT485) && (ramdac->cmd_r0 & 0x80)) { switch (svga->dac_addr & ((ramdac->type >= BT485A) ? 0xff : 0x3f)) { - case 0x00: default: + case 0x00: temp = ramdac->status | (svga->dac_status ? 0x04 : 0x00); break; case 0x01: @@ -307,7 +322,6 @@ bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga) temp = 0xff; break; } - break; } } else temp = ramdac->status | (svga->dac_status ? 0x04 : 0x00); @@ -337,6 +351,9 @@ bt48x_ramdac_in(uint16_t addr, int rs2, int rs3, void *p, svga_t *svga) case 0x0f: /* Cursor Y High Register (RS value = 1111) */ temp = (ramdac->hwc_y >> 8) & 0xff; break; + + default: + break; } return temp; @@ -419,6 +436,9 @@ bt48x_hwcursor_draw(svga_t *svga, int displine) case 3: p[x_pos] = clr3; break; + + default: + break; } break; case 2: /* PM/Windows */ @@ -432,6 +452,9 @@ bt48x_hwcursor_draw(svga_t *svga, int displine) case 3: p[x_pos] ^= 0xffffff; break; + + default: + break; } break; case 3: /* X-Windows */ @@ -442,8 +465,14 @@ bt48x_hwcursor_draw(svga_t *svga, int displine) case 3: p[x_pos] = clr2; break; + + default: + break; } break; + + default: + break; } } offset++; @@ -484,6 +513,9 @@ bt48x_ramdac_init(const device_t *info) case BT485A: ramdac->status = 0x20; break; + + default: + break; } return ramdac; diff --git a/src/video/vid_cga.c b/src/video/vid_cga.c index 1fd8babb5..14ff3b221 100644 --- a/src/video/vid_cga.c +++ b/src/video/vid_cga.c @@ -33,6 +33,7 @@ #include <86box/video.h> #include <86box/vid_cga.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> #define CGA_RGB 0 #define CGA_COMPOSITE 1 @@ -50,9 +51,9 @@ static video_timings_t timing_cga = { .type = VIDEO_ISA, .write_b = 8, .write_w void cga_recalctimings(cga_t *cga); void -cga_out(uint16_t addr, uint8_t val, void *p) +cga_out(uint16_t addr, uint8_t val, void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; uint8_t old; if ((addr >= 0x3d0) && (addr <= 0x3d7)) @@ -89,13 +90,16 @@ cga_out(uint16_t addr, uint8_t val, void *p) if (old ^ val) cga_recalctimings(cga); return; + + default: + break; } } uint8_t -cga_in(uint16_t addr, void *p) +cga_in(uint16_t addr, void *priv) { - cga_t *cga = (cga_t *) p; + const cga_t *cga = (cga_t *) priv; uint8_t ret = 0xff; @@ -112,29 +116,32 @@ cga_in(uint16_t addr, void *p) case 0x3DA: ret = cga->cgastat; break; + + default: + break; } return ret; } void -cga_pravetz_out(uint16_t addr, uint8_t val, void *p) +cga_pravetz_out(UNUSED(uint16_t addr), uint8_t val, void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; cga->fontbase = (((unsigned int) val) << 8); } uint8_t -cga_pravetz_in(uint16_t addr, void *p) +cga_pravetz_in(UNUSED(uint16_t addr), void *priv) { - cga_t *cga = (cga_t *) p; + const cga_t *cga = (cga_t *) priv; return (cga->fontbase >> 8); } void -cga_waitstates(void *p) +cga_waitstates(UNUSED(void *priv)) { int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; int ws; @@ -144,9 +151,9 @@ cga_waitstates(void *p) } void -cga_write(uint32_t addr, uint8_t val, void *p) +cga_write(uint32_t addr, uint8_t val, void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; cga->vram[addr & 0x3fff] = val; if (cga->snow_enabled) { @@ -158,9 +165,9 @@ cga_write(uint32_t addr, uint8_t val, void *p) } uint8_t -cga_read(uint32_t addr, void *p) +cga_read(uint32_t addr, void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; cga_waitstates(cga); if (cga->snow_enabled) { @@ -193,9 +200,9 @@ cga_recalctimings(cga_t *cga) } void -cga_poll(void *p) +cga_poll(void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; uint16_t ca = (cga->crtc[15] | (cga->crtc[14] << 8)) & 0x3fff; int drawcursor; int x; @@ -508,7 +515,7 @@ cga_init(cga_t *cga) } void * -cga_standalone_init(const device_t *info) +cga_standalone_init(UNUSED(const device_t *info)) { int display_type; cga_t *cga = malloc(sizeof(cga_t)); @@ -554,18 +561,18 @@ cga_pravetz_init(const device_t *info) } void -cga_close(void *p) +cga_close(void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; free(cga->vram); free(cga); } void -cga_speed_changed(void *p) +cga_speed_changed(void *priv) { - cga_t *cga = (cga_t *) p; + cga_t *cga = (cga_t *) priv; cga_recalctimings(cga); } diff --git a/src/video/vid_cga_comp.c b/src/video/vid_cga_comp.c index 6ffc5cbcd..31e4a6bf7 100644 --- a/src/video/vid_cga_comp.c +++ b/src/video/vid_cga_comp.c @@ -172,7 +172,7 @@ update_cga16_color(uint8_t cgamode) video_sharpness = (int) (sharpness * 256 / 100); } -static Bit8u +static uint8_t byte_clamp(int v) { v >>= 13; @@ -186,21 +186,20 @@ static int temp[SCALER_MAXWIDTH + 10] = { 0 }; static int atemp[SCALER_MAXWIDTH + 2] = { 0 }; static int btemp[SCALER_MAXWIDTH + 2] = { 0 }; -Bit32u * -Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewidth*/, Bit32u *TempLine) +uint32_t * +Composite_Process(uint8_t cgamode, uint8_t border, uint32_t blocks /*, bool doublewidth*/, uint32_t *TempLine) { - int x; - Bit32u x2; + uint32_t x2; int w = blocks * 4; - int *o; - Bit32u *rgbi; - int *b; - int *i; - Bit32u *srgb; - int *ap; - int *bp; + int *o; + const uint32_t *rgbi; + const int *b; + int *i; + uint32_t *srgb; + int *ap; + int *bp; #define COMPOSITE_CONVERT(I, Q) \ do { \ @@ -230,21 +229,21 @@ Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewi o = temp; rgbi = TempLine; b = &CGA_Composite_Table[border * 68]; - for (x = 0; x < 4; ++x) + for (uint8_t x = 0; x < 4; ++x) OUT(b[(x + 3) & 3]); OUT(CGA_Composite_Table[(border << 6) | ((*rgbi & 0x0f) << 2) | 3]); - for (x = 0; x < w - 1; ++x) { + for (int x = 0; x < w - 1; ++x) { OUT(CGA_Composite_Table[((rgbi[0] & 0x0f) << 6) | ((rgbi[1] & 0x0f) << 2) | (x & 3)]); ++rgbi; } OUT(CGA_Composite_Table[((*rgbi & 0x0f) << 6) | (border << 2) | 3]); - for (x = 0; x < 5; ++x) + for (uint8_t x = 0; x < 5; ++x) OUT(b[x & 3]); if ((cgamode & 4) != 0) { /* Decode */ i = temp + 5; - srgb = (Bit32u *) TempLine; + srgb = TempLine; for (x2 = 0; x2 < blocks * 4; ++x2) { int c = (i[0] + i[0]) << 3; int d = (i[-1] + i[1]) << 3; @@ -258,7 +257,7 @@ Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewi i = temp + 4; ap = atemp + 1; bp = btemp + 1; - for (x = -1; x < w + 1; ++x) { + for (int x = -1; x < w + 1; ++x) { ap[x] = i[-4] - ((i[-2] - i[0] + i[2]) << 1) + i[4]; bp[x] = (i[-3] - i[-1] + i[1] - i[3]) << 1; ++i; @@ -268,7 +267,7 @@ Composite_Process(uint8_t cgamode, Bit8u border, Bit32u blocks /*, bool doublewi i = temp + 5; i[-1] = (i[-1] << 3) - ap[-1]; i[0] = (i[0] << 3) - ap[0]; - srgb = (Bit32u *) TempLine; + srgb = TempLine; for (x2 = 0; x2 < blocks; ++x2) { int y; int a; diff --git a/src/video/vid_cl54xx.c b/src/video/vid_cl54xx.c index 637598345..225810974 100644 --- a/src/video/vid_cl54xx.c +++ b/src/video/vid_cl54xx.c @@ -236,19 +236,19 @@ static video_timings_t timing_gd54xx_vlb = { .type = VIDEO_BUS, .write_b = 4, .w static video_timings_t timing_gd54xx_pci = { .type = VIDEO_PCI, .write_b = 4, .write_w = 4, .write_l = 8, .read_b = 10, .read_w = 10, .read_l = 20 }; static void -gd543x_mmio_write(uint32_t addr, uint8_t val, void *p); +gd543x_mmio_write(uint32_t addr, uint8_t val, void *priv); static void -gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *p); +gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *priv); static void -gd543x_mmio_writew(uint32_t addr, uint16_t val, void *p); +gd543x_mmio_writew(uint32_t addr, uint16_t val, void *priv); static void -gd543x_mmio_writel(uint32_t addr, uint32_t val, void *p); +gd543x_mmio_writel(uint32_t addr, uint32_t val, void *priv); static uint8_t -gd543x_mmio_read(uint32_t addr, void *p); +gd543x_mmio_read(uint32_t addr, void *priv); static uint16_t -gd543x_mmio_readw(uint32_t addr, void *p); +gd543x_mmio_readw(uint32_t addr, void *priv); static uint32_t -gd543x_mmio_readl(uint32_t addr, void *p); +gd543x_mmio_readl(uint32_t addr, void *priv); static void gd54xx_recalc_banking(gd54xx_t *gd54xx); @@ -492,7 +492,7 @@ gd54xx_update_irqs(gd54xx_t *gd54xx) static void gd54xx_vblank_start(svga_t *svga) { - gd54xx_t *gd54xx = (gd54xx_t *) svga->p; + gd54xx_t *gd54xx = (gd54xx_t *) svga->priv; if (gd54xx->vblank_irq >= 0) { gd54xx->vblank_irq = 1; gd54xx_update_irqs(gd54xx); @@ -512,7 +512,7 @@ gd54xx_is_5422(svga_t *svga) static void gd54xx_overlay_draw(svga_t *svga, int displine) { - gd54xx_t *gd54xx = (gd54xx_t *) svga->p; + gd54xx_t *gd54xx = (gd54xx_t *) svga->priv; int shift = (svga->crtc[0x27] >= CIRRUS_ID_CLGD5446) ? 2 : 0; int h_acc = svga->overlay_latch.h_acc; int r[8]; @@ -612,9 +612,9 @@ gd54xx_is_5434(svga_t *svga) } static void -gd54xx_out(uint16_t addr, uint8_t val, void *p) +gd54xx_out(uint16_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t old; uint8_t o; @@ -1157,9 +1157,9 @@ gd54xx_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -gd54xx_in(uint16_t addr, void *p) +gd54xx_in(uint16_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t index; @@ -1646,7 +1646,7 @@ gd543x_recalc_mapping(gd54xx_t *gd54xx) static void gd54xx_recalctimings(svga_t *svga) { - gd54xx_t *gd54xx = (gd54xx_t *) svga->p; + gd54xx_t *gd54xx = (gd54xx_t *) svga->priv; uint8_t clocksel; uint8_t rdmask; uint8_t linedbl = svga->dispend * 9 / 10 >= svga->hdisp; @@ -1833,7 +1833,7 @@ gd54xx_recalctimings(svga_t *svga) static void gd54xx_hwcursor_draw(svga_t *svga, int displine) { - gd54xx_t *gd54xx = (gd54xx_t *) svga->p; + gd54xx_t *gd54xx = (gd54xx_t *) svga->priv; int comb; int b0; int b1; @@ -1988,9 +1988,9 @@ gd54xx_mem_sys_src_write(gd54xx_t *gd54xx, uint8_t val) } static void -gd54xx_write(uint32_t addr, uint8_t val, void *p) +gd54xx_write(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2009,9 +2009,9 @@ gd54xx_write(uint32_t addr, uint8_t val, void *p) } static void -gd54xx_writew(uint32_t addr, uint16_t val, void *p) +gd54xx_writew(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2036,9 +2036,9 @@ gd54xx_writew(uint32_t addr, uint16_t val, void *p) } static void -gd54xx_writel(uint32_t addr, uint32_t val, void *p) +gd54xx_writel(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2147,9 +2147,9 @@ gd54xx_aperture2_enabled(gd54xx_t *gd54xx) } static uint8_t -gd54xx_readb_linear(uint32_t addr, void *p) +gd54xx_readb_linear(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2187,9 +2187,9 @@ gd54xx_readb_linear(uint32_t addr, void *p) } static uint16_t -gd54xx_readw_linear(uint32_t addr, void *p) +gd54xx_readw_linear(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2209,8 +2209,8 @@ gd54xx_readw_linear(uint32_t addr, void *p) /* Do mem sys dest reads here if the blitter is neither paused, nor is there a second aperture. */ if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - temp = gd54xx_readb_linear(addr, p); - temp |= gd54xx_readb_linear(addr + 1, p) << 8; + temp = gd54xx_readb_linear(addr, priv); + temp |= gd54xx_readb_linear(addr + 1, priv) << 8; return temp; } @@ -2235,9 +2235,9 @@ gd54xx_readw_linear(uint32_t addr, void *p) } static uint32_t -gd54xx_readl_linear(uint32_t addr, void *p) +gd54xx_readl_linear(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2257,10 +2257,10 @@ gd54xx_readl_linear(uint32_t addr, void *p) /* Do mem sys dest reads here if the blitter is neither paused, nor is there a second aperture. */ if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - temp = gd54xx_readb_linear(addr, p); - temp |= gd54xx_readb_linear(addr + 1, p) << 8; - temp |= gd54xx_readb_linear(addr + 2, p) << 16; - temp |= gd54xx_readb_linear(addr + 3, p) << 24; + temp = gd54xx_readb_linear(addr, priv); + temp |= gd54xx_readb_linear(addr + 1, priv) << 8; + temp |= gd54xx_readb_linear(addr + 2, priv) << 16; + temp |= gd54xx_readb_linear(addr + 3, priv) << 24; return temp; } @@ -2294,9 +2294,9 @@ gd54xx_readl_linear(uint32_t addr, void *p) } static uint8_t -gd5436_aperture2_readb(uint32_t addr, void *p) +gd5436_aperture2_readb(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) return gd54xx_mem_sys_dest_read(gd54xx); @@ -2305,14 +2305,14 @@ gd5436_aperture2_readb(uint32_t addr, void *p) } static uint16_t -gd5436_aperture2_readw(uint32_t addr, void *p) +gd5436_aperture2_readw(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; uint16_t ret = 0xffff; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd5436_aperture2_readb(addr, p); - ret |= gd5436_aperture2_readb(addr + 1, p) << 8; + ret = gd5436_aperture2_readb(addr, priv); + ret |= gd5436_aperture2_readb(addr + 1, priv) << 8; return ret; } @@ -2320,16 +2320,16 @@ gd5436_aperture2_readw(uint32_t addr, void *p) } static uint32_t -gd5436_aperture2_readl(uint32_t addr, void *p) +gd5436_aperture2_readl(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; uint32_t ret = 0xffffffff; if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd5436_aperture2_readb(addr, p); - ret |= gd5436_aperture2_readb(addr + 1, p) << 8; - ret |= gd5436_aperture2_readb(addr + 2, p) << 16; - ret |= gd5436_aperture2_readb(addr + 3, p) << 24; + ret = gd5436_aperture2_readb(addr, priv); + ret |= gd5436_aperture2_readb(addr + 1, priv) << 8; + ret |= gd5436_aperture2_readb(addr + 2, priv) << 16; + ret |= gd5436_aperture2_readb(addr + 3, priv) << 24; return ret; } @@ -2337,9 +2337,9 @@ gd5436_aperture2_readl(uint32_t addr, void *p) } static void -gd5436_aperture2_writeb(uint32_t addr, uint8_t val, void *p) +gd5436_aperture2_writeb(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) @@ -2347,9 +2347,9 @@ gd5436_aperture2_writeb(uint32_t addr, uint8_t val, void *p) } static void -gd5436_aperture2_writew(uint32_t addr, uint16_t val, void *p) +gd5436_aperture2_writew(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2359,9 +2359,9 @@ gd5436_aperture2_writew(uint32_t addr, uint16_t val, void *p) } static void -gd5436_aperture2_writel(uint32_t addr, uint32_t val, void *p) +gd5436_aperture2_writel(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (gd54xx->countminusone && !gd54xx->blt.ms_is_dest && gd54xx_aperture2_enabled(gd54xx) && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2373,9 +2373,9 @@ gd5436_aperture2_writel(uint32_t addr, uint32_t val, void *p) } static void -gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *p) +gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2401,8 +2401,8 @@ gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *p) } switch (ap) { - case 0: default: + case 0: break; case 1: /* 0 -> 1, 1 -> 0, 2 -> 3, 3 -> 2 */ @@ -2420,9 +2420,9 @@ gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *p) } static void -gd54xx_writew_linear(uint32_t addr, uint16_t val, void *p) +gd54xx_writew_linear(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2484,9 +2484,9 @@ gd54xx_writew_linear(uint32_t addr, uint16_t val, void *p) } static void -gd54xx_writel_linear(uint32_t addr, uint32_t val, void *p) +gd54xx_writel_linear(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ap = gd54xx_get_aperture(addr); @@ -2561,9 +2561,9 @@ gd54xx_writel_linear(uint32_t addr, uint32_t val, void *p) } static uint8_t -gd54xx_read(uint32_t addr, void *p) +gd54xx_read(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if ((svga->seqregs[0x07] & 0x01) == 0) @@ -2577,9 +2577,9 @@ gd54xx_read(uint32_t addr, void *p) } static uint16_t -gd54xx_readw(uint32_t addr, void *p) +gd54xx_readw(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint16_t ret; @@ -2587,8 +2587,8 @@ gd54xx_readw(uint32_t addr, void *p) return svga_readw(addr, svga); if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd54xx_read(addr, p); - ret |= gd54xx_read(addr + 1, p) << 8; + ret = gd54xx_read(addr, priv); + ret |= gd54xx_read(addr + 1, priv) << 8; return ret; } @@ -2597,9 +2597,9 @@ gd54xx_readw(uint32_t addr, void *p) } static uint32_t -gd54xx_readl(uint32_t addr, void *p) +gd54xx_readl(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint32_t ret; @@ -2607,10 +2607,10 @@ gd54xx_readl(uint32_t addr, void *p) return svga_readl(addr, svga); if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd54xx_read(addr, p); - ret |= gd54xx_read(addr + 1, p) << 8; - ret |= gd54xx_read(addr + 2, p) << 16; - ret |= gd54xx_read(addr + 3, p) << 24; + ret = gd54xx_read(addr, priv); + ret |= gd54xx_read(addr + 1, priv) << 8; + ret |= gd54xx_read(addr + 2, priv) << 16; + ret |= gd54xx_read(addr + 3, priv) << 24; return ret; } @@ -2628,9 +2628,9 @@ gd543x_do_mmio(svga_t *svga, uint32_t addr) } static void -gd543x_mmio_write(uint32_t addr, uint8_t val, void *p) +gd543x_mmio_write(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t old; @@ -2794,9 +2794,9 @@ gd543x_mmio_write(uint32_t addr, uint8_t val, void *p) } static void -gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *p) +gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (!gd543x_do_mmio(svga, addr) && !gd54xx->blt.ms_is_dest && gd54xx->countminusone && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { @@ -2804,13 +2804,13 @@ gd543x_mmio_writeb(uint32_t addr, uint8_t val, void *p) return; } - gd543x_mmio_write(addr, val, p); + gd543x_mmio_write(addr, val, priv); } static void -gd543x_mmio_writew(uint32_t addr, uint16_t val, void *p) +gd543x_mmio_writew(uint32_t addr, uint16_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd543x_do_mmio(svga, addr)) { @@ -2828,9 +2828,9 @@ gd543x_mmio_writew(uint32_t addr, uint16_t val, void *p) } static void -gd543x_mmio_writel(uint32_t addr, uint32_t val, void *p) +gd543x_mmio_writel(uint32_t addr, uint32_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; if (gd543x_do_mmio(svga, addr)) { @@ -2854,9 +2854,9 @@ gd543x_mmio_writel(uint32_t addr, uint32_t val, void *p) } static uint8_t -gd543x_mmio_read(uint32_t addr, void *p) +gd543x_mmio_read(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ret = 0xff; @@ -2993,9 +2993,9 @@ gd543x_mmio_read(uint32_t addr, void *p) } static uint16_t -gd543x_mmio_readw(uint32_t addr, void *p) +gd543x_mmio_readw(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint16_t ret = 0xffff; @@ -3004,8 +3004,8 @@ gd543x_mmio_readw(uint32_t addr, void *p) else if (gd54xx->mmio_vram_overlap) ret = gd54xx_read(addr, gd54xx) | (gd54xx_read(addr + 1, gd54xx) << 8); else if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd543x_mmio_read(addr, p); - ret |= gd543x_mmio_read(addr + 1, p) << 8; + ret = gd543x_mmio_read(addr, priv); + ret |= gd543x_mmio_read(addr + 1, priv) << 8; return ret; } @@ -3013,9 +3013,9 @@ gd543x_mmio_readw(uint32_t addr, void *p) } static uint32_t -gd543x_mmio_readl(uint32_t addr, void *p) +gd543x_mmio_readl(uint32_t addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint32_t ret = 0xffffffff; @@ -3024,10 +3024,10 @@ gd543x_mmio_readl(uint32_t addr, void *p) else if (gd54xx->mmio_vram_overlap) ret = gd54xx_read(addr, gd54xx) | (gd54xx_read(addr + 1, gd54xx) << 8) | (gd54xx_read(addr + 2, gd54xx) << 16) | (gd54xx_read(addr + 3, gd54xx) << 24); else if (gd54xx->countminusone && gd54xx->blt.ms_is_dest && !(gd54xx->blt.status & CIRRUS_BLT_PAUSED)) { - ret = gd543x_mmio_read(addr, p); - ret |= gd543x_mmio_read(addr + 1, p) << 8; - ret |= gd543x_mmio_read(addr + 2, p) << 16; - ret |= gd543x_mmio_read(addr + 3, p) << 24; + ret = gd543x_mmio_read(addr, priv); + ret |= gd543x_mmio_read(addr + 1, priv) << 8; + ret |= gd543x_mmio_read(addr + 2, priv) << 16; + ret |= gd543x_mmio_read(addr + 3, priv) << 24; return ret; } @@ -3035,86 +3035,86 @@ gd543x_mmio_readl(uint32_t addr, void *p) } static void -gd5480_vgablt_write(uint32_t addr, uint8_t val, void *p) +gd5480_vgablt_write(uint32_t addr, uint8_t val, void *priv) { addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - gd543x_mmio_writeb((addr & 0x000000ff) | 0x000b8000, val, p); + gd543x_mmio_writeb((addr & 0x000000ff) | 0x000b8000, val, priv); else if (addr < 0x00000100) - gd54xx_out(0x03c0 + addr, val, p); + gd54xx_out(0x03c0 + addr, val, priv); } static void -gd5480_vgablt_writew(uint32_t addr, uint16_t val, void *p) +gd5480_vgablt_writew(uint32_t addr, uint16_t val, void *priv) { addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - gd543x_mmio_writew((addr & 0x000000ff) | 0x000b8000, val, p); + gd543x_mmio_writew((addr & 0x000000ff) | 0x000b8000, val, priv); else if (addr < 0x00000100) { - gd5480_vgablt_write(addr, val & 0xff, p); - gd5480_vgablt_write(addr + 1, val >> 8, p); + gd5480_vgablt_write(addr, val & 0xff, priv); + gd5480_vgablt_write(addr + 1, val >> 8, priv); } } static void -gd5480_vgablt_writel(uint32_t addr, uint32_t val, void *p) +gd5480_vgablt_writel(uint32_t addr, uint32_t val, void *priv) { addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - gd543x_mmio_writel((addr & 0x000000ff) | 0x000b8000, val, p); + gd543x_mmio_writel((addr & 0x000000ff) | 0x000b8000, val, priv); else if (addr < 0x00000100) { - gd5480_vgablt_writew(addr, val & 0xffff, p); - gd5480_vgablt_writew(addr + 2, val >> 16, p); + gd5480_vgablt_writew(addr, val & 0xffff, priv); + gd5480_vgablt_writew(addr + 2, val >> 16, priv); } } static uint8_t -gd5480_vgablt_read(uint32_t addr, void *p) +gd5480_vgablt_read(uint32_t addr, void *priv) { uint8_t ret = 0xff; addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - ret = gd543x_mmio_read((addr & 0x000000ff) | 0x000b8000, p); + ret = gd543x_mmio_read((addr & 0x000000ff) | 0x000b8000, priv); else if (addr < 0x00000100) - ret = gd54xx_in(0x03c0 + addr, p); + ret = gd54xx_in(0x03c0 + addr, priv); return ret; } static uint16_t -gd5480_vgablt_readw(uint32_t addr, void *p) +gd5480_vgablt_readw(uint32_t addr, void *priv) { uint16_t ret = 0xffff; addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - ret = gd543x_mmio_readw((addr & 0x000000ff) | 0x000b8000, p); + ret = gd543x_mmio_readw((addr & 0x000000ff) | 0x000b8000, priv); else if (addr < 0x00000100) { - ret = gd5480_vgablt_read(addr, p); - ret |= (gd5480_vgablt_read(addr + 1, p) << 8); + ret = gd5480_vgablt_read(addr, priv); + ret |= (gd5480_vgablt_read(addr + 1, priv) << 8); } return ret; } static uint32_t -gd5480_vgablt_readl(uint32_t addr, void *p) +gd5480_vgablt_readl(uint32_t addr, void *priv) { uint32_t ret = 0xffffffff; addr &= 0x00000fff; if ((addr >= 0x00000100) && (addr < 0x00000200)) - ret = gd543x_mmio_readl((addr & 0x000000ff) | 0x000b8000, p); + ret = gd543x_mmio_readl((addr & 0x000000ff) | 0x000b8000, priv); else if (addr < 0x00000100) { - ret = gd5480_vgablt_readw(addr, p); - ret |= (gd5480_vgablt_readw(addr + 2, p) << 16); + ret = gd5480_vgablt_readw(addr, priv); + ret |= (gd5480_vgablt_readw(addr + 2, priv) << 16); } return ret; @@ -3557,9 +3557,9 @@ gd54xx_start_blit(uint32_t cpu_dat, uint32_t count, gd54xx_t *gd54xx, svga_t *sv } static uint8_t -cl_pci_read(int func, int addr, void *p) +cl_pci_read(int func, int addr, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint8_t ret = 0x00; @@ -3656,9 +3656,9 @@ cl_pci_read(int func, int addr, void *p) } static void -cl_pci_write(int func, int addr, uint8_t val, void *p) +cl_pci_write(int func, int addr, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_t *svga = &gd54xx->svga; uint32_t byte; @@ -3724,17 +3724,17 @@ cl_pci_write(int func, int addr, uint8_t val, void *p) } static uint8_t -gd5428_mca_read(int port, void *p) +gd5428_mca_read(int port, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; return gd54xx->pos_regs[port & 7]; } static void -gd5428_mca_write(int port, uint8_t val, void *p) +gd5428_mca_write(int port, uint8_t val, void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; if (port < 0x102) return; @@ -3744,7 +3744,7 @@ gd5428_mca_write(int port, uint8_t val, void *p) } static uint8_t -gd5428_mca_feedb(void *p) +gd5428_mca_feedb(void *priv) { return 1; } @@ -4264,9 +4264,9 @@ gd5480_available(void) } void -gd54xx_close(void *p) +gd54xx_close(void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_close(&gd54xx->svga); @@ -4279,17 +4279,17 @@ gd54xx_close(void *p) } void -gd54xx_speed_changed(void *p) +gd54xx_speed_changed(void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; svga_recalctimings(&gd54xx->svga); } void -gd54xx_force_redraw(void *p) +gd54xx_force_redraw(void *priv) { - gd54xx_t *gd54xx = (gd54xx_t *) p; + gd54xx_t *gd54xx = (gd54xx_t *) priv; gd54xx->svga.fullchange = gd54xx->svga.monitor->mon_changeframecount; } diff --git a/src/video/vid_colorplus.c b/src/video/vid_colorplus.c index 81c1746f3..be176d9d0 100644 --- a/src/video/vid_colorplus.c +++ b/src/video/vid_colorplus.c @@ -34,6 +34,7 @@ #include <86box/vid_cga.h> #include <86box/vid_colorplus.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> /* Bits in the colorplus control register: */ #define COLORPLUS_PLANE_SWAP 0x40 /* Swap planes at 0000h and 4000h */ @@ -55,9 +56,9 @@ video_timings_t timing_colorplus = { .type = VIDEO_ISA, .write_b = 8, .write_w = void cga_recalctimings(cga_t *cga); void -colorplus_out(uint16_t addr, uint8_t val, void *p) +colorplus_out(uint16_t addr, uint8_t val, void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; if (addr == 0x3DD) { colorplus->control = val & 0x70; @@ -67,17 +68,17 @@ colorplus_out(uint16_t addr, uint8_t val, void *p) } uint8_t -colorplus_in(uint16_t addr, void *p) +colorplus_in(uint16_t addr, void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; return cga_in(addr, &colorplus->cga); } void -colorplus_write(uint32_t addr, uint8_t val, void *p) +colorplus_write(uint32_t addr, uint8_t val, void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; if ((colorplus->control & COLORPLUS_PLANE_SWAP) && (colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_GRAPHICS_MODE)) { addr ^= 0x4000; @@ -94,9 +95,9 @@ colorplus_write(uint32_t addr, uint8_t val, void *p) } uint8_t -colorplus_read(uint32_t addr, void *p) +colorplus_read(uint32_t addr, void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; if ((colorplus->control & COLORPLUS_PLANE_SWAP) && (colorplus->control & COLORPLUS_EITHER_MODE) && (colorplus->cga.cgamode & CGA_GRAPHICS_MODE)) { addr ^= 0x4000; @@ -119,9 +120,9 @@ colorplus_recalctimings(colorplus_t *colorplus) } void -colorplus_poll(void *p) +colorplus_poll(void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; int x; int c; int oldvc; @@ -333,7 +334,7 @@ colorplus_init(colorplus_t *colorplus) } void * -colorplus_standalone_init(const device_t *info) +colorplus_standalone_init(UNUSED(const device_t *info)) { int display_type; @@ -362,18 +363,18 @@ colorplus_standalone_init(const device_t *info) } void -colorplus_close(void *p) +colorplus_close(void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; free(colorplus->cga.vram); free(colorplus); } void -colorplus_speed_changed(void *p) +colorplus_speed_changed(void *priv) { - colorplus_t *colorplus = (colorplus_t *) p; + colorplus_t *colorplus = (colorplus_t *) priv; cga_recalctimings(&colorplus->cga); } diff --git a/src/video/vid_compaq_cga.c b/src/video/vid_compaq_cga.c index c913e6e7c..4753ec223 100644 --- a/src/video/vid_compaq_cga.c +++ b/src/video/vid_compaq_cga.c @@ -83,9 +83,9 @@ compaq_cga_recalctimings(compaq_cga_t *self) } void -compaq_cga_poll(void *p) +compaq_cga_poll(void *priv) { - compaq_cga_t *self = (compaq_cga_t *) p; + compaq_cga_t *self = (compaq_cga_t *) priv; uint16_t ca = (self->cga.crtc[15] | (self->cga.crtc[14] << 8)) & 0x3fff; int drawcursor; int x; @@ -452,18 +452,18 @@ compaq_cga_init(const device_t *info) } void -compaq_cga_close(void *p) +compaq_cga_close(void *priv) { - compaq_cga_t *self = (compaq_cga_t *) p; + compaq_cga_t *self = (compaq_cga_t *) priv; free(self->cga.vram); free(self); } void -compaq_cga_speed_changed(void *p) +compaq_cga_speed_changed(void *priv) { - compaq_cga_t *self = (compaq_cga_t *) p; + compaq_cga_t *self = (compaq_cga_t *) priv; if (self->cga.crtc[9] == 13) /* Character height */ compaq_cga_recalctimings(self); diff --git a/src/video/vid_ega.c b/src/video/vid_ega.c index 8cfd51db6..babd45756 100644 --- a/src/video/vid_ega.c +++ b/src/video/vid_ega.c @@ -56,7 +56,7 @@ static video_timings_t timing_ega = { .type = VIDEO_ISA, .write_b = 8, .write_w static uint8_t ega_rotate[8][256]; static uint32_t pallook16[256]; static uint32_t pallook64[256]; -static int ega_type = 0; +static int ega_type = 0; static int old_overscan_color = 0; uint8_t egaremap2bpp[256]; @@ -64,15 +64,15 @@ uint8_t egaremap2bpp[256]; /* 3C2 controls default mode on EGA. On VGA, it determines monitor type (mono or colour): 7=CGA mode (200 lines), 9=EGA mode (350 lines), 8=EGA mode (200 lines). */ int egaswitchread; -int egaswitches = 9; +int egaswitches = 9; int update_overscan = 0; -uint8_t ega_in(uint16_t addr, void *p); +uint8_t ega_in(uint16_t addr, void *priv); void -ega_out(uint16_t addr, uint8_t val, void *p) +ega_out(uint16_t addr, uint8_t val, void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; uint8_t o; uint8_t old; @@ -102,6 +102,9 @@ ega_out(uint16_t addr, uint8_t val, void *p) case 0xb3: ati_eeprom_write((ati_eeprom_t *) ega->eeprom, val & 8, val & 2, val & 1); break; + + default: + break; } break; @@ -180,6 +183,9 @@ ega_out(uint16_t addr, uint8_t val, void *p) case 4: ega->chain2_write = !(val & 4); break; + + default: + break; } break; case 0x3ce: @@ -213,11 +219,17 @@ ega_out(uint16_t addr, uint8_t val, void *p) case 0xC: /*32k at B8000*/ mem_mapping_set_addr(&ega->mapping, 0xb8000, 0x08000); break; + + default: + break; } break; case 7: ega->colournocare = val; break; + + default: + break; } break; case 0x3d0: @@ -244,13 +256,16 @@ ega_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } } uint8_t -ega_in(uint16_t addr, void *p) +ega_in(uint16_t addr, void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; uint8_t ret = 0xff; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(ega->miscout & 1)) @@ -267,6 +282,7 @@ ega_in(uint16_t addr, void *p) if (ati_eeprom_read((ati_eeprom_t *) ega->eeprom)) ret |= 8; break; + default: ret = ega->regs[ega->index]; break; @@ -315,7 +331,7 @@ ega_in(uint16_t addr, void *p) break; case 0x3d1: case 0x3d5: - switch(ega->crtcreg) { + switch (ega->crtcreg) { case 0xc: case 0xd: case 0xe: @@ -340,6 +356,9 @@ ega_in(uint16_t addr, void *p) ega->stat ^= 0x30; /*Fools IBM EGA video BIOS self-test*/ ret = ega->stat; break; + + default: + break; } return ret; @@ -435,11 +454,11 @@ 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->render = ega_render_text; ega->hdisp_old = ega->hdisp; } else { ega->hdisp *= (ega->seqregs[1] & 8) ? 16 : 8; - ega->render = ega_render_graphics; + ega->render = ega_render_graphics; ega->hdisp_old = ega->hdisp; } } @@ -481,9 +500,9 @@ ega_recalctimings(ega_t *ega) } void -ega_poll(void *p) +ega_poll(void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; int x; int old_ma; int wx = 640; @@ -779,7 +798,7 @@ ega_remap_cpu_addr(uint32_t inaddr, ega_t *ega) if (ega->gdcreg[6] & 2) { a0mux |= 2; } - if (ega->vram_limit <= 64*1024) { + if (ega->vram_limit <= 64 * 1024) { a0mux |= 1; } @@ -798,6 +817,9 @@ ega_remap_cpu_addr(uint32_t inaddr, ega_t *ega) case 0xC: // 32K B800 addr &= 0x7FFF; break; + + default: + break; } switch (a0mux) { @@ -811,15 +833,18 @@ ega_remap_cpu_addr(uint32_t inaddr, ega_t *ega) // A0 becomes the inversion of PGSEL (reg 0x3C2, miscout, bit 5) // That is, 1 selects the "low" 64k, and 0 selects the "high" 64k. addr &= ~1; - addr |= (~ega->miscout>>5)&1; + addr |= (~ega->miscout >> 5) & 1; break; case 3: // A0 becomes A14 addr &= ~1; - addr |= (inaddr>>14)&1; + addr |= (inaddr >> 14) & 1; break; case 6: // A0 becomes A16 addr &= ~1; - addr |= (inaddr>>16)&1; + addr |= (inaddr >> 16) & 1; + break; + + default: break; } @@ -831,9 +856,9 @@ ega_remap_cpu_addr(uint32_t inaddr, ega_t *ega) } void -ega_write(uint32_t addr, uint8_t val, void *p) +ega_write(uint32_t addr, uint8_t val, void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; uint8_t vala; uint8_t valb; uint8_t valc; @@ -940,6 +965,9 @@ ega_write(uint32_t addr, uint8_t val, void *p) if (writemask2 & 8) ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) ^ ega->ld; break; + + default: + break; } } break; @@ -999,16 +1027,22 @@ ega_write(uint32_t addr, uint8_t val, void *p) if (writemask2 & 8) ega->vram[addr | 0x3] = (vald & ega->gdcreg[8]) ^ ega->ld; break; + + default: + break; } } break; + + default: + break; } } uint8_t -ega_read(uint32_t addr, void *p) +ega_read(uint32_t addr, void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; uint8_t temp; uint8_t temp2; uint8_t temp3; @@ -1111,6 +1145,9 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) case 3: pallook64[c] = pallook16[c] = makecol32(0x34, 0xff, 0x5d); break; + + default: + break; } break; case DISPLAY_AMBER: @@ -1124,6 +1161,9 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) case 3: pallook64[c] = pallook16[c] = makecol32(0xff, 0xe3, 0x34); break; + + default: + break; } break; case DISPLAY_WHITE: @@ -1138,6 +1178,9 @@ ega_init(ega_t *ega, int monitor_type, int is_mono) case 3: pallook64[c] = pallook16[c] = makecol32(0xff, 0xfd, 0xed); break; + + default: + break; } break; } @@ -1201,8 +1244,8 @@ ega_standalone_init(const device_t *info) ega_type = 1; switch (info->local) { - case EGA_IBM: default: + case EGA_IBM: rom_init(&ega->bios_rom, BIOS_IBM_PATH, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); break; @@ -1292,9 +1335,9 @@ et2000_standalone_available(void) } static void -ega_close(void *p) +ega_close(void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; if (ega->eeprom) free(ega->eeprom); @@ -1303,9 +1346,9 @@ ega_close(void *p) } static void -ega_speed_changed(void *p) +ega_speed_changed(void *priv) { - ega_t *ega = (ega_t *) p; + ega_t *ega = (ega_t *) priv; ega_recalctimings(ega); } diff --git a/src/video/vid_ega_render.c b/src/video/vid_ega_render.c index 4b6710891..2d15d6dc5 100644 --- a/src/video/vid_ega_render.c +++ b/src/video/vid_ega_render.c @@ -47,29 +47,30 @@ ega_display_line(ega_t *ega) void ega_render_blank(ega_t *ega) { - int xx; - if ((ega->displine + ega->y_add) < 0) return; for (int x = 0; x < (ega->hdisp + ega->scrollcache); x++) { switch (ega->seqregs[1] & 9) { case 0: - for (xx = 0; xx < 9; xx++) + for (uint8_t xx = 0; xx < 9; xx++) buffer32->line[ega->displine + ega->y_add][ega->x_add + (x * 9) + xx] = 0; break; case 1: - for (xx = 0; xx < 8; xx++) + for (uint8_t xx = 0; xx < 8; xx++) buffer32->line[ega->displine + ega->y_add][ega->x_add + (x * 8) + xx] = 0; break; case 8: - for (xx = 0; xx < 18; xx++) + for (uint8_t xx = 0; xx < 18; xx++) buffer32->line[ega->displine + ega->y_add][ega->x_add + (x * 18) + xx] = 0; break; case 9: - for (xx = 0; xx < 16; xx++) + for (uint8_t xx = 0; xx < 16; xx++) buffer32->line[ega->displine + ega->y_add][ega->x_add + (x * 16) + xx] = 0; break; + + default: + break; } } } @@ -114,16 +115,16 @@ ega_render_text(ega_t *ega) ega->lastline_draw = ega->displine; if (ega->fullchange) { - const bool doublewidth = ((ega->seqregs[1] & 8) != 0); - const bool attrblink = ((ega->attrregs[0x10] & 8) != 0); + const bool doublewidth = ((ega->seqregs[1] & 8) != 0); + const bool attrblink = ((ega->attrregs[0x10] & 8) != 0); const bool attrlinechars = (ega->attrregs[0x10] & 4); - const bool crtcreset = ((ega->crtc[0x17] & 0x80) == 0); - const bool seq9dot = ((ega->seqregs[1] & 1) == 0); - const int dwshift = doublewidth ? 1 : 0; - const int dotwidth = 1 << dwshift; - const int charwidth = dotwidth*(seq9dot ? 9 : 8); - const bool blinked = ega->blink & 0x10; - uint32_t *p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; + const bool crtcreset = ((ega->crtc[0x17] & 0x80) == 0); + const bool seq9dot = ((ega->seqregs[1] & 1) == 0); + const int dwshift = doublewidth ? 1 : 0; + const int dotwidth = 1 << dwshift; + const int charwidth = dotwidth * (seq9dot ? 9 : 8); + const bool blinked = ega->blink & 0x10; + uint32_t *p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; for (int x = 0; x < (ega->hdisp + ega->scrollcache); x += charwidth) { uint32_t addr = ega->remap_func(ega, ega->ma) & ega->vrammask; @@ -166,7 +167,7 @@ ega_render_text(ega_t *ega) dat |= (dat >> 1) & 1; for (int xx = 0; xx < charwidth; xx++) - p[xx] = (dat & (0x100 >> (xx>>dwshift))) ? fg : bg; + p[xx] = (dat & (0x100 >> (xx >> dwshift))) ? fg : bg; ega->ma += 4; p += charwidth; @@ -185,28 +186,28 @@ ega_render_graphics(ega_t *ega) ega->firstline_draw = ega->displine; ega->lastline_draw = ega->displine; - const bool doublewidth = ((ega->seqregs[1] & 8) != 0); - const bool cga2bpp = ((ega->gdcreg[5] & 0x20) != 0); - const bool attrblink = ((ega->attrregs[0x10] & 8) != 0); - const bool blinked = ega->blink & 0x10; - const bool crtcreset = ((ega->crtc[0x17] & 0x80) == 0); - const bool seqoddeven = ((ega->seqregs[1] & 4) != 0); - const uint8_t blinkmask = (attrblink && blinked ? 0x8 : 0x0); - uint32_t *p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; - const int dwshift = doublewidth ? 1 : 0; - const int dotwidth = 1 << dwshift; - const int charwidth = dotwidth*8; - int secondcclk = 0; + const bool doublewidth = ((ega->seqregs[1] & 8) != 0); + const bool cga2bpp = ((ega->gdcreg[5] & 0x20) != 0); + const bool attrblink = ((ega->attrregs[0x10] & 8) != 0); + const bool blinked = ega->blink & 0x10; + const bool crtcreset = ((ega->crtc[0x17] & 0x80) == 0); + const bool seqoddeven = ((ega->seqregs[1] & 4) != 0); + const uint8_t blinkmask = (attrblink && blinked ? 0x8 : 0x0); + uint32_t *p = &buffer32->line[ega->displine + ega->y_add][ega->x_add]; + const int dwshift = doublewidth ? 1 : 0; + const int dotwidth = 1 << dwshift; + const int charwidth = dotwidth * 8; + int secondcclk = 0; for (int x = 0; x <= (ega->hdisp + ega->scrollcache); x += charwidth) { uint32_t addr = ega->remap_func(ega, ega->ma) & ega->vrammask; uint8_t edat[4]; if (seqoddeven) { // FIXME: Verify the behaviour of planes 1,3 on actual hardware - edat[0] = ega->vram[(addr | 0) ^ secondcclk]; - edat[1] = ega->vram[(addr | 1) ^ secondcclk]; - edat[2] = ega->vram[(addr | 2) ^ secondcclk]; - edat[3] = ega->vram[(addr | 3) ^ secondcclk]; + edat[0] = ega->vram[(addr | 0) ^ secondcclk]; + edat[1] = ega->vram[(addr | 1) ^ secondcclk]; + edat[2] = ega->vram[(addr | 2) ^ secondcclk]; + edat[3] = ega->vram[(addr | 3) ^ secondcclk]; secondcclk = (secondcclk + 1) & 1; if (secondcclk == 0) ega->ma += 4; @@ -218,25 +219,25 @@ ega_render_graphics(ega_t *ega) if (cga2bpp) { // Remap CGA 2bpp-chunky data into fully planar data - uint8_t dat0 = egaremap2bpp[edat[1] ] | (egaremap2bpp[edat[0] ] << 4); - uint8_t dat1 = egaremap2bpp[edat[1]>>1] | (egaremap2bpp[edat[0]>>1] << 4); - uint8_t dat2 = egaremap2bpp[edat[3] ] | (egaremap2bpp[edat[2] ] << 4); - uint8_t dat3 = egaremap2bpp[edat[3]>>1] | (egaremap2bpp[edat[2]>>1] << 4); - edat[0] = dat0; - edat[1] = dat1; - edat[2] = dat2; - edat[3] = dat3; + uint8_t dat0 = egaremap2bpp[edat[1]] | (egaremap2bpp[edat[0]] << 4); + uint8_t dat1 = egaremap2bpp[edat[1] >> 1] | (egaremap2bpp[edat[0] >> 1] << 4); + uint8_t dat2 = egaremap2bpp[edat[3]] | (egaremap2bpp[edat[2]] << 4); + uint8_t dat3 = egaremap2bpp[edat[3] >> 1] | (egaremap2bpp[edat[2] >> 1] << 4); + edat[0] = dat0; + edat[1] = dat1; + edat[2] = dat2; + edat[3] = dat3; } if (!crtcreset) { for (int i = 0; i < 8; i += 2) { const int outoffs = i << dwshift; const int inshift = 6 - i; - uint8_t dat = (edatlookup[(edat[0] >> inshift) & 3][(edat[1] >> inshift) & 3] ) - | (edatlookup[(edat[2] >> inshift) & 3][(edat[3] >> inshift) & 3] << 2); + uint8_t dat = (edatlookup[(edat[0] >> inshift) & 3][(edat[1] >> inshift) & 3]) + | (edatlookup[(edat[2] >> inshift) & 3][(edat[3] >> inshift) & 3] << 2); // FIXME: Confirm blink behaviour is actually XOR on real hardware uint32_t p0 = ega->pallook[ega->egapal[((dat >> 4) & ega->plane_mask) ^ blinkmask]]; - uint32_t p1 = ega->pallook[ega->egapal[(dat & ega->plane_mask) ^ blinkmask]]; + uint32_t p1 = ega->pallook[ega->egapal[(dat & ega->plane_mask) ^ blinkmask]]; for (int subx = 0; subx < dotwidth; subx++) p[outoffs + subx] = p0; for (int subx = 0; subx < dotwidth; subx++) diff --git a/src/video/vid_et3000.c b/src/video/vid_et3000.c index 28e3a0f02..e1290cd99 100644 --- a/src/video/vid_et3000.c +++ b/src/video/vid_et3000.c @@ -66,6 +66,9 @@ et3000_in(uint16_t addr, void *priv) case 0x3d5: return svga->crtc[svga->crtcreg]; + + default: + break; } return svga_in(addr, svga); @@ -124,6 +127,9 @@ et3000_out(uint16_t addr, uint8_t val, void *priv) svga->write_bank = (val & 7) << 16; svga->read_bank = ((val >> 3) & 7) << 16; break; + + default: + break; } } return; @@ -147,6 +153,9 @@ et3000_out(uint16_t addr, uint8_t val, void *priv) } } break; + + default: + break; } svga_out(addr, val, svga); @@ -184,11 +193,16 @@ et3000_recalctimings(svga_t *svga) case 0x60: svga->render = svga_render_8bpp_highres; break; + + default: + break; } } - /* pclog("HDISP = %i, HTOTAL = %i, ROWOFFSET = %i, INTERLACE = %i\n", - svga->hdisp, svga->htotal, svga->rowoffset, svga->interlace); */ +#if 0 + pclog("HDISP = %i, HTOTAL = %i, ROWOFFSET = %i, INTERLACE = %i\n", + svga->hdisp, svga->htotal, svga->rowoffset, svga->interlace); +#endif switch (((svga->miscout >> 2) & 3) | ((svga->crtc[0x24] << 1) & 4)) { case 0: @@ -227,6 +241,9 @@ et3000_init(const device_t *info) io_sethandler(0x03c0, 32, et3000_in, NULL, NULL, et3000_out, NULL, NULL, dev); break; + + default: + break; } rom_init(&dev->bios_rom, (char *) fn, diff --git a/src/video/vid_et4000.c b/src/video/vid_et4000.c index b4c505dae..a97d65cdb 100644 --- a/src/video/vid_et4000.c +++ b/src/video/vid_et4000.c @@ -52,6 +52,8 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> #define ET4000_TYPE_ISA 1 /* ISA ET4000AX */ #define ET4000_TYPE_MCA 2 /* MCA ET4000AX */ @@ -105,8 +107,8 @@ static const uint8_t crtc_mask[0x40] = { static video_timings_t timing_et4000_isa = { .type = VIDEO_ISA, .write_b = 3, .write_w = 3, .write_l = 6, .read_b = 5, .read_w = 5, .read_l = 10 }; static video_timings_t timing_et4000_mca = { .type = VIDEO_MCA, .write_b = 4, .write_w = 5, .write_l = 10, .read_b = 5, .read_w = 5, .read_l = 10 }; -static void et4000_kasan_out(uint16_t addr, uint8_t val, void *p); -static uint8_t et4000_kasan_in(uint16_t addr, void *p); +static void et4000_kasan_out(uint16_t addr, uint8_t val, void *priv); +static uint8_t et4000_kasan_in(uint16_t addr, void *priv); static uint8_t et4000_in(uint16_t addr, void *priv) @@ -146,6 +148,9 @@ et4000_in(uint16_t addr, void *priv) case 0x3d5: return svga->crtc[svga->crtcreg]; + + default: + break; } return svga_in(addr, svga); @@ -288,6 +293,9 @@ et4000_out(uint16_t addr, uint8_t val, void *priv) } } break; + + default: + break; } svga_out(addr, val, svga); @@ -425,6 +433,9 @@ et4000_kasan_out(uint16_t addr, uint8_t val, void *priv) case 5: et4000->kasan_cfg_regs[5] = val; et4000->svga.ksc5601_english_font_type = 0x100 | val; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 6: case 7: et4000->svga.ksc5601_udc_area_msb[et4000->kasan_cfg_index - 0xF6] = val; @@ -474,9 +485,9 @@ et4000_kasan_out(uint16_t addr, uint8_t val, void *priv) } uint32_t -get_et4000_addr(uint32_t addr, void *p) +get_et4000_addr(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; uint32_t nbank; switch (svga->crtc[0x37] & 0x0B) { @@ -536,7 +547,7 @@ get_et4000_addr(uint32_t addr, void *p) static void et4000_recalctimings(svga_t *svga) { - et4000_t *dev = (et4000_t *) svga->p; + et4000_t *dev = (et4000_t *) svga->priv; svga->ma_latch |= (svga->crtc[0x33] & 3) << 16; if (svga->crtc[0x35] & 1) @@ -580,6 +591,9 @@ et4000_recalctimings(svga_t *svga) case 24: svga->hdisp /= 3; break; + + default: + break; } if (dev->type == ET4000_TYPE_KOREAN || dev->type == ET4000_TYPE_TRIGEM || dev->type == ET4000_TYPE_KASAN) { @@ -598,7 +612,7 @@ et4000_recalctimings(svga_t *svga) static void et4000_kasan_recalctimings(svga_t *svga) { - et4000_t *et4000 = (et4000_t *) svga->p; + et4000_t *et4000 = (et4000_t *) svga->priv; et4000_recalctimings(svga); @@ -633,7 +647,7 @@ et4000_mca_write(int port, uint8_t val, void *priv) } static uint8_t -et4000_mca_feedb(void *priv) +et4000_mca_feedb(UNUSED(void *priv)) { return 1; } diff --git a/src/video/vid_et4000w32.c b/src/video/vid_et4000w32.c index 4016067ab..c2ce39778 100644 --- a/src/video/vid_et4000w32.c +++ b/src/video/vid_et4000w32.c @@ -130,14 +130,14 @@ static video_timings_t timing_et4000w32_isa = { .type = VIDEO_ISA, .write_b = 4, void et4000w32p_recalcmapping(et4000w32p_t *et4000); -static uint8_t et4000w32p_mmu_read(uint32_t addr, void *p); -static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p); +static uint8_t et4000w32p_mmu_read(uint32_t addr, void *priv); +static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *priv); static void et4000w32_blit_start(et4000w32p_t *et4000); static void et4000w32p_blit_start(et4000w32p_t *et4000); static void et4000w32_blit(int count, int cpu_input, uint32_t src_dat, uint32_t mix_dat, et4000w32p_t *et4000); static void et4000w32p_blit(int count, uint32_t mix, uint32_t sdat, int cpu_input, et4000w32p_t *et4000); -uint8_t et4000w32p_in(uint16_t addr, void *p); +uint8_t et4000w32p_in(uint16_t addr, void *priv); #ifdef ENABLE_ET4000W32_LOG int et4000w32_do_log = ENABLE_ET4000W32_LOG; @@ -158,9 +158,9 @@ et4000w32_log(const char *fmt, ...) #endif void -et4000w32p_out(uint16_t addr, uint8_t val, void *p) +et4000w32p_out(uint16_t addr, uint8_t val, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; uint8_t old; uint32_t add2addr = 0; @@ -321,9 +321,9 @@ et4000w32p_out(uint16_t addr, uint8_t val, void *p) } uint8_t -et4000w32p_in(uint16_t addr, void *p) +et4000w32p_in(uint16_t addr, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -343,7 +343,6 @@ et4000w32p_in(uint16_t addr, void *p) return sdac_ramdac_in(addr, 0, svga->ramdac, svga); else return stg_ramdac_in(addr, svga->ramdac, svga); - break; case 0x3cb: return et4000->banking2; @@ -417,7 +416,7 @@ et4000w32p_in(uint16_t addr, void *p) void et4000w32p_recalctimings(svga_t *svga) { - et4000w32p_t *et4000 = (et4000w32p_t *) svga->p; + et4000w32p_t *et4000 = (et4000w32p_t *) svga->priv; svga->ma_latch |= (svga->crtc[0x33] & 0x7) << 16; if (svga->crtc[0x35] & 0x01) @@ -899,9 +898,9 @@ et4000w32p_accel_write_mmu(et4000w32p_t *et4000, uint32_t addr, uint8_t val, uin } static void -et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p) +et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; switch (addr & 0x6000) { @@ -975,9 +974,9 @@ et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p) } static uint8_t -et4000w32p_mmu_read(uint32_t addr, void *p) +et4000w32p_mmu_read(uint32_t addr, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; uint8_t temp; @@ -1075,7 +1074,6 @@ et4000w32p_mmu_read(uint32_t addr, void *p) return et4000->acl.internal.pixel_depth; else return et4000->acl.internal.vbus; - break; case 0x8f: return et4000->acl.internal.xy_dir; case 0x90: @@ -2084,7 +2082,7 @@ et4000w32_blit(int count, int cpu_input, uint32_t src_dat, uint32_t mix_dat, et4 uint8_t source; uint8_t dest; uint8_t rop; - uint8_t out; + uint8_t out = 0; int mixmap; if (!(et4000->acl.status & ACL_XYST) && !et4000->acl.mmu_start) { @@ -2453,7 +2451,7 @@ et4000w32p_blit(int count, uint32_t mix, uint32_t sdat, int cpu_input, et4000w32 void et4000w32p_hwcursor_draw(svga_t *svga, int displine) { - et4000w32p_t *et4000 = (et4000w32p_t *) svga->p; + et4000w32p_t *et4000 = (et4000w32p_t *) svga->priv; int offset; int xx; int xx2; @@ -2559,9 +2557,9 @@ et4000w32p_io_set(et4000w32p_t *et4000) } uint8_t -et4000w32p_pci_read(int func, int addr, void *p) +et4000w32p_pci_read(UNUSED(int func), int addr, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; addr &= 0xff; @@ -2615,9 +2613,9 @@ et4000w32p_pci_read(int func, int addr, void *p) } void -et4000w32p_pci_write(int func, int addr, uint8_t val, void *p) +et4000w32p_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_t *svga = &et4000->svga; addr &= 0xff; @@ -2873,9 +2871,9 @@ et4000w32p_cardex_available(void) } void -et4000w32p_close(void *p) +et4000w32p_close(void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_close(&et4000->svga); @@ -2883,17 +2881,17 @@ et4000w32p_close(void *p) } void -et4000w32p_speed_changed(void *p) +et4000w32p_speed_changed(void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; svga_recalctimings(&et4000->svga); } void -et4000w32p_force_redraw(void *p) +et4000w32p_force_redraw(void *priv) { - et4000w32p_t *et4000 = (et4000w32p_t *) p; + et4000w32p_t *et4000 = (et4000w32p_t *) priv; et4000->svga.fullchange = changeframecount; } diff --git a/src/video/vid_f82c425.c b/src/video/vid_f82c425.c index d2fd22dce..a2ffeddb5 100644 --- a/src/video/vid_f82c425.c +++ b/src/video/vid_f82c425.c @@ -63,6 +63,7 @@ #include "cpu.h" #include <86box/video.h> #include <86box/vid_cga.h> +#include <86box/plat_unused.h> #define F82C425_XSIZE 640 #define F82C425_YSIZE 200 @@ -226,9 +227,9 @@ f82c425_colormap(f82c425_t *f82c425) } static void -f82c425_out(uint16_t addr, uint8_t val, void *p) +f82c425_out(uint16_t addr, uint8_t val, void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; if (addr == 0x3d4) f82c425->crtcreg = val; @@ -271,9 +272,9 @@ f82c425_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -f82c425_in(uint16_t addr, void *p) +f82c425_in(uint16_t addr, void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; if ((f82c425->function & 0x01) == 0) return 0xff; @@ -305,18 +306,18 @@ f82c425_in(uint16_t addr, void *p) } static void -f82c425_write(uint32_t addr, uint8_t val, void *p) +f82c425_write(uint32_t addr, uint8_t val, void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; f82c425->vram[addr & 0x3fff] = val; cycles -= 4; } static uint8_t -f82c425_read(uint32_t addr, void *p) +f82c425_read(uint32_t addr, void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; cycles -= 4; return f82c425->vram[addr & 0x3fff]; @@ -454,9 +455,9 @@ f82c425_cgaline4(f82c425_t *f82c425) } static void -f82c425_poll(void *p) +f82c425_poll(void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; if (f82c425->video_options != st_video_options || !!(f82c425->function & 1) != st_enabled) { f82c425->video_options = st_video_options; @@ -560,9 +561,10 @@ f82c425_poll(void *p) } static void * -f82c425_init(const device_t *info) +f82c425_init(UNUSED(const device_t *info)) { f82c425_t *f82c425 = malloc(sizeof(f82c425_t)); + memset(f82c425, 0, sizeof(f82c425_t)); cga_init(&f82c425->cga); video_inform(VIDEO_FLAG_TYPE_CGA, &timing_f82c425); @@ -595,18 +597,18 @@ f82c425_init(const device_t *info) } static void -f82c425_close(void *p) +f82c425_close(void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; free(f82c425->vram); free(f82c425); } static void -f82c425_speed_changed(void *p) +f82c425_speed_changed(void *priv) { - f82c425_t *f82c425 = (f82c425_t *) p; + f82c425_t *f82c425 = (f82c425_t *) priv; f82c425_recalctimings(f82c425); } diff --git a/src/video/vid_genius.c b/src/video/vid_genius.c index 09f2f6ada..763cfe540 100644 --- a/src/video/vid_genius.c +++ b/src/video/vid_genius.c @@ -138,13 +138,13 @@ static uint8_t genius_pal[4]; static uint8_t mdaattr[256][2][2]; void genius_recalctimings(genius_t *genius); -void genius_write(uint32_t addr, uint8_t val, void *p); -uint8_t genius_read(uint32_t addr, void *p); +void genius_write(uint32_t addr, uint8_t val, void *priv); +uint8_t genius_read(uint32_t addr, void *priv); void -genius_out(uint16_t addr, uint8_t val, void *p) +genius_out(uint16_t addr, uint8_t val, void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; switch (addr) { case 0x3b0: /* Command / control register */ @@ -208,9 +208,9 @@ genius_out(uint16_t addr, uint8_t val, void *p) } uint8_t -genius_in(uint16_t addr, void *p) +genius_in(uint16_t addr, void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; uint8_t ret = 0xff; switch (addr) { @@ -269,9 +269,9 @@ genius_waitstates(void) } void -genius_write(uint32_t addr, uint8_t val, void *p) +genius_write(uint32_t addr, uint8_t val, void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; genius_waitstates(); if (genius->genius_control & 1) { @@ -293,9 +293,9 @@ genius_write(uint32_t addr, uint8_t val, void *p) } uint8_t -genius_read(uint32_t addr, void *p) +genius_read(uint32_t addr, void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; uint8_t ret; genius_waitstates(); @@ -623,9 +623,9 @@ genius_hiresline(genius_t *genius) } void -genius_poll(void *p) +genius_poll(void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; uint8_t background; if (!genius->linepos) { @@ -784,9 +784,9 @@ void } void -genius_close(void *p) +genius_close(void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; free(genius->vram); free(genius); @@ -799,9 +799,9 @@ genius_available(void) } void -genius_speed_changed(void *p) +genius_speed_changed(void *priv) { - genius_t *genius = (genius_t *) p; + genius_t *genius = (genius_t *) priv; genius_recalctimings(genius); } diff --git a/src/video/vid_hercules.c b/src/video/vid_hercules.c index f3ce178cd..e2879cec3 100644 --- a/src/video/vid_hercules.c +++ b/src/video/vid_hercules.c @@ -32,6 +32,7 @@ #include <86box/device.h> #include <86box/video.h> #include <86box/vid_hercules.h> +#include <86box/plat_unused.h> static video_timings_t timing_hercules = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; @@ -192,7 +193,7 @@ hercules_in(uint16_t addr, void *priv) } static void -hercules_waitstates(void *p) +hercules_waitstates(UNUSED(void *priv)) { int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; int ws; @@ -493,7 +494,9 @@ hercules_poll(void *priv) else video_blit_memtoscreen(8, dev->firstline + 14, xsize, ysize); frames++; - // if ((dev->ctrl & 2) && (dev->ctrl2 & 1)) { +#if 0 + if ((dev->ctrl & 2) && (dev->ctrl2 & 1)) { +#endif if (dev->ctrl & 0x02) { video_res_x = dev->crtc[1] * 16; video_res_y = dev->crtc[6] * 4; @@ -527,7 +530,7 @@ hercules_poll(void *priv) } static void * -hercules_init(const device_t *info) +hercules_init(UNUSED(const device_t *info)) { hercules_t *dev; diff --git a/src/video/vid_herculesplus.c b/src/video/vid_herculesplus.c index a5422fbc1..587410c07 100644 --- a/src/video/vid_herculesplus.c +++ b/src/video/vid_herculesplus.c @@ -30,6 +30,7 @@ #include <86box/rom.h> #include <86box/device.h> #include <86box/video.h> +#include <86box/plat_unused.h> /* extended CRTC registers */ #define HERCULESPLUS_CRTC_XMODE 20 /* xMode register */ @@ -162,6 +163,9 @@ herculesplus_out(uint16_t port, uint8_t val, void *priv) else mem_mapping_set_addr(&dev->mapping, 0xb0000, 0x08000); return; + + default: + break; } } @@ -191,6 +195,9 @@ herculesplus_in(uint16_t port, void *priv) /* 0x10: Hercules Plus card identity */ ret = (dev->stat & 0xf) | ((dev->stat & 8) << 4) | 0x10; break; + + default: + break; } return ret; @@ -458,6 +465,9 @@ text_line(herculesplus_t *dev, uint16_t ca) case 5: /* 48k RAMfont */ draw_char_ram48(dev, x, chr, attr); break; + + default: + break; } ++dev->ma; @@ -641,7 +651,7 @@ herculesplus_poll(void *priv) } static void * -herculesplus_init(const device_t *info) +herculesplus_init(UNUSED(const device_t *info)) { herculesplus_t *dev; diff --git a/src/video/vid_ht216.c b/src/video/vid_ht216.c index 6b99975d5..bd09a9ede 100644 --- a/src/video/vid_ht216.c +++ b/src/video/vid_ht216.c @@ -35,6 +35,8 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/plat_fallthrough.h> +#include <86box/plat_unused.h> typedef struct ht216_t { svga_t svga; @@ -92,8 +94,8 @@ typedef struct ht216_t { void ht216_remap(ht216_t *ht216); -void ht216_out(uint16_t addr, uint8_t val, void *p); -uint8_t ht216_in(uint16_t addr, void *p); +void ht216_out(uint16_t addr, uint8_t val, void *priv); +uint8_t ht216_in(uint16_t addr, void *priv); #define BIOS_G2_GC205_PATH "roms/video/video7/BIOS.BIN" #define BIOS_VIDEO7_VGA_1024I_PATH "roms/video/video7/Video Seven VGA 1024i - BIOS - v2.19 - 435-0062-05 - U17 - 27C256.BIN" @@ -164,9 +166,9 @@ ht216_recalc_bank_regs(ht216_t *ht216, int mode) } void -ht216_out(uint16_t addr, uint8_t val, void *p) +ht216_out(uint16_t addr, uint8_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint8_t old; @@ -319,7 +321,9 @@ ht216_out(uint16_t addr, uint8_t val, void *p) svga->adv_flags &= ~FLAG_RAMDAC_SHIFT; if (val & 0x04) svga->adv_flags |= FLAG_RAMDAC_SHIFT; - /* FALLTHROUGH */ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif /*Bank registers*/ case 0xe8: case 0xe9: @@ -463,9 +467,9 @@ ht216_out(uint16_t addr, uint8_t val, void *p) } uint8_t -ht216_in(uint16_t addr, void *p) +ht216_in(uint16_t addr, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint8_t ret = 0xff; @@ -606,7 +610,7 @@ ht216_remap(ht216_t *ht216) void ht216_recalctimings(svga_t *svga) { - ht216_t *ht216 = (ht216_t *) svga->p; + ht216_t *ht216 = (ht216_t *) svga->priv; int high_res_256 = 0; switch ((((((svga->miscout >> 2) & 3) || ((ht216->ht_regs[0xa4] >> 2) & 3)) | ((ht216->ht_regs[0xa4] >> 2) & 4)) || ((ht216->ht_regs[0xf8] >> 5) & 0x0f)) | ((ht216->ht_regs[0xf8] << 1) & 8)) { @@ -702,7 +706,7 @@ ht216_recalctimings(svga_t *svga) static void ht216_hwcursor_draw(svga_t *svga, int displine) { - ht216_t *ht216 = (ht216_t *) svga->p; + ht216_t *ht216 = (ht216_t *) svga->priv; int shift = (ht216->adjust_cursor ? 2 : 1); uint32_t dat[2]; int offset = svga->hwcursor_latch.x + svga->hwcursor_latch.xoff; @@ -1164,9 +1168,9 @@ ht216_write_common(ht216_t *ht216, uint32_t addr, uint8_t val) } static void -ht216_write(uint32_t addr, uint8_t val, void *p) +ht216_write(uint32_t addr, uint8_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint32_t prev_addr = addr; @@ -1185,9 +1189,9 @@ ht216_write(uint32_t addr, uint8_t val, void *p) } static void -ht216_writew(uint32_t addr, uint16_t val, void *p) +ht216_writew(uint32_t addr, uint16_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint32_t prev_addr = addr; @@ -1208,9 +1212,9 @@ ht216_writew(uint32_t addr, uint16_t val, void *p) } static void -ht216_writel(uint32_t addr, uint32_t val, void *p) +ht216_writel(uint32_t addr, uint32_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint32_t prev_addr = addr; @@ -1233,9 +1237,9 @@ ht216_writel(uint32_t addr, uint32_t val, void *p) } static void -ht216_write_linear(uint32_t addr, uint8_t val, void *p) +ht216_write_linear(uint32_t addr, uint8_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; addr -= ht216->linear_base; @@ -1250,9 +1254,9 @@ ht216_write_linear(uint32_t addr, uint8_t val, void *p) } static void -ht216_writew_linear(uint32_t addr, uint16_t val, void *p) +ht216_writew_linear(uint32_t addr, uint16_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; addr -= ht216->linear_base; @@ -1269,9 +1273,9 @@ ht216_writew_linear(uint32_t addr, uint16_t val, void *p) } static void -ht216_writel_linear(uint32_t addr, uint32_t val, void *p) +ht216_writel_linear(uint32_t addr, uint32_t val, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; addr -= ht216->linear_base; @@ -1372,9 +1376,9 @@ ht216_read_common(ht216_t *ht216, uint32_t addr) } static uint8_t -ht216_read(uint32_t addr, void *p) +ht216_read(uint32_t addr, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; uint32_t prev_addr = addr; @@ -1390,9 +1394,9 @@ ht216_read(uint32_t addr, void *p) } static uint8_t -ht216_read_linear(uint32_t addr, void *p) +ht216_read_linear(uint32_t addr, void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_t *svga = &ht216->svga; addr -= ht216->linear_base; @@ -1427,7 +1431,7 @@ radius_mca_write(int port, uint8_t val, void *priv) } static uint8_t -radius_mca_feedb(void *priv) +radius_mca_feedb(UNUSED(void *priv)) { return 1; } @@ -1611,9 +1615,9 @@ radius_svga_multiview_available(void) } void -ht216_close(void *p) +ht216_close(void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_close(&ht216->svga); @@ -1621,17 +1625,17 @@ ht216_close(void *p) } void -ht216_speed_changed(void *p) +ht216_speed_changed(void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; svga_recalctimings(&ht216->svga); } void -ht216_force_redraw(void *p) +ht216_force_redraw(void *priv) { - ht216_t *ht216 = (ht216_t *) p; + ht216_t *ht216 = (ht216_t *) priv; ht216->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ibm_rgb528_ramdac.c b/src/video/vid_ibm_rgb528_ramdac.c index 339cf6700..b7a27781b 100644 --- a/src/video/vid_ibm_rgb528_ramdac.c +++ b/src/video/vid_ibm_rgb528_ramdac.c @@ -25,6 +25,7 @@ #include <86box/timer.h> #include <86box/video.h> #include <86box/vid_svga.h> +#include <86box/plat_unused.h> typedef union { uint8_t pixel; @@ -913,7 +914,7 @@ ibm_rgb528_hwcursor_draw(svga_t *svga, int displine) } void * -ibm_rgb528_ramdac_init(const device_t *info) +ibm_rgb528_ramdac_init(UNUSED(const device_t *info)) { ibm_rgb528_ramdac_t *ramdac = (ibm_rgb528_ramdac_t *) malloc(sizeof(ibm_rgb528_ramdac_t)); memset(ramdac, 0, sizeof(ibm_rgb528_ramdac_t)); diff --git a/src/video/vid_icd2061.c b/src/video/vid_icd2061.c index 57dcdce38..adfaf6ad4 100644 --- a/src/video/vid_icd2061.c +++ b/src/video/vid_icd2061.c @@ -29,6 +29,7 @@ #define HAVE_STDARG_H #include <86box/86box.h> #include <86box/device.h> +#include <86box/plat_unused.h> typedef struct icd2061_t { float freq[3]; @@ -135,9 +136,9 @@ icd2061_write(void *p, int val) } float -icd2061_getclock(int clock, void *p) +icd2061_getclock(int clock, void *priv) { - icd2061_t *icd2061 = (icd2061_t *) p; + icd2061_t *icd2061 = (icd2061_t *) priv; if (clock > 2) clock = 2; @@ -146,7 +147,7 @@ icd2061_getclock(int clock, void *p) } static void * -icd2061_init(const device_t *info) +icd2061_init(UNUSED(const device_t *info)) { icd2061_t *icd2061 = (icd2061_t *) malloc(sizeof(icd2061_t)); memset(icd2061, 0, sizeof(icd2061_t)); diff --git a/src/video/vid_ics2494.c b/src/video/vid_ics2494.c index 99a877a75..16c4139fe 100644 --- a/src/video/vid_ics2494.c +++ b/src/video/vid_ics2494.c @@ -49,9 +49,9 @@ ics2494_log(const char *fmt, ...) #endif float -ics2494_getclock(int clock, void *p) +ics2494_getclock(int clock, void *priv) { - ics2494_t *ics2494 = (ics2494_t *) p; + ics2494_t *ics2494 = (ics2494_t *) priv; if (clock > 15) clock = 15; diff --git a/src/video/vid_ics2595.c b/src/video/vid_ics2595.c index 520bcda43..6420ee7e4 100644 --- a/src/video/vid_ics2595.c +++ b/src/video/vid_ics2595.c @@ -23,6 +23,7 @@ #include #include <86box/86box.h> #include <86box/device.h> +#include <86box/plat_unused.h> typedef struct ics2595_t { int oldfs3, oldfs2; @@ -70,6 +71,9 @@ ics2595_write(void *p, int strobe, int dat) ics2595->state = ICS2595_IDLE; } break; + + default: + break; } } @@ -81,7 +85,7 @@ ics2595_write(void *p, int strobe, int dat) } static void * -ics2595_init(const device_t *info) +ics2595_init(UNUSED(const device_t *info)) { ics2595_t *ics2595 = (ics2595_t *) malloc(sizeof(ics2595_t)); memset(ics2595, 0, sizeof(ics2595_t)); @@ -99,9 +103,9 @@ ics2595_close(void *priv) } double -ics2595_getclock(void *p) +ics2595_getclock(void *priv) { - ics2595_t *ics2595 = (ics2595_t *) p; + ics2595_t *ics2595 = (ics2595_t *) priv; return ics2595->output_clock; } diff --git a/src/video/vid_im1024.c b/src/video/vid_im1024.c index cb3999be4..25ba92e9c 100644 --- a/src/video/vid_im1024.c +++ b/src/video/vid_im1024.c @@ -635,7 +635,7 @@ hndl_poly(pgc_t *pgc) } static int -parse_poly(pgc_t *pgc, pgc_cl_t *cl, int c) +parse_poly(pgc_t *pgc, pgc_cl_t *cl, UNUSED(int c)) { uint8_t count; @@ -1031,7 +1031,7 @@ static const pgc_cmd_t im1024_commands[] = { }; static void * -im1024_init(const device_t *info) +im1024_init(UNUSED(const device_t *info)) { im1024_t *dev; diff --git a/src/video/vid_incolor.c b/src/video/vid_incolor.c index 6e8054aaa..7a3b416fc 100644 --- a/src/video/vid_incolor.c +++ b/src/video/vid_incolor.c @@ -30,6 +30,7 @@ #include <86box/rom.h> #include <86box/device.h> #include <86box/video.h> +#include <86box/plat_unused.h> /* extended CRTC registers */ #define INCOLOR_CRTC_XMODE 20 /* xMode register */ @@ -972,7 +973,7 @@ incolor_poll(void *priv) } static void * -incolor_init(const device_t *info) +incolor_init(UNUSED(const device_t *info)) { incolor_t *dev; int c; diff --git a/src/video/vid_mda.c b/src/video/vid_mda.c index 44f91ec95..f743885c5 100644 --- a/src/video/vid_mda.c +++ b/src/video/vid_mda.c @@ -31,6 +31,7 @@ #include <86box/device.h> #include <86box/video.h> #include <86box/vid_mda.h> +#include <86box/plat_unused.h> static int mdacols[256][2][2]; @@ -39,9 +40,10 @@ static video_timings_t timing_mda = { .type = VIDEO_ISA, .write_b = 8, .write_w void mda_recalctimings(mda_t *mda); void -mda_out(uint16_t addr, uint8_t val, void *p) +mda_out(uint16_t addr, uint8_t val, void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; + switch (addr) { case 0x3b0: case 0x3b2: @@ -64,13 +66,17 @@ mda_out(uint16_t addr, uint8_t val, void *p) case 0x3b8: mda->ctrl = val; return; + + default: + break; } } uint8_t -mda_in(uint16_t addr, void *p) +mda_in(uint16_t addr, void *priv) { - mda_t *mda = (mda_t *) p; + const mda_t *mda = (mda_t *) priv; + switch (addr) { case 0x3b0: case 0x3b2: @@ -84,21 +90,25 @@ mda_in(uint16_t addr, void *p) return mda->crtc[mda->crtcreg]; case 0x3ba: return mda->stat | 0xF0; + + default: + break; } return 0xff; } void -mda_write(uint32_t addr, uint8_t val, void *p) +mda_write(uint32_t addr, uint8_t val, void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; mda->vram[addr & 0xfff] = val; } uint8_t -mda_read(uint32_t addr, void *p) +mda_read(uint32_t addr, void *priv) { - mda_t *mda = (mda_t *) p; + const mda_t *mda = (mda_t *) priv; + return mda->vram[addr & 0xfff]; } @@ -118,9 +128,9 @@ mda_recalctimings(mda_t *mda) } void -mda_poll(void *p) +mda_poll(void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; uint16_t ca = (mda->crtc[15] | (mda->crtc[14] << 8)) & 0x3fff; int drawcursor; int x; @@ -299,7 +309,7 @@ mda_init(mda_t *mda) } void * -mda_standalone_init(const device_t *info) +mda_standalone_init(UNUSED(const device_t *info)) { mda_t *mda = malloc(sizeof(mda_t)); memset(mda, 0, sizeof(mda_t)); @@ -324,18 +334,18 @@ mda_setcol(int chr, int blink, int fg, uint8_t cga_ink) } void -mda_close(void *p) +mda_close(void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; free(mda->vram); free(mda); } void -mda_speed_changed(void *p) +mda_speed_changed(void *priv) { - mda_t *mda = (mda_t *) p; + mda_t *mda = (mda_t *) priv; mda_recalctimings(mda); } diff --git a/src/video/vid_mga.c b/src/video/vid_mga.c index 677531c29..67f8d5751 100644 --- a/src/video/vid_mga.c +++ b/src/video/vid_mga.c @@ -633,28 +633,28 @@ static void wake_fifo_thread(mystique_t *mystique); static void wait_fifo_idle(mystique_t *mystique); static void mystique_queue(mystique_t *mystique, uint32_t addr, uint32_t val, uint32_t type); -static uint8_t mystique_readb_linear(uint32_t addr, void *p); -static uint16_t mystique_readw_linear(uint32_t addr, void *p); -static uint32_t mystique_readl_linear(uint32_t addr, void *p); -static void mystique_writeb_linear(uint32_t addr, uint8_t val, void *p); -static void mystique_writew_linear(uint32_t addr, uint16_t val, void *p); -static void mystique_writel_linear(uint32_t addr, uint32_t val, void *p); +static uint8_t mystique_readb_linear(uint32_t addr, void *priv); +static uint16_t mystique_readw_linear(uint32_t addr, void *priv); +static uint32_t mystique_readl_linear(uint32_t addr, void *priv); +static void mystique_writeb_linear(uint32_t addr, uint8_t val, void *priv); +static void mystique_writew_linear(uint32_t addr, uint16_t val, void *priv); +static void mystique_writel_linear(uint32_t addr, uint32_t val, void *priv); static void mystique_recalc_mapping(mystique_t *mystique); static int mystique_line_compare(svga_t *svga); -static uint8_t mystique_iload_read_b(uint32_t addr, void *p); -static uint32_t mystique_iload_read_l(uint32_t addr, void *p); -static void mystique_iload_write_b(uint32_t addr, uint8_t val, void *p); -static void mystique_iload_write_l(uint32_t addr, uint32_t val, void *p); +static uint8_t mystique_iload_read_b(uint32_t addr, void *priv); +static uint32_t mystique_iload_read_l(uint32_t addr, void *priv); +static void mystique_iload_write_b(uint32_t addr, uint8_t val, void *priv); +static void mystique_iload_write_l(uint32_t addr, uint32_t val, void *priv); static uint32_t blit_idump_read(mystique_t *mystique); static void blit_iload_write(mystique_t *mystique, uint32_t data, int size); void -mystique_out(uint16_t addr, uint8_t val, void *p) +mystique_out(uint16_t addr, uint8_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_t *svga = &mystique->svga; uint8_t old; @@ -664,6 +664,9 @@ mystique_out(uint16_t addr, uint8_t val, void *p) switch (addr) { case 0x3c8: mystique->xreg_idx = val; +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 0x3c6: case 0x3c7: case 0x3c9: @@ -746,9 +749,9 @@ mystique_out(uint16_t addr, uint8_t val, void *p) } uint8_t -mystique_in(uint16_t addr, void *p) +mystique_in(uint16_t addr, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_t *svga = &mystique->svga; uint8_t temp = 0xff; @@ -803,7 +806,7 @@ mystique_in(uint16_t addr, void *p) static int mystique_line_compare(svga_t *svga) { - mystique_t *mystique = (mystique_t *) svga->p; + mystique_t *mystique = (mystique_t *) svga->priv; mystique->status |= STATUS_VLINEPEN; mystique_update_irqs(mystique); @@ -814,7 +817,7 @@ mystique_line_compare(svga_t *svga) static void mystique_vsync_callback(svga_t *svga) { - mystique_t *mystique = (mystique_t *) svga->p; + mystique_t *mystique = (mystique_t *) svga->priv; if (svga->crtc[0x11] & 0x10) { mystique->status |= STATUS_VSYNCPEN; @@ -823,9 +826,9 @@ mystique_vsync_callback(svga_t *svga) } static float -mystique_getclock(int clock, void *p) +mystique_getclock(int clock, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; if (clock == 0) return 25175000.0; @@ -845,7 +848,7 @@ mystique_getclock(int clock, void *p) void mystique_recalctimings(svga_t *svga) { - mystique_t *mystique = (mystique_t *) svga->p; + mystique_t *mystique = (mystique_t *) svga->priv; int clk_sel = (svga->miscout >> 2) & 3; svga->clock = (cpuclock * (float) (1ULL << 32)) / svga->getclock(clk_sel & 3, svga->clock_gen); @@ -1361,9 +1364,9 @@ mystique_write_xreg(mystique_t *mystique, int reg, uint8_t val) } static uint8_t -mystique_ctrl_read_b(uint32_t addr, void *p) +mystique_ctrl_read_b(uint32_t addr, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_t *svga = &mystique->svga; uint8_t ret = 0xff; int fifocount; @@ -1586,9 +1589,9 @@ mystique_ctrl_read_b(uint32_t addr, void *p) } static void -mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *p) +mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; int start_blit = 0; if ((addr & 0x300) == 0x100) { @@ -1705,7 +1708,9 @@ mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *p) case REG_YDSTLEN: case REG_YDSTLEN + 1: WRITE8(addr, mystique->dwgreg.length, val); - /* pclog("Write YDSTLEN+%i %i\n", addr&1, mystique->dwgreg.length); */ +#if 0 + pclog("Write YDSTLEN+%i %i\n", addr&1, mystique->dwgreg.length); +#endif break; case REG_YDSTLEN + 2: mystique->dwgreg.ydst = (mystique->dwgreg.ydst & ~0xff) | val; @@ -1924,9 +1929,9 @@ mystique_accel_ctrl_write_b(uint32_t addr, uint8_t val, void *p) } static void -mystique_ctrl_write_b(uint32_t addr, uint8_t val, void *p) +mystique_ctrl_write_b(uint32_t addr, uint8_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_t *svga = &mystique->svga; uint16_t addr_0x0f = 0; uint16_t addr_0x03 = 0; @@ -1962,7 +1967,7 @@ mystique_ctrl_write_b(uint32_t addr, uint8_t val, void *p) } if ((addr & 0x3fff) < 0x1c00) { - mystique_iload_write_b(addr, val, p); + mystique_iload_write_b(addr, val, priv); return; } if ((addr & 0x3e00) == 0x1c00 || (addr & 0x3e00) == 0x2c00) { @@ -2144,25 +2149,25 @@ mystique_ctrl_write_b(uint32_t addr, uint8_t val, void *p) } static uint32_t -mystique_ctrl_read_l(uint32_t addr, void *p) +mystique_ctrl_read_l(uint32_t addr, void *priv) { uint32_t ret; if ((addr & 0x3fff) < 0x1c00) - return mystique_iload_read_l(addr, p); + return mystique_iload_read_l(addr, priv); - ret = mystique_ctrl_read_b(addr, p); - ret |= mystique_ctrl_read_b(addr + 1, p) << 8; - ret |= mystique_ctrl_read_b(addr + 2, p) << 16; - ret |= mystique_ctrl_read_b(addr + 3, p) << 24; + ret = mystique_ctrl_read_b(addr, priv); + ret |= mystique_ctrl_read_b(addr + 1, priv) << 8; + ret |= mystique_ctrl_read_b(addr + 2, priv) << 16; + ret |= mystique_ctrl_read_b(addr + 3, priv) << 24; return ret; } static void -mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) +mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; int start_blit = 0; if ((addr & 0x300) == 0x100) { @@ -2256,7 +2261,9 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) mystique->dwgreg.pattern[y][x] = val & (1 << (x + (y * 16))); } } - // pclog("SRC0 = 0x%08X\n", val); +#if 0 + pclog("SRC0 = 0x%08X\n", val); +#endif if (mystique->busy && (mystique->dwgreg.dwgctrl_running & DWGCTRL_OPCODE_MASK) == DWGCTRL_OPCODE_ILOAD) blit_iload_write(mystique, mystique->dwgreg.src[0], 32); } @@ -2379,10 +2386,10 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) break; default: - mystique_accel_ctrl_write_b(addr, val & 0xff, p); - mystique_accel_ctrl_write_b(addr + 1, (val >> 8) & 0xff, p); - mystique_accel_ctrl_write_b(addr + 2, (val >> 16) & 0xff, p); - mystique_accel_ctrl_write_b(addr + 3, (val >> 24) & 0xff, p); + mystique_accel_ctrl_write_b(addr, val & 0xff, priv); + mystique_accel_ctrl_write_b(addr + 1, (val >> 8) & 0xff, priv); + mystique_accel_ctrl_write_b(addr + 2, (val >> 16) & 0xff, priv); + mystique_accel_ctrl_write_b(addr + 3, (val >> 24) & 0xff, priv); break; } @@ -2391,13 +2398,13 @@ mystique_accel_ctrl_write_l(uint32_t addr, uint32_t val, void *p) } static void -mystique_ctrl_write_l(uint32_t addr, uint32_t val, void *p) +mystique_ctrl_write_l(uint32_t addr, uint32_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; uint32_t reg_addr; if ((addr & 0x3fff) < 0x1c00) { - mystique_iload_write_l(addr, val, p); + mystique_iload_write_l(addr, val, priv); return; } @@ -2452,18 +2459,18 @@ mystique_ctrl_write_l(uint32_t addr, uint32_t val, void *p) break; default: - mystique_ctrl_write_b(addr, val & 0xff, p); - mystique_ctrl_write_b(addr + 1, (val >> 8) & 0xff, p); - mystique_ctrl_write_b(addr + 2, (val >> 16) & 0xff, p); - mystique_ctrl_write_b(addr + 3, (val >> 24) & 0xff, p); + mystique_ctrl_write_b(addr, val & 0xff, priv); + mystique_ctrl_write_b(addr + 1, (val >> 8) & 0xff, priv); + mystique_ctrl_write_b(addr + 2, (val >> 16) & 0xff, priv); + mystique_ctrl_write_b(addr + 3, (val >> 24) & 0xff, priv); break; } } static uint8_t -mystique_iload_read_b(uint32_t addr, void *p) +mystique_iload_read_b(UNUSED(uint32_t addr), void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; wait_fifo_idle(mystique); @@ -2474,9 +2481,9 @@ mystique_iload_read_b(uint32_t addr, void *p) } static uint32_t -mystique_iload_read_l(uint32_t addr, void *p) +mystique_iload_read_l(UNUSED(uint32_t addr), void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; wait_fifo_idle(mystique); @@ -2488,22 +2495,23 @@ mystique_iload_read_l(uint32_t addr, void *p) } static void -mystique_iload_write_b(uint32_t addr, uint8_t val, void *p) +mystique_iload_write_b(UNUSED(uint32_t addr), UNUSED(uint8_t val), UNUSED(void *priv)) { + // } static void -mystique_iload_write_l(uint32_t addr, uint32_t val, void *p) +mystique_iload_write_l(UNUSED(uint32_t addr), uint32_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; mystique_queue(mystique, 0, val, FIFO_WRITE_ILOAD_LONG); } static void -mystique_accel_iload_write_l(uint32_t addr, uint32_t val, void *p) +mystique_accel_iload_write_l(UNUSED(uint32_t addr), uint32_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; switch (mystique->dwgreg.dmamod) { case DMA_MODE_REG: @@ -2531,15 +2539,18 @@ mystique_accel_iload_write_l(uint32_t addr, uint32_t val, void *p) blit_iload_write(mystique, val, 32); break; - /* default: - pclog("ILOAD write DMAMOD %i\n", mystique->dwgreg.dmamod); */ + default: +#if 0 + pclog("ILOAD write DMAMOD %i\n", mystique->dwgreg.dmamod); */ +#endif + break; } } static uint8_t -mystique_readb_linear(uint32_t addr, void *p) +mystique_readb_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_read_b; @@ -2551,9 +2562,9 @@ mystique_readb_linear(uint32_t addr, void *p) } static uint16_t -mystique_readw_linear(uint32_t addr, void *p) +mystique_readw_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_read_w; @@ -2565,9 +2576,9 @@ mystique_readw_linear(uint32_t addr, void *p) } static uint32_t -mystique_readl_linear(uint32_t addr, void *p) +mystique_readl_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_read_l; @@ -2579,9 +2590,9 @@ mystique_readl_linear(uint32_t addr, void *p) } static void -mystique_writeb_linear(uint32_t addr, uint8_t val, void *p) +mystique_writeb_linear(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_write_b; @@ -2594,9 +2605,9 @@ mystique_writeb_linear(uint32_t addr, uint8_t val, void *p) } static void -mystique_writew_linear(uint32_t addr, uint16_t val, void *p) +mystique_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_write_w; @@ -2609,9 +2620,9 @@ mystique_writew_linear(uint32_t addr, uint16_t val, void *p) } static void -mystique_writel_linear(uint32_t addr, uint32_t val, void *p) +mystique_writel_linear(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; cycles -= video_timing_write_l; @@ -2751,9 +2762,9 @@ run_dma(mystique_t *mystique) } static void -fifo_thread(void *p) +fifo_thread(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; while (mystique->thread_run) { thread_set_event(mystique->fifo_not_full_event); @@ -2815,9 +2826,9 @@ wake_fifo_thread_now(mystique_t *mystique) } static void -mystique_wake_timer(void *p) +mystique_wake_timer(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; thread_set_event(mystique->wake_fifo_thread); /*Wake up FIFO thread if moving from idle*/ } @@ -2837,9 +2848,9 @@ wait_fifo_idle(mystique_t *mystique) SOFTRAP IRQs and code reading the status register. Croc will get into an IRQ loop and triple fault if the ENDPRDMASTS flag is seen before the IRQ is taken*/ static void -mystique_softrap_pending_timer(void *p) +mystique_softrap_pending_timer(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; timer_advance_u64(&mystique->softrap_pending_timer, TIMER_USEC * 100); @@ -3268,6 +3279,9 @@ blit_iload_iload(mystique_t *mystique, uint32_t data, int size) case MACCESS_PWIDTH_32: min_size = 32; break; + + default: + break; } while (size >= min_size) { @@ -5148,7 +5162,7 @@ mystique_start_blit(mystique_t *mystique) static void mystique_hwcursor_draw(svga_t *svga, int displine) { - mystique_t *mystique = (mystique_t *) svga->p; + mystique_t *mystique = (mystique_t *) svga->priv; uint64_t dat[2]; int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; @@ -5178,9 +5192,9 @@ mystique_hwcursor_draw(svga_t *svga, int displine) } static uint8_t -mystique_pci_read(int func, int addr, void *p) +mystique_pci_read(UNUSED(int func), int addr, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; uint8_t ret = 0x00; if ((addr >= 0x30) && (addr <= 0x33) && !(mystique->pci_regs[0x43] & 0x40)) @@ -5328,9 +5342,9 @@ mystique_pci_read(int func, int addr, void *p) } static void -mystique_pci_write(int func, int addr, uint8_t val, void *p) +mystique_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; switch (addr) { case PCI_REG_COMMAND: @@ -5569,9 +5583,9 @@ mystique_init(const device_t *info) } static void -mystique_close(void *p) +mystique_close(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; mystique->thread_run = 0; thread_set_event(mystique->wake_fifo_thread); @@ -5608,17 +5622,17 @@ mystique_220_available(void) } static void -mystique_speed_changed(void *p) +mystique_speed_changed(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; svga_recalctimings(&mystique->svga); } static void -mystique_force_redraw(void *p) +mystique_force_redraw(void *priv) { - mystique_t *mystique = (mystique_t *) p; + mystique_t *mystique = (mystique_t *) priv; mystique->svga.fullchange = changeframecount; } diff --git a/src/video/vid_nga.c b/src/video/vid_nga.c index 2d673393b..32c103a8b 100644 --- a/src/video/vid_nga.c +++ b/src/video/vid_nga.c @@ -38,6 +38,7 @@ #include <86box/vid_cga.h> #include <86box/vid_nga.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> #define CGA_RGB 0 #define CGA_COMPOSITE 1 @@ -86,7 +87,7 @@ nga_in(uint16_t addr, void *priv) } void -nga_waitstates(void *p) +nga_waitstates(UNUSED(void *priv)) { int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; int ws; @@ -553,7 +554,7 @@ nga_speed_changed(void *priv) } void * -nga_init(const device_t *info) +nga_init(UNUSED(const device_t *info)) { int mem; uint8_t charset; diff --git a/src/video/vid_oak_oti.c b/src/video/vid_oak_oti.c index 4a3b22934..932e13913 100644 --- a/src/video/vid_oak_oti.c +++ b/src/video/vid_oak_oti.c @@ -29,6 +29,7 @@ #include <86box/video.h> #include <86box/vid_svga.h> #include <86box/vid_svga_render.h> +#include <86box/plat_unused.h> #define BIOS_037C_PATH "roms/video/oti/bios.bin" #define BIOS_067_AMA932J_PATH "roms/machines/ama932j/OTI067.BIN" @@ -64,9 +65,9 @@ typedef struct { static video_timings_t timing_oti = { .type = VIDEO_ISA, .write_b = 6, .write_w = 8, .write_l = 16, .read_b = 6, .read_w = 8, .read_l = 16 }; static void -oti_out(uint16_t addr, uint8_t val, void *p) +oti_out(uint16_t addr, uint8_t val, void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; svga_t *svga = &oti->svga; uint8_t old; uint8_t idx; @@ -85,7 +86,6 @@ oti_out(uint16_t addr, uint8_t val, void *p) return; } else break; - break; case 0x3c6: case 0x3c7: @@ -199,9 +199,9 @@ oti_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -oti_in(uint16_t addr, void *p) +oti_in(uint16_t addr, void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; svga_t *svga = &oti->svga; uint8_t idx; uint8_t temp; @@ -319,9 +319,9 @@ oti_in(uint16_t addr, void *p) } static void -oti_pos_out(uint16_t addr, uint8_t val, void *p) +oti_pos_out(UNUSED(uint16_t addr), uint8_t val, void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; if ((val ^ oti->pos) & 8) { if (val & 8) @@ -336,9 +336,9 @@ oti_pos_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -oti_pos_in(uint16_t addr, void *p) +oti_pos_in(UNUSED(uint16_t addr), void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; return (oti->pos); } @@ -373,7 +373,7 @@ oti_getclock(int clock) static void oti_recalctimings(svga_t *svga) { - oti_t *oti = (oti_t *) svga->p; + oti_t *oti = (oti_t *) svga->priv; int clk_sel = ((svga->miscout >> 2) & 3) | ((oti->regs[0x0d] & 0x20) >> 3); svga->clock = (cpuclock * (double) (1ULL << 32)) / oti_getclock(clk_sel); @@ -479,9 +479,9 @@ oti_init(const device_t *info) } static void -oti_close(void *p) +oti_close(void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; svga_close(&oti->svga); @@ -489,17 +489,17 @@ oti_close(void *p) } static void -oti_speed_changed(void *p) +oti_speed_changed(void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; svga_recalctimings(&oti->svga); } static void -oti_force_redraw(void *p) +oti_force_redraw(void *priv) { - oti_t *oti = (oti_t *) p; + oti_t *oti = (oti_t *) priv; oti->svga.fullchange = changeframecount; } diff --git a/src/video/vid_ogc.c b/src/video/vid_ogc.c index 20be41fad..edc4c841e 100644 --- a/src/video/vid_ogc.c +++ b/src/video/vid_ogc.c @@ -39,6 +39,7 @@ #include <86box/vid_cga.h> #include <86box/vid_ogc.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> /* * Current bugs: @@ -140,7 +141,7 @@ ogc_in(uint16_t addr, void *priv) } void -ogc_waitstates(void *p) +ogc_waitstates(UNUSED(void *priv)) { int ws_array[16] = { 3, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8, 4, 5, 6, 7, 8 }; int ws; @@ -572,7 +573,7 @@ ogc_mdaattr_rebuild(void) * - Optional EGC expansion board (which handles 640x400x16) not implemented */ void * -ogc_init(const device_t *info) +ogc_init(UNUSED(const device_t *info)) { // int display_type; ogc_t *ogc = (ogc_t *) malloc(sizeof(ogc_t)); diff --git a/src/video/vid_paradise.c b/src/video/vid_paradise.c index 8971fe01e..a00015f9e 100644 --- a/src/video/vid_paradise.c +++ b/src/video/vid_paradise.c @@ -75,9 +75,9 @@ static video_timings_t timing_paradise_wd90c = { .type = VIDEO_ISA, .write_b = void paradise_remap(paradise_t *paradise); uint8_t -paradise_in(uint16_t addr, void *p) +paradise_in(uint16_t addr, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -135,9 +135,9 @@ paradise_in(uint16_t addr, void *p) } void -paradise_out(uint16_t addr, uint8_t val, void *p) +paradise_out(uint16_t addr, uint8_t val, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; uint8_t old; @@ -301,7 +301,7 @@ paradise_remap(paradise_t *paradise) void paradise_recalctimings(svga_t *svga) { - paradise_t *paradise = (paradise_t *) svga->p; + paradise_t *paradise = (paradise_t *) svga->priv; svga->lowres = !(svga->gdcreg[0x0e] & 0x01); @@ -345,9 +345,9 @@ paradise_recalctimings(svga_t *svga) } static void -paradise_write(uint32_t addr, uint8_t val, void *p) +paradise_write(uint32_t addr, uint8_t val, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; uint32_t prev_addr; uint32_t prev_addr2; @@ -394,9 +394,9 @@ paradise_write(uint32_t addr, uint8_t val, void *p) svga_write_linear(addr, val, svga); } static void -paradise_writew(uint32_t addr, uint16_t val, void *p) +paradise_writew(uint32_t addr, uint16_t val, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; uint32_t prev_addr; uint32_t prev_addr2; @@ -444,9 +444,9 @@ paradise_writew(uint32_t addr, uint16_t val, void *p) } static uint8_t -paradise_read(uint32_t addr, void *p) +paradise_read(uint32_t addr, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; uint32_t prev_addr; uint32_t prev_addr2; @@ -493,9 +493,9 @@ paradise_read(uint32_t addr, void *p) return svga_read_linear(addr, svga); } static uint16_t -paradise_readw(uint32_t addr, void *p) +paradise_readw(uint32_t addr, void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_t *svga = ¶dise->svga; uint32_t prev_addr; uint32_t prev_addr2; @@ -728,9 +728,9 @@ paradise_wd90c30_standalone_available(void) } void -paradise_close(void *p) +paradise_close(void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_close(¶dise->svga); @@ -738,17 +738,17 @@ paradise_close(void *p) } void -paradise_speed_changed(void *p) +paradise_speed_changed(void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; svga_recalctimings(¶dise->svga); } void -paradise_force_redraw(void *p) +paradise_force_redraw(void *priv) { - paradise_t *paradise = (paradise_t *) p; + paradise_t *paradise = (paradise_t *) priv; paradise->svga.fullchange = changeframecount; } diff --git a/src/video/vid_pgc.c b/src/video/vid_pgc.c index d68850bef..0033e96d1 100644 --- a/src/video/vid_pgc.c +++ b/src/video/vid_pgc.c @@ -414,7 +414,7 @@ hndl_clbeg(pgc_t *dev) } static void -hndl_clend(pgc_t *dev) +hndl_clend(UNUSED(pgc_t *dev)) { /* Should not happen outside a CLBEG. */ } @@ -1035,7 +1035,7 @@ hndl_poly(pgc_t *dev) /* Parse but don't execute a POLY command (for adding to a command list) */ static int -parse_poly(pgc_t *dev, pgc_cl_t *cl, int c) +parse_poly(pgc_t *dev, pgc_cl_t *cl, UNUSED(int c)) { uint8_t count; @@ -1898,7 +1898,6 @@ pgc_param_coord(pgc_t *dev, int32_t *value) pgc_error(dev, PGC_ERROR_MISSING); return err_digit(dev); } - break; /* Scientific notation. */ case 'd': diff --git a/src/video/vid_s3.c b/src/video/vid_s3.c index 7f840d134..bcdd64d40 100644 --- a/src/video/vid_s3.c +++ b/src/video/vid_s3.c @@ -376,24 +376,24 @@ typedef struct s3_t { static void s3_updatemapping(s3_t *s3); -static void s3_accel_write(uint32_t addr, uint8_t val, void *p); -static void s3_accel_write_w(uint32_t addr, uint16_t val, void *p); -static void s3_accel_write_l(uint32_t addr, uint32_t val, void *p); -static uint8_t s3_accel_read(uint32_t addr, void *p); -static uint16_t s3_accel_read_w(uint32_t addr, void *p); -static uint32_t s3_accel_read_l(uint32_t addr, void *p); +static void s3_accel_write(uint32_t addr, uint8_t val, void *priv); +static void s3_accel_write_w(uint32_t addr, uint16_t val, void *priv); +static void s3_accel_write_l(uint32_t addr, uint32_t val, void *priv); +static uint8_t s3_accel_read(uint32_t addr, void *priv); +static uint16_t s3_accel_read_w(uint32_t addr, void *priv); +static uint32_t s3_accel_read_l(uint32_t addr, void *priv); -static void s3_out(uint16_t addr, uint8_t val, void *p); -static uint8_t s3_in(uint16_t addr, void *p); +static void s3_out(uint16_t addr, uint8_t val, void *priv); +static uint8_t s3_in(uint16_t addr, void *priv); -static void s3_accel_out(uint16_t port, uint8_t val, void *p); -static void s3_accel_out_w(uint16_t port, uint16_t val, void *p); -static void s3_accel_out_l(uint16_t port, uint32_t val, void *p); -static uint8_t s3_accel_in(uint16_t port, void *p); -static uint16_t s3_accel_in_w(uint16_t port, void *p); -static uint32_t s3_accel_in_l(uint16_t port, void *p); -static uint8_t s3_pci_read(int func, int addr, void *p); -static void s3_pci_write(int func, int addr, uint8_t val, void *p); +static void s3_accel_out(uint16_t port, uint8_t val, void *priv); +static void s3_accel_out_w(uint16_t port, uint16_t val, void *priv); +static void s3_accel_out_l(uint16_t port, uint32_t val, void *priv); +static uint8_t s3_accel_in(uint16_t port, void *priv); +static uint16_t s3_accel_in_w(uint16_t port, void *priv); +static uint32_t s3_accel_in_l(uint16_t port, void *priv); +static uint8_t s3_pci_read(int func, int addr, void *priv); +static void s3_pci_write(int func, int addr, uint8_t val, void *priv); /*Remap address for chain-4/doubleword style layout. These will stay for convenience.*/ @@ -1980,7 +1980,7 @@ s3_accel_write_fifo_l(s3_t *s3, uint32_t addr, uint32_t val) static void s3_vblank_start(svga_t *svga) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; s3->subsys_stat |= INT_VSY; s3_update_irqs(s3); @@ -2003,7 +2003,7 @@ s3_hwcursor_convert_addr(svga_t *svga) static void s3_hwcursor_draw(svga_t *svga, int displine) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; int shift = 1; int width = 16; uint16_t dat[2]; @@ -2332,7 +2332,7 @@ s3_hwcursor_draw(svga_t *svga, int displine) static void s3_trio64v_overlay_draw(svga_t *svga, int displine) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; int offset = (s3->streams.sec_x - s3->streams.pri_x) + 1; int h_acc = s3->streams.dda_horiz_accumulator; int r[8]; @@ -2562,9 +2562,9 @@ s3_io_set(s3_t *s3) } static void -s3_out(uint16_t addr, uint8_t val, void *p) +s3_out(uint16_t addr, uint8_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint8_t old; uint8_t mask; @@ -2909,9 +2909,9 @@ s3_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -s3_in(uint16_t addr, void *p) +s3_in(uint16_t addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; int rs2; int rs3; @@ -3018,7 +3018,6 @@ s3_in(uint16_t addr, void *p) } } else return svga->crtc[0x6b]; - break; case 0x6c: if (s3->chip != S3_TRIO64V2) { if (svga->crtc[0x53] & 0x08) { @@ -3027,7 +3026,6 @@ s3_in(uint16_t addr, void *p) return (svga->crtc[0x5a] & 0x80); } else return svga->crtc[0x6c]; - break; } return svga->crtc[svga->crtcreg]; } @@ -3037,7 +3035,7 @@ s3_in(uint16_t addr, void *p) static void s3_recalctimings(svga_t *svga) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; int clk_sel = (svga->miscout >> 2) & 3; if (!svga->scrblank && svga->attr_palette_enable) { @@ -3348,7 +3346,7 @@ s3_recalctimings(svga_t *svga) static void s3_trio64v_recalctimings(svga_t *svga) { - s3_t *s3 = (s3_t *) svga->p; + s3_t *s3 = (s3_t *) svga->priv; int clk_sel = (svga->miscout >> 2) & 3; if (!svga->scrblank && svga->attr_palette_enable) { @@ -3582,9 +3580,9 @@ s3_updatemapping(s3_t *s3) } static float -s3_trio64_getclock(int clock, void *p) +s3_trio64_getclock(int clock, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; float t; int m; @@ -3602,9 +3600,9 @@ s3_trio64_getclock(int clock, void *p) } static void -s3_accel_out(uint16_t port, uint8_t val, void *p) +s3_accel_out(uint16_t port, uint8_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; if (port >= 0x8000) { @@ -3650,9 +3648,9 @@ s3_accel_out(uint16_t port, uint8_t val, void *p) } static void -s3_accel_out_w(uint16_t port, uint16_t val, void *p) +s3_accel_out_w(uint16_t port, uint16_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; if (!s3->enable_8514) return; @@ -3664,9 +3662,9 @@ s3_accel_out_w(uint16_t port, uint16_t val, void *p) } static void -s3_accel_out_l(uint16_t port, uint32_t val, void *p) +s3_accel_out_l(uint16_t port, uint32_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; if (!s3->enable_8514) return; @@ -3678,9 +3676,9 @@ s3_accel_out_l(uint16_t port, uint32_t val, void *p) } static uint8_t -s3_accel_in(uint16_t port, void *p) +s3_accel_in(uint16_t port, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; int temp; @@ -4262,9 +4260,9 @@ s3_accel_in(uint16_t port, void *p) } static uint16_t -s3_accel_in_w(uint16_t port, void *p) +s3_accel_in_w(uint16_t port, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint16_t temp = 0x0000; uint16_t *vram_w = (uint16_t *) svga->vram; @@ -4318,9 +4316,9 @@ s3_accel_in_w(uint16_t port, void *p) } static uint32_t -s3_accel_in_l(uint16_t port, void *p) +s3_accel_in_l(UNUSED(uint16_t port), void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint32_t temp = 0x00000000; uint16_t *vram_w = (uint16_t *) svga->vram; @@ -4371,9 +4369,9 @@ s3_accel_in_l(uint16_t port, void *p) } static void -s3_accel_write(uint32_t addr, uint8_t val, void *p) +s3_accel_write(uint32_t addr, uint8_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; if (!s3->enable_8514) @@ -4389,9 +4387,9 @@ s3_accel_write(uint32_t addr, uint8_t val, void *p) } static void -s3_accel_write_w(uint32_t addr, uint16_t val, void *p) +s3_accel_write_w(uint32_t addr, uint16_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; if (!s3->enable_8514) @@ -4407,9 +4405,9 @@ s3_accel_write_w(uint32_t addr, uint16_t val, void *p) } static void -s3_accel_write_l(uint32_t addr, uint32_t val, void *p) +s3_accel_write_l(uint32_t addr, uint32_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; if (!s3->enable_8514) @@ -4425,9 +4423,9 @@ s3_accel_write_l(uint32_t addr, uint32_t val, void *p) } static uint8_t -s3_accel_read(uint32_t addr, void *p) +s3_accel_read(uint32_t addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint8_t temp = 0x00; @@ -4492,12 +4490,12 @@ s3_accel_read(uint32_t addr, void *p) case 0x8505: return s3->subsys_cntl; default: - return s3_accel_in(addr & 0xffff, p); + return s3_accel_in(addr & 0xffff, priv); } return 0xff; } else { if (addr & 0x8000) { - temp = s3_accel_in(addr & 0xffff, p); + temp = s3_accel_in(addr & 0xffff, priv); } else if (s3_cpu_dest(s3)) { READ_PIXTRANS_BYTE_MM @@ -4528,9 +4526,9 @@ s3_accel_read(uint32_t addr, void *p) } static uint16_t -s3_accel_read_w(uint32_t addr, void *p) +s3_accel_read_w(uint32_t addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint16_t temp = 0x0000; uint16_t *vram_w = (uint16_t *) svga->vram; @@ -4546,7 +4544,7 @@ s3_accel_read_w(uint32_t addr, void *p) return s3->accel.short_stroke; default: - return s3_accel_read(addr, p) | s3_accel_read(addr + 1, p) << 8; + return s3_accel_read(addr, priv) | s3_accel_read(addr + 1, priv) << 8; } return 0xffff; } else { @@ -4556,8 +4554,8 @@ s3_accel_read_w(uint32_t addr, void *p) s3_wait_fifo_idle(s3); temp = s3->accel.short_stroke; } else { - temp = s3_accel_read((addr & 0xfffe), p); - temp |= s3_accel_read((addr & 0xfffe) + 1, p) << 8; + temp = s3_accel_read((addr & 0xfffe), priv); + temp |= s3_accel_read((addr & 0xfffe) + 1, priv) << 8; } } else if (s3_cpu_dest(s3)) { READ_PIXTRANS_WORD @@ -4589,9 +4587,9 @@ s3_accel_read_w(uint32_t addr, void *p) } static uint32_t -s3_accel_read_l(uint32_t addr, void *p) +s3_accel_read_l(uint32_t addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; uint32_t temp = 0x00000000; uint16_t *vram_w = (uint16_t *) svga->vram; @@ -4721,15 +4719,15 @@ s3_accel_read_l(uint32_t addr, void *p) break; default: - temp = s3_accel_read_w(addr, p) | (s3_accel_read_w(addr + 2, p) << 16); + temp = s3_accel_read_w(addr, priv) | (s3_accel_read_w(addr + 2, priv) << 16); break; } } else { if (addr & 0x8000) { - temp = s3_accel_read((addr & 0xfffc), p); - temp |= s3_accel_read((addr & 0xfffc) + 1, p) << 8; - temp |= s3_accel_read((addr & 0xfffc) + 2, p) << 16; - temp |= s3_accel_read((addr & 0xfffc) + 3, p) << 24; + temp = s3_accel_read((addr & 0xfffc), priv); + temp |= s3_accel_read((addr & 0xfffc) + 1, priv) << 8; + temp |= s3_accel_read((addr & 0xfffc) + 2, priv) << 16; + temp |= s3_accel_read((addr & 0xfffc) + 3, priv) << 24; } else if (s3_cpu_dest(s3)) { READ_PIXTRANS_LONG @@ -7319,9 +7317,9 @@ s3_accel_start(int count, int cpu_input, uint32_t mix_dat, uint32_t cpu_dat, s3_ } static uint8_t -s3_pci_read(int func, int addr, void *p) +s3_pci_read(UNUSED(int func), int addr, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; switch (addr) { @@ -7340,7 +7338,6 @@ s3_pci_read(int func, int addr, void *p) return s3->pci_regs[PCI_REG_COMMAND] | 0x80; /*Respond to IO and memory accesses*/ else return s3->pci_regs[PCI_REG_COMMAND]; /*Respond to IO and memory accesses*/ - break; case 0x07: return (s3->chip == S3_TRIO64V2) ? (s3->pci_regs[0x07] & 0x36) : (1 << 1); /*Medium DEVSEL timing*/ @@ -7355,17 +7352,14 @@ s3_pci_read(int func, int addr, void *p) return 0x00; /*Supports VGA interface*/ else return 0x01; - break; case 0x0b: if (s3->chip >= S3_TRIO32 || s3->chip == S3_VISION968 || s3->chip == S3_VISION868) return 0x03; else return 0x00; - break; case 0x0d: return (s3->chip == S3_TRIO64V2) ? (s3->pci_regs[0x0d] & 0xf8) : 0x00; - break; case 0x10: return 0x00; /*Linear frame buffer address*/ @@ -7376,7 +7370,6 @@ s3_pci_read(int func, int addr, void *p) return 0x00; else return (svga->crtc[0x5a] & 0x80); - break; case 0x13: if (svga->crtc[0x53] & 0x08) { @@ -7384,7 +7377,6 @@ s3_pci_read(int func, int addr, void *p) } else { return svga->crtc[0x59]; } - break; case 0x30: return s3->has_bios ? (s3->pci_regs[0x30] & 0x01) : 0x00; /*BIOS ROM address*/ @@ -7405,15 +7397,14 @@ s3_pci_read(int func, int addr, void *p) break; case 0x3f: return (s3->chip == S3_TRIO64V2) ? 0xff : 0x00; - break; } return 0; } static void -s3_pci_write(int func, int addr, uint8_t val, void *p) +s3_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_t *svga = &s3->svga; switch (addr) { @@ -8565,9 +8556,9 @@ s3_trio64v2_dx_available(void) } static void -s3_close(void *p) +s3_close(void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; s3->fifo_thread_run = 0; thread_set_event(s3->wake_fifo_thread); @@ -8584,17 +8575,17 @@ s3_close(void *p) } static void -s3_speed_changed(void *p) +s3_speed_changed(void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; svga_recalctimings(&s3->svga); } static void -s3_force_redraw(void *p) +s3_force_redraw(void *priv) { - s3_t *s3 = (s3_t *) p; + s3_t *s3 = (s3_t *) priv; s3->svga.fullchange = s3->svga.monitor->mon_changeframecount; } diff --git a/src/video/vid_s3_virge.c b/src/video/vid_s3_virge.c index 1eb1fa855..6c382cf7f 100644 --- a/src/video/vid_s3_virge.c +++ b/src/video/vid_s3_virge.c @@ -279,6 +279,7 @@ typedef struct virge_t { uint32_t dma_ptr; uint64_t blitter_time; volatile int fifo_slot; + int fifo_slots_num; pc_timer_t tri_timer; @@ -307,12 +308,12 @@ static void s3_virge_updatemapping(virge_t *virge); static void s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat); -static uint8_t s3_virge_mmio_read(uint32_t addr, void *p); -static uint16_t s3_virge_mmio_read_w(uint32_t addr, void *p); -static uint32_t s3_virge_mmio_read_l(uint32_t addr, void *p); -static void s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p); -static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p); -static void s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *p); +static uint8_t s3_virge_mmio_read(uint32_t addr, void *priv); +static uint16_t s3_virge_mmio_read_w(uint32_t addr, void *rivp); +static uint32_t s3_virge_mmio_read_l(uint32_t addr, void *priv); +static void s3_virge_mmio_write(uint32_t addr, uint8_t val, void *priv); +static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *priv); +static void s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv); enum { CMD_SET_AE = 1, @@ -387,9 +388,9 @@ s3_virge_log(const char *fmt, ...) #endif static void -s3_virge_tri_timer(void *p) +s3_virge_tri_timer(void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; thread_set_event(virge->wake_render_thread); /*Wake up FIFO thread if moving from idle*/ } @@ -447,9 +448,9 @@ render_thread(void *param) } static void -s3_virge_out(uint16_t addr, uint8_t val, void *p) +s3_virge_out(uint16_t addr, uint8_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; uint8_t old; uint32_t cursoraddr; @@ -653,9 +654,9 @@ s3_virge_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -s3_virge_in(uint16_t addr, void *p) +s3_virge_in(uint16_t addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; uint8_t ret; @@ -760,7 +761,7 @@ s3_virge_in(uint16_t addr, void *p) static void s3_virge_recalctimings(svga_t *svga) { - virge_t *virge = (virge_t *) svga->p; + virge_t *virge = (virge_t *) svga->priv; svga->hdisp = svga->hdisp_old; @@ -988,7 +989,7 @@ s3_virge_updatemapping(virge_t *virge) static void s3_virge_vblank_start(svga_t *svga) { - virge_t *virge = (virge_t *) svga->p; + virge_t *virge = (virge_t *) svga->priv; virge->subsys_stat |= INT_VSY; s3_virge_update_irqs(virge); @@ -1031,6 +1032,8 @@ s3_virge_mmio_fifo_write_l(uint32_t addr, uint32_t val, virge_t *virge) else s3_virge_bitblt(virge, 32, val); } else { + if (virge->fifo_slot >= virge->fifo_slots_num) + return; virge->fifo_slot++; switch (addr & 0xfffc) { case 0x8590: @@ -1471,25 +1474,34 @@ s3_virge_mmio_fifo_write_l(uint32_t addr, uint32_t val, virge_t *virge) } static uint8_t -s3_virge_mmio_read(uint32_t addr, void *p) +s3_virge_mmio_read(uint32_t addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; uint8_t ret = 0xff; s3_virge_log("[%04X:%08X]: MMIO ReadB addr = %04x\n", CS, cpu_state.pc, addr & 0xffff); switch (addr & 0xffff) { case 0x8505: - ret = 0; - if (virge->s3d_busy || virge->fifo_slot) { - ret = 0x10; - } else { - ret = 0x30; - } + ret = 0xc0; + if (!virge->s3d_busy && !virge->fifo_slot) + ret |= 0x20; if (virge->fifo_slot) virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot); return ret; + case 0x850c: + ret = virge->advfunc_cntl & 0x3f; + if (virge->fifo_slot) + virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 6; + ret &= 0xff; + break; + case 0x850d: + ret = (virge->fifo_slots_num - virge->fifo_slot) >> 2; + break; + case 0x83b0: case 0x83b1: case 0x83b2: @@ -1555,24 +1567,34 @@ s3_virge_mmio_read(uint32_t addr, void *p) return 0xff; } static uint16_t -s3_virge_mmio_read_w(uint32_t addr, void *p) +s3_virge_mmio_read_w(uint32_t addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; uint16_t ret = 0xffff; s3_virge_log("[%04X:%08X]: MMIO ReadW addr = %04x\n", CS, cpu_state.pc, addr & 0xfffe); switch (addr & 0xfffe) { case 0x8504: + ret = 0xc000; + if (!virge->s3d_busy && !virge->fifo_slot) + ret |= 0x2000; if (!virge->fifo_slot) virge->subsys_stat |= INT_FIFO_EMP; ret |= virge->subsys_stat; if (virge->fifo_slot) virge->fifo_slot--; - ret |= 0x30; /*A bit of a workaround at the moment.*/ + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 8; s3_virge_update_irqs(virge); return ret; + case 0x850c: + ret = virge->advfunc_cntl & 0x3f; + if (virge->fifo_slot) + virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 6; + break; + case 0x859c: return virge->cmd_dma; @@ -1584,9 +1606,9 @@ s3_virge_mmio_read_w(uint32_t addr, void *p) } static uint32_t -s3_virge_mmio_read_l(uint32_t addr, void *p) +s3_virge_mmio_read_l(uint32_t addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; uint32_t ret = 0xffffffff; s3_virge_log("[%04X:%08X]: MMIO ReadL addr = %04x\n", CS, cpu_state.pc, addr & 0xfffc); @@ -1660,10 +1682,9 @@ s3_virge_mmio_read_l(uint32_t addr, void *p) break; case 0x8504: - if (virge->s3d_busy || virge->fifo_slot) { - ret = (0x10 << 8); - } else { - ret = (0x10 << 8) | (1 << 13); + ret = 0x0000c000; + if (!virge->s3d_busy && !virge->fifo_slot) { + ret |= 0x00002000; if (!virge->s3d_busy) virge->subsys_stat |= INT_3DF_EMP; if (!virge->fifo_slot) @@ -1672,9 +1693,17 @@ s3_virge_mmio_read_l(uint32_t addr, void *p) ret |= virge->subsys_stat; if (virge->fifo_slot) virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 8; s3_virge_update_irqs(virge); break; + case 0x850c: + ret = virge->advfunc_cntl & 0x3f; + if (virge->fifo_slot) + virge->fifo_slot--; + ret |= (virge->fifo_slots_num - virge->fifo_slot) << 6; + break; + case 0x8590: ret = virge->cmd_dma_base; break; @@ -1745,9 +1774,9 @@ s3_virge_mmio_read_l(uint32_t addr, void *p) } static void -s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p) +s3_virge_mmio_write(uint32_t addr, uint8_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; s3_virge_log("MMIO WriteB addr = %04x, val = %02x\n", addr & 0xffff, val); if (((addr & 0xffff) >= 0x8590) || ((addr & 0xffff) < 0x8000)) { if ((addr & 0xffff) == 0xff20) { @@ -1812,9 +1841,9 @@ s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p) } static void -s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p) +s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; s3_virge_log("[%04X:%08X]: MMIO WriteW addr = %04x, val = %04x\n", CS, cpu_state.pc, addr & 0xfffe, val); if (((addr & 0xfffe) >= 0x8590) || ((addr & 0xfffe) < 0x8000)) if ((addr & 0xfffe) == 0xff20) @@ -1830,9 +1859,9 @@ s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p) } static void -s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *p) +s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; s3_virge_log("[%04X:%08X]: MMIO WriteL addr = %04x, val = %04x\n", CS, cpu_state.pc, addr & 0xfffc, val); @@ -3486,7 +3515,7 @@ s3_virge_triangle(virge_t *virge, s3d_t *s3d_tri) static void s3_virge_hwcursor_draw(svga_t *svga, int displine) { - virge_t *virge = (virge_t *) svga->p; + virge_t *virge = (virge_t *) svga->priv; uint16_t dat[2]; int xx; int offset = svga->hwcursor_latch.x - svga->hwcursor_latch.xoff; @@ -3498,26 +3527,41 @@ s3_virge_hwcursor_draw(svga_t *svga, int displine) svga->hwcursor_latch.addr += 16; switch (svga->bpp) { + default: + if (virge->chip != S3_VIRGEGX2) { + fg = svga->pallook[virge->hwc_fg_col & 0xff]; + bg = svga->pallook[virge->hwc_bg_col & 0xff]; + break; + } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + case 15: - fg = video_15to32[virge->hwc_fg_col & 0xffff]; - bg = video_15to32[virge->hwc_bg_col & 0xffff]; - break; + if (virge->chip != S3_VIRGEGX2) { + fg = video_15to32[virge->hwc_fg_col & 0xffff]; + bg = video_15to32[virge->hwc_bg_col & 0xffff]; + break; + } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 16: - fg = video_16to32[virge->hwc_fg_col & 0xffff]; - bg = video_16to32[virge->hwc_bg_col & 0xffff]; - break; + if (virge->chip != S3_VIRGEGX2) { + fg = video_16to32[virge->hwc_fg_col & 0xffff]; + bg = video_16to32[virge->hwc_bg_col & 0xffff]; + break; + } +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif case 24: case 32: fg = virge->hwc_fg_col; bg = virge->hwc_bg_col; break; - - default: - fg = svga->pallook[virge->hwc_fg_col & 0xff]; - bg = svga->pallook[virge->hwc_bg_col & 0xff]; - break; } for (uint8_t x = 0; x < 64; x += 16) { @@ -3527,6 +3571,9 @@ s3_virge_hwcursor_draw(svga_t *svga, int displine) /*X11*/ for (xx = 0; xx < 16; xx++) { if (offset >= 0) { + if (virge->chip == S3_VIRGEGX2) + dat[0] ^= 0x8000; + if (dat[0] & 0x8000) buffer32->line[displine][offset + svga->x_add] = (dat[1] & 0x8000) ? fg : bg; } @@ -3771,7 +3818,7 @@ s3_virge_hwcursor_draw(svga_t *svga, int displine) static void s3_virge_overlay_draw(svga_t *svga, int displine) { - virge_t *virge = (virge_t *) svga->p; + virge_t *virge = (virge_t *) svga->priv; int offset = (virge->streams.sec_x - virge->streams.pri_x) + 1; int h_acc = virge->streams.dda_horiz_accumulator; int r[8]; @@ -3813,9 +3860,9 @@ s3_virge_overlay_draw(svga_t *svga, int displine) } static uint8_t -s3_virge_pci_read(int func, int addr, void *p) +s3_virge_pci_read(UNUSED(int func), int addr, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; uint8_t ret = 0; @@ -3975,9 +4022,9 @@ s3_virge_pci_read(int func, int addr, void *p) } static void -s3_virge_pci_write(int func, int addr, uint8_t val, void *p) +s3_virge_pci_write(UNUSED(int func), int addr, uint8_t val, void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_t *svga = &virge->svga; switch (addr) { case 0x00: @@ -4086,24 +4133,29 @@ s3_virge_reset(void *priv) switch (virge->local) { case S3_VIRGE_325: case S3_DIAMOND_STEALTH3D_2000: + virge->fifo_slots_num = 8; virge->svga.crtc[0x59] = 0x70; break; case S3_DIAMOND_STEALTH3D_3000: case S3_STB_VELOCITY_3D: + virge->fifo_slots_num = 8; virge->svga.crtc[0x59] = 0x70; break; case S3_VIRGE_GX2: case S3_DIAMOND_STEALTH3D_4000: + virge->fifo_slots_num = 16; virge->svga.crtc[0x6c] = 1; virge->svga.crtc[0x59] = 0x70; break; case S3_TRIO_3D2X: + virge->fifo_slots_num = 16; virge->svga.crtc[0x6c] = 1; virge->svga.crtc[0x59] = 0x70; break; default: + virge->fifo_slots_num = 8; virge->svga.crtc[0x6c] = 1; virge->svga.crtc[0x59] = 0x70; break; @@ -4262,6 +4314,7 @@ s3_virge_init(const device_t *info) switch (info->local) { case S3_VIRGE_325: case S3_DIAMOND_STEALTH3D_2000: + virge->fifo_slots_num = 8; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x56; virge->virge_id_low = 0x31; @@ -4271,6 +4324,7 @@ s3_virge_init(const device_t *info) break; case S3_DIAMOND_STEALTH3D_3000: case S3_STB_VELOCITY_3D: + virge->fifo_slots_num = 8; virge->svga.decode_mask = (8 << 20) - 1; virge->virge_id_high = 0x88; virge->virge_id_low = 0x3d; @@ -4280,6 +4334,7 @@ s3_virge_init(const device_t *info) break; case S3_VIRGE_GX2: case S3_DIAMOND_STEALTH3D_4000: + virge->fifo_slots_num = 16; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x10; @@ -4291,6 +4346,7 @@ s3_virge_init(const device_t *info) break; case S3_TRIO_3D2X: + virge->fifo_slots_num = 16; virge->svga.decode_mask = (8 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x13; @@ -4304,8 +4360,12 @@ s3_virge_init(const device_t *info) case S3_VIRGE_GX: virge->virge_rev = 0x01; - /*FALLTHROUGH*/ +#ifdef FALLTHROUGH_ANNOTATION + [[fallthrough]]; +#endif + default: + virge->fifo_slots_num = 8; virge->svga.decode_mask = (4 << 20) - 1; virge->virge_id_high = 0x8a; virge->virge_id_low = 0x01; @@ -4382,9 +4442,9 @@ s3_virge_init(const device_t *info) } static void -s3_virge_close(void *p) +s3_virge_close(void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; virge->render_thread_run = 0; thread_set_event(virge->wake_render_thread); @@ -4462,17 +4522,17 @@ s3_trio3d2x_available(void) } static void -s3_virge_speed_changed(void *p) +s3_virge_speed_changed(void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; svga_recalctimings(&virge->svga); } static void -s3_virge_force_redraw(void *p) +s3_virge_force_redraw(void *priv) { - virge_t *virge = (virge_t *) p; + virge_t *virge = (virge_t *) priv; virge->svga.fullchange = changeframecount; } diff --git a/src/video/vid_sdac_ramdac.c b/src/video/vid_sdac_ramdac.c index 1587bf0e0..d68af2bfa 100644 --- a/src/video/vid_sdac_ramdac.c +++ b/src/video/vid_sdac_ramdac.c @@ -243,9 +243,9 @@ sdac_ramdac_in(uint16_t addr, int rs2, void *p, svga_t *svga) } float -sdac_getclock(int clock, void *p) +sdac_getclock(int clock, void *priv) { - sdac_ramdac_t *ramdac = (sdac_ramdac_t *) p; + sdac_ramdac_t *ramdac = (sdac_ramdac_t *) priv; float t; int m; int n1; diff --git a/src/video/vid_sigma.c b/src/video/vid_sigma.c index 148dcc81c..97383bc65 100644 --- a/src/video/vid_sigma.c +++ b/src/video/vid_sigma.c @@ -192,9 +192,9 @@ static video_timings_t timing_sigma = { .type = VIDEO_ISA, .write_b = 8, .write_ static void sigma_recalctimings(sigma_t *cga); static void -sigma_out(uint16_t addr, uint8_t val, void *p) +sigma_out(uint16_t addr, uint8_t val, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; uint8_t old; if (addr >= 0x3D0 && addr < 0x3E0) { @@ -260,10 +260,10 @@ sigma_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -sigma_in(uint16_t addr, void *p) +sigma_in(uint16_t addr, void *priv) { uint8_t result = 0xFF; - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; switch (addr) { case 0x2D0: @@ -332,27 +332,27 @@ sigma_in(uint16_t addr, void *p) } static void -sigma_write(uint32_t addr, uint8_t val, void *p) +sigma_write(uint32_t addr, uint8_t val, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; sigma->vram[sigma->plane * 0x8000 + (addr & 0x7fff)] = val; cycles -= 4; } static uint8_t -sigma_read(uint32_t addr, void *p) +sigma_read(uint32_t addr, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; cycles -= 4; return sigma->vram[sigma->plane * 0x8000 + (addr & 0x7fff)]; } static void -sigma_bwrite(uint32_t addr, uint8_t val, void *p) +sigma_bwrite(uint32_t addr, uint8_t val, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; addr &= 0x3FFF; if ((addr < 0x1800) || sigma->rom_paged || (addr >= 0x2000)) @@ -362,9 +362,9 @@ sigma_bwrite(uint32_t addr, uint8_t val, void *p) } static uint8_t -sigma_bread(uint32_t addr, void *p) +sigma_bread(uint32_t addr, void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; uint8_t result; addr &= 0x3FFF; @@ -589,9 +589,9 @@ sigma_gfx4col(sigma_t *sigma) } static void -sigma_poll(void *p) +sigma_poll(void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; int x; int c; int oldvc; @@ -833,18 +833,18 @@ sigma_available(void) } static void -sigma_close(void *p) +sigma_close(void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; free(sigma->vram); free(sigma); } void -sigma_speed_changed(void *p) +sigma_speed_changed(void *priv) { - sigma_t *sigma = (sigma_t *) p; + sigma_t *sigma = (sigma_t *) priv; sigma_recalctimings(sigma); } diff --git a/src/video/vid_stg_ramdac.c b/src/video/vid_stg_ramdac.c index d235477c9..64dd27def 100644 --- a/src/video/vid_stg_ramdac.c +++ b/src/video/vid_stg_ramdac.c @@ -199,9 +199,9 @@ stg_ramdac_in(uint16_t addr, void *p, svga_t *svga) } float -stg_getclock(int clock, void *p) +stg_getclock(int clock, void *priv) { - stg_ramdac_t *ramdac = (stg_ramdac_t *) p; + stg_ramdac_t *ramdac = (stg_ramdac_t *) priv; float t; int m; int n; diff --git a/src/video/vid_svga.c b/src/video/vid_svga.c index 913a052ff..0e83c034a 100644 --- a/src/video/vid_svga.c +++ b/src/video/vid_svga.c @@ -108,9 +108,9 @@ svga_set_override(svga_t *svga, int val) } void -svga_out(uint16_t addr, uint8_t val, void *p) +svga_out(uint16_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; uint8_t o; uint8_t index; @@ -161,15 +161,15 @@ svga_out(uint16_t addr, uint8_t val, void *p) case 0x3c2: svga->miscout = val; svga->vidclock = val & 4; - io_removehandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->p); + io_removehandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->priv); if (!(val & 1)) - io_sethandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->p); + io_sethandler(0x03a0, 0x0020, svga->video_in, NULL, NULL, svga->video_out, NULL, NULL, svga->priv); svga_recalctimings(svga); break; case 0x3c3: if (xga_enabled) { svga->xga.on = (val & 0x01) ? 0 : 1; - vga_on = !svga->xga.on; + vga_on = !svga->xga.on; } break; case 0x3c4: @@ -205,6 +205,9 @@ svga_out(uint16_t addr, uint8_t val, void *p) svga->chain4 = val & 8; svga->fast = (svga->gdcreg[8] == 0xff && !(svga->gdcreg[3] & 0x18) && !svga->gdcreg[1]) && ((svga->chain4 && (svga->packed_chain4 || svga->force_old_addr)) || svga->fb_only) && !(svga->adv_flags & FLAG_ADDR_BY8); break; + + default: + break; } break; case 0x2ea: @@ -245,6 +248,9 @@ svga_out(uint16_t addr, uint8_t val, void *p) svga->dac_pos = 0; svga->dac_addr = (svga->dac_addr + 1) & 255; break; + + default: + break; } break; case 0x3ce: @@ -283,25 +289,34 @@ svga_out(uint16_t addr, uint8_t val, void *p) mem_mapping_set_addr(&svga->mapping, 0xb8000, 0x08000); svga->banked_mask = 0x7fff; break; + + default: + break; } } break; case 7: svga->colournocare = val; break; + + default: + break; } svga->gdcreg[svga->gdcaddr & 15] = val; svga->fast = (svga->gdcreg[8] == 0xff && !(svga->gdcreg[3] & 0x18) && !svga->gdcreg[1]) && ((svga->chain4 && (svga->packed_chain4 || svga->force_old_addr)) || svga->fb_only); if (((svga->gdcaddr & 15) == 5 && (val ^ o) & 0x70) || ((svga->gdcaddr & 15) == 6 && (val ^ o) & 1)) svga_recalctimings(svga); break; + + default: + break; } } uint8_t -svga_in(uint16_t addr, void *p) +svga_in(uint16_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; uint8_t index; uint8_t ret = 0xff; @@ -362,6 +377,9 @@ svga_in(uint16_t addr, void *p) else ret = svga->vgapal[index].b & 0x3f; break; + + default: + break; } if (svga->adv_flags & FLAG_RAMDAC_SHIFT) ret >>= 2; @@ -403,6 +421,9 @@ svga_in(uint16_t addr, void *p) ret = svga->cgastat; break; + + default: + break; } return ret; @@ -561,8 +582,14 @@ svga_recalctimings(svga_t *svga) else svga->render = svga_render_32bpp_highres; break; + + default: + break; } break; + + default: + break; } } } @@ -602,6 +629,9 @@ svga_recalctimings(svga_t *svga) xga_recalctimings(svga); } + if (svga->hdisp >= 2048) + svga->monitor->mon_overscan_x = 0; + svga->y_add = (svga->monitor->mon_overscan_y >> 1) - (svga->crtc[8] & 0x1f); svga->x_add = (svga->monitor->mon_overscan_x >> 1); @@ -693,17 +723,17 @@ svga_do_render(svga_t *svga) } void -svga_poll(void *p) +svga_poll(void *priv) { - svga_t *svga = (svga_t *) p; - ibm8514_t *dev = &svga->dev8514; - uint32_t x; - uint32_t blink_delay; - int wx; - int wy; - int ret; - int old_ma; - int linecountff = 0; + svga_t *svga = (svga_t *) priv; + ibm8514_t *dev = &svga->dev8514; + uint32_t x; + uint32_t blink_delay; + int wx; + int wy; + int ret; + int old_ma; + int linecountff = 0; if (!vga_on && ibm8514_enabled && ibm8514_on) { if (!dev->local) { @@ -792,7 +822,7 @@ svga_poll(void *p) if ((svga->cgastat & 8) && ((svga->displine & 15) == (svga->crtc[0x11] & 15)) && svga->vslines) svga->cgastat &= ~8; svga->vslines++; - if (svga->displine > 1500) + if (svga->displine > 2000) svga->displine = 0; } else { timer_advance_u64(&svga->timer, svga->dispontime); @@ -805,14 +835,14 @@ svga_poll(void *p) if ((svga->sc == (svga->crtc[11] & 31)) || (svga->sc == svga->rowcount)) svga->con = 0; if (svga->dispon) { - /*Real IBM 8514/A or compatibility mode doesn't have linedbl, so skip those.*/ + /*Real IBM 8514/A or compatibility mode doesn't have linedbl, so skip those.*/ if (dev->local && ibm8514_on) { - svga->linedbl = 0; + svga->linedbl = 0; svga->linecountff = 0; - linecountff = 1; + linecountff = 1; } if (svga->linedbl && !svga->linecountff && !linecountff) { - svga->linecountff = 1; + svga->linecountff = 1; svga->ma = svga->maback; } else if (svga->sc == svga->rowcount) { svga->linecountff = 0; @@ -917,7 +947,7 @@ svga_poll(void *p) svga->oddeven ^= 1; svga->monitor->mon_changeframecount = svga->interlace ? 3 : 2; - svga->vslines = 0; + svga->vslines = 0; if ((dev->local && vga_on) || !dev->local) { if (svga->interlace && svga->oddeven) @@ -930,7 +960,7 @@ svga_poll(void *p) else svga->ma = svga->maback = svga->ma_latch; } - svga->ca = ((svga->crtc[0xe] << 8) | svga->crtc[0xf]) + ((svga->crtc[0xb] & 0x60) >> 5) + svga->ca_adj; + svga->ca = ((svga->crtc[0xe] << 8) | svga->crtc[0xf]) + ((svga->crtc[0xb] & 0x60) >> 5) + svga->ca_adj; svga->ma = (svga->ma << 2); svga->maback = (svga->maback << 2); svga->ca = (svga->ca << 2); @@ -982,18 +1012,18 @@ svga_poll(void *p) } int -svga_init(const device_t *info, svga_t *svga, void *p, int memsize, +svga_init(const device_t *info, svga_t *svga, void *priv, int memsize, void (*recalctimings_ex)(struct svga_t *svga), - uint8_t (*video_in)(uint16_t addr, void *p), - void (*video_out)(uint16_t addr, uint8_t val, void *p), + uint8_t (*video_in)(uint16_t addr, void *priv), + void (*video_out)(uint16_t addr, uint8_t val, void *priv), void (*hwcursor_draw)(struct svga_t *svga, int displine), void (*overlay_draw)(struct svga_t *svga, int displine)) { int e; - svga->p = p; + svga->priv = priv; svga->monitor_index = monitor_index_global; - svga->monitor = &monitors[svga->monitor_index]; + svga->monitor = &monitors[svga->monitor_index]; for (int c = 0; c < 256; c++) { e = c; @@ -1007,10 +1037,10 @@ svga_init(const device_t *info, svga_t *svga, void *p, int memsize, svga->attrregs[0x11] = 0; svga->overscan_color = 0x000000; - svga->monitor->mon_overscan_x = 16; - svga->monitor->mon_overscan_y = 32; - svga->x_add = 8; - svga->y_add = 16; + svga->monitor->mon_overscan_x = 16; + svga->monitor->mon_overscan_y = 32; + svga->x_add = 8; + svga->y_add = 16; svga->crtc[0] = 63; svga->crtc[6] = 255; @@ -1119,12 +1149,12 @@ svga_decode_addr(svga_t *svga, uint32_t addr, int write) } static __inline void -svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) +svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; int writemask2 = svga->writemask; - int reset_wm = 0; + int reset_wm = 0; latch_t vall; uint8_t wm = svga->writemask; uint8_t count; @@ -1153,7 +1183,7 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) } } else { svga->xga.on = 0; - vga_on = !svga->xga.on; + vga_on = !svga->xga.on; } } addr = svga_decode_addr(svga, addr, 1); @@ -1197,7 +1227,7 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) - addr = svga->translate_address(addr, p); + addr = svga->translate_address(addr, priv); if (addr >= svga->vram_max) return; @@ -1325,6 +1355,9 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) } } break; + + default: + break; } if (reset_wm) @@ -1332,9 +1365,9 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) } static __inline uint8_t -svga_read_common(uint32_t addr, uint8_t linear, void *p) +svga_read_common(uint32_t addr, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; uint32_t latch_addr = 0; int readplane = svga->readplane; uint8_t count; @@ -1351,11 +1384,11 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) if (((svga->xga.op_mode & 7) >= 4) && (svga->xga.aperture_cntl >= 1)) { if (svga->xga.test == 0xa5) { /*Memory size test of XGA*/ svga->xga.on = 1; - vga_on = !svga->xga.on; + vga_on = !svga->xga.on; return svga->xga.test; } else if (svga->xga.test == 0x5a) { svga->xga.on = 1; - vga_on = !svga->xga.on; + vga_on = !svga->xga.on; return svga->xga.test; } else if ((addr == 0xa0000) || (addr == 0xa0010)) { addr += svga->xga.read_bank; @@ -1363,7 +1396,7 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) } } else { svga->xga.on = 0; - vga_on = !svga->xga.on; + vga_on = !svga->xga.on; } } addr = svga_decode_addr(svga, addr, 0); @@ -1386,7 +1419,7 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) else if ((svga->chain4 && (svga->packed_chain4 || svga->force_old_addr)) || svga->fb_only) { addr &= svga->decode_mask; if (svga->translate_address) - addr = svga->translate_address(addr, p); + addr = svga->translate_address(addr, priv); if (addr >= svga->vram_max) return 0xff; latch_addr = (addr & svga->vram_mask) & ~3; @@ -1401,7 +1434,7 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) addr &= ~1; if (linear && ibm8514_on && (svga->adv_flags & FLAG_ATI)) addr &= svga->vram_mask; - else + else addr <<= 2; } else { if (linear && ibm8514_on && (svga->adv_flags & FLAG_ATI)) { @@ -1418,8 +1451,8 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - latch_addr = svga->translate_address(latch_addr, p); - addr = svga->translate_address(addr, p); + latch_addr = svga->translate_address(latch_addr, priv); + addr = svga->translate_address(addr, priv); } /* standard VGA latched access */ @@ -1459,27 +1492,27 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) } void -svga_write(uint32_t addr, uint8_t val, void *p) +svga_write(uint32_t addr, uint8_t val, void *priv) { - svga_write_common(addr, val, 0, p); + svga_write_common(addr, val, 0, priv); } void -svga_write_linear(uint32_t addr, uint8_t val, void *p) +svga_write_linear(uint32_t addr, uint8_t val, void *priv) { - svga_write_common(addr, val, 1, p); + svga_write_common(addr, val, 1, priv); } uint8_t -svga_read(uint32_t addr, void *p) +svga_read(uint32_t addr, void *priv) { - return svga_read_common(addr, 0, p); + return svga_read_common(addr, 0, priv); } uint8_t -svga_read_linear(uint32_t addr, void *p) +svga_read_linear(uint32_t addr, void *priv) { - return svga_read_common(addr, 1, p); + return svga_read_common(addr, 1, priv); } void @@ -1570,12 +1603,12 @@ svga_doblit(int wx, int wy, svga_t *svga) } void -svga_writeb_linear(uint32_t addr, uint8_t val, void *p) +svga_writeb_linear(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) { - svga_write_linear(addr, val, p); + svga_write_linear(addr, val, priv); return; } @@ -1583,18 +1616,18 @@ svga_writeb_linear(uint32_t addr, uint8_t val, void *p) if (addr >= svga->vram_max) return; addr &= svga->vram_mask; - svga->changedvram[addr >> 12] = svga->monitor->mon_changeframecount; - *(uint8_t *) &svga->vram[addr] = val; + svga->changedvram[addr >> 12] = svga->monitor->mon_changeframecount; + *&svga->vram[addr] = val; } void -svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) +svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) { - svga_write_common(addr, val, linear, p); - svga_write_common(addr + 1, val >> 8, linear, p); + svga_write_common(addr, val, linear, priv); + svga_write_common(addr + 1, val >> 8, linear, priv); return; } @@ -1609,12 +1642,12 @@ svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - uint32_t addr2 = svga->translate_address(addr, p); + uint32_t addr2 = svga->translate_address(addr, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = val & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; } - addr2 = svga->translate_address(addr + 1, p); + addr2 = svga->translate_address(addr + 1, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = (val >> 8) & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; @@ -1630,27 +1663,27 @@ svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) } void -svga_writew(uint32_t addr, uint16_t val, void *p) +svga_writew(uint32_t addr, uint16_t val, void *priv) { - svga_writew_common(addr, val, 0, p); + svga_writew_common(addr, val, 0, priv); } void -svga_writew_linear(uint32_t addr, uint16_t val, void *p) +svga_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_writew_common(addr, val, 1, p); + svga_writew_common(addr, val, 1, priv); } void -svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) +svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) { - svga_write_common(addr, val, linear, p); - svga_write_common(addr + 1, val >> 8, linear, p); - svga_write_common(addr + 2, val >> 16, linear, p); - svga_write_common(addr + 3, val >> 24, linear, p); + svga_write_common(addr, val, linear, priv); + svga_write_common(addr + 1, val >> 8, linear, priv); + svga_write_common(addr + 2, val >> 16, linear, priv); + svga_write_common(addr + 3, val >> 24, linear, priv); return; } @@ -1665,22 +1698,22 @@ svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - uint32_t addr2 = svga->translate_address(addr, p); + uint32_t addr2 = svga->translate_address(addr, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = val & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; } - addr2 = svga->translate_address(addr + 1, p); + addr2 = svga->translate_address(addr + 1, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = (val >> 8) & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; } - addr2 = svga->translate_address(addr + 2, p); + addr2 = svga->translate_address(addr + 2, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = (val >> 16) & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; } - addr2 = svga->translate_address(addr + 3, p); + addr2 = svga->translate_address(addr + 3, priv); if (addr2 < svga->vram_max) { svga->vram[addr2 & svga->vram_mask] = (val >> 24) & 0xff; svga->changedvram[addr2 >> 12] = svga->monitor->mon_changeframecount; @@ -1696,39 +1729,39 @@ svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) } void -svga_writel(uint32_t addr, uint32_t val, void *p) +svga_writel(uint32_t addr, uint32_t val, void *priv) { - svga_writel_common(addr, val, 0, p); + svga_writel_common(addr, val, 0, priv); } void -svga_writel_linear(uint32_t addr, uint32_t val, void *p) +svga_writel_linear(uint32_t addr, uint32_t val, void *priv) { - svga_writel_common(addr, val, 1, p); + svga_writel_common(addr, val, 1, priv); } uint8_t -svga_readb_linear(uint32_t addr, void *p) +svga_readb_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + const svga_t *svga = (svga_t *) priv; if (!svga->fast) - return svga_read_linear(addr, p); + return svga_read_linear(addr, priv); addr &= svga->decode_mask; if (addr >= svga->vram_max) return 0xff; - return *(uint8_t *) &svga->vram[addr & svga->vram_mask]; + return *&svga->vram[addr & svga->vram_mask]; } uint16_t -svga_readw_common(uint32_t addr, uint8_t linear, void *p) +svga_readw_common(uint32_t addr, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) - return svga_read_common(addr, linear, p) | (svga_read_common(addr + 1, linear, p) << 8); + return svga_read_common(addr, linear, priv) | (svga_read_common(addr + 1, linear, priv) << 8); cycles -= svga->monitor->mon_video_timing_read_w; @@ -1741,12 +1774,12 @@ svga_readw_common(uint32_t addr, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - uint8_t val1 = 0xff; - uint8_t val2 = 0xff; - uint32_t addr2 = svga->translate_address(addr, p); + uint8_t val1 = 0xff; + uint8_t val2 = 0xff; + uint32_t addr2 = svga->translate_address(addr, priv); if (addr2 < svga->vram_max) val1 = svga->vram[addr2 & svga->vram_mask]; - addr2 = svga->translate_address(addr + 1, p); + addr2 = svga->translate_address(addr + 1, priv); if (addr2 < svga->vram_max) val2 = svga->vram[addr2 & svga->vram_mask]; return (val2 << 8) | val1; @@ -1758,24 +1791,24 @@ svga_readw_common(uint32_t addr, uint8_t linear, void *p) } uint16_t -svga_readw(uint32_t addr, void *p) +svga_readw(uint32_t addr, void *priv) { - return svga_readw_common(addr, 0, p); + return svga_readw_common(addr, 0, priv); } uint16_t -svga_readw_linear(uint32_t addr, void *p) +svga_readw_linear(uint32_t addr, void *priv) { - return svga_readw_common(addr, 1, p); + return svga_readw_common(addr, 1, priv); } uint32_t -svga_readl_common(uint32_t addr, uint8_t linear, void *p) +svga_readl_common(uint32_t addr, uint8_t linear, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; if (!svga->fast) { - return svga_read_common(addr, linear, p) | (svga_read_common(addr + 1, linear, p) << 8) | (svga_read_common(addr + 2, linear, p) << 16) | (svga_read_common(addr + 3, linear, p) << 24); + return svga_read_common(addr, linear, priv) | (svga_read_common(addr + 1, linear, priv) << 8) | (svga_read_common(addr + 2, linear, priv) << 16) | (svga_read_common(addr + 3, linear, priv) << 24); } cycles -= svga->monitor->mon_video_timing_read_l; @@ -1789,20 +1822,20 @@ svga_readl_common(uint32_t addr, uint8_t linear, void *p) addr &= svga->decode_mask; if (svga->translate_address) { - uint8_t val1 = 0xff; - uint8_t val2 = 0xff; - uint8_t val3 = 0xff; - uint8_t val4 = 0xff; - uint32_t addr2 = svga->translate_address(addr, p); + uint8_t val1 = 0xff; + uint8_t val2 = 0xff; + uint8_t val3 = 0xff; + uint8_t val4 = 0xff; + uint32_t addr2 = svga->translate_address(addr, priv); if (addr2 < svga->vram_max) val1 = svga->vram[addr2 & svga->vram_mask]; - addr2 = svga->translate_address(addr + 1, p); + addr2 = svga->translate_address(addr + 1, priv); if (addr2 < svga->vram_max) val2 = svga->vram[addr2 & svga->vram_mask]; - addr2 = svga->translate_address(addr + 2, p); + addr2 = svga->translate_address(addr + 2, priv); if (addr2 < svga->vram_max) val3 = svga->vram[addr2 & svga->vram_mask]; - addr2 = svga->translate_address(addr + 3, p); + addr2 = svga->translate_address(addr + 3, priv); if (addr2 < svga->vram_max) val4 = svga->vram[addr2 & svga->vram_mask]; return (val4 << 24) | (val3 << 16) | (val2 << 8) | val1; @@ -1814,13 +1847,13 @@ svga_readl_common(uint32_t addr, uint8_t linear, void *p) } uint32_t -svga_readl(uint32_t addr, void *p) +svga_readl(uint32_t addr, void *priv) { - return svga_readl_common(addr, 0, p); + return svga_readl_common(addr, 0, priv); } uint32_t -svga_readl_linear(uint32_t addr, void *p) +svga_readl_linear(uint32_t addr, void *priv) { - return svga_readl_common(addr, 1, p); + return svga_readl_common(addr, 1, priv); } diff --git a/src/video/vid_svga_render.c b/src/video/vid_svga_render.c index af4cb83da..c9369f09c 100644 --- a/src/video/vid_svga_render.c +++ b/src/video/vid_svga_render.c @@ -65,6 +65,9 @@ svga_render_blank(svga_t *svga) case 9: char_width = 16; break; + + default: + break; } uint32_t *line_ptr = &svga->monitor->target_buffer->line[svga->displine + svga->y_add][svga->x_add]; @@ -1305,7 +1308,7 @@ 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->ma + (x << 1)) & svga->vram_display_mask]); p[x << 1] = p[(x << 1) + 1] = (dat & 0x00008000) ? svga->pallook[dat & 0xff] : video_15to32[dat & 0xffff]; dat >>= 16; @@ -1386,7 +1389,7 @@ 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->ma + (x << 1)) & svga->vram_display_mask]); p[x << 1] = p[(x << 1) + 1] = video_16to32[dat & 0xffff]; p[(x << 1) + 2] = p[(x << 1) + 3] = video_16to32[dat >> 16]; diff --git a/src/video/vid_table.c b/src/video/vid_table.c index aaf407ca4..eb999eb3f 100644 --- a/src/video/vid_table.c +++ b/src/video/vid_table.c @@ -412,7 +412,7 @@ video_get_video_from_internal_name(char *s) int c = 0; while (video_cards[c].device != NULL) { - if (!strcmp((char *) video_cards[c].device->internal_name, s)) + if (!strcmp(video_cards[c].device->internal_name, s)) return c; c++; } diff --git a/src/video/vid_tgui9440.c b/src/video/vid_tgui9440.c index fc191b249..f659f90fe 100644 --- a/src/video/vid_tgui9440.c +++ b/src/video/vid_tgui9440.c @@ -169,17 +169,17 @@ typedef struct tgui_t { video_timings_t timing_tgui_vlb = { .type = VIDEO_BUS, .write_b = 4, .write_w = 8, .write_l = 16, .read_b = 4, .read_w = 8, .read_l = 16 }; video_timings_t timing_tgui_pci = { .type = VIDEO_PCI, .write_b = 4, .write_w = 8, .write_l = 16, .read_b = 4, .read_w = 8, .read_l = 16 }; -static void tgui_out(uint16_t addr, uint8_t val, void *p); -static uint8_t tgui_in(uint16_t addr, void *p); +static void tgui_out(uint16_t addr, uint8_t val, void *priv); +static uint8_t tgui_in(uint16_t addr, void *priv); static void tgui_recalcmapping(tgui_t *tgui); -static void tgui_accel_out(uint16_t addr, uint8_t val, void *p); -static void tgui_accel_out_w(uint16_t addr, uint16_t val, void *p); -static void tgui_accel_out_l(uint16_t addr, uint32_t val, void *p); -static uint8_t tgui_accel_in(uint16_t addr, void *p); -static uint16_t tgui_accel_in_w(uint16_t addr, void *p); -static uint32_t tgui_accel_in_l(uint16_t addr, void *p); +static void tgui_accel_out(uint16_t addr, uint8_t val, void *priv); +static void tgui_accel_out_w(uint16_t addr, uint16_t val, void *priv); +static void tgui_accel_out_l(uint16_t addr, uint32_t val, void *priv); +static uint8_t tgui_accel_in(uint16_t addr, void *priv); +static uint16_t tgui_accel_in_w(uint16_t addr, void *priv); +static uint32_t tgui_accel_in_l(uint16_t addr, void *priv); static uint8_t tgui_accel_read(uint32_t addr, void *priv); static uint16_t tgui_accel_read_w(uint32_t addr, void *priv); @@ -193,15 +193,15 @@ static void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *priv); static void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *priv); static void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *priv); -static uint8_t tgui_ext_linear_read(uint32_t addr, void *p); -static void tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p); -static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p); -static void tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *p); +static uint8_t tgui_ext_linear_read(uint32_t addr, void *priv); +static void tgui_ext_linear_write(uint32_t addr, uint8_t val, void *priv); +static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *priv); +static void tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *priv); -static uint8_t tgui_ext_read(uint32_t addr, void *p); -static void tgui_ext_write(uint32_t addr, uint8_t val, void *p); -static void tgui_ext_writew(uint32_t addr, uint16_t val, void *p); -static void tgui_ext_writel(uint32_t addr, uint32_t val, void *p); +static uint8_t tgui_ext_read(uint32_t addr, void *priv); +static void tgui_ext_write(uint32_t addr, uint8_t val, void *priv); +static void tgui_ext_writew(uint32_t addr, uint16_t val, void *priv); +static void tgui_ext_writel(uint32_t addr, uint32_t val, void *priv); /*Remap address for chain-4/doubleword style layout*/ static __inline uint32_t @@ -289,9 +289,9 @@ tgui_set_io(tgui_t *tgui) } static void -tgui_out(uint16_t addr, uint8_t val, void *p) +tgui_out(uint16_t addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint8_t old; @@ -531,9 +531,9 @@ tgui_out(uint16_t addr, uint8_t val, void *p) } static uint8_t -tgui_in(uint16_t addr, void *p) +tgui_in(uint16_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint8_t temp; @@ -624,7 +624,7 @@ tgui_in(uint16_t addr, void *p) void tgui_recalctimings(svga_t *svga) { - tgui_t *tgui = (tgui_t *) svga->p; + tgui_t *tgui = (tgui_t *) svga->priv; uint8_t ger22lower = tgui->accel.ger22 & 0xff; uint8_t ger22upper = (tgui->accel.ger22 >> 8); @@ -927,9 +927,9 @@ tgui_hwcursor_draw(svga_t *svga, int displine) } uint8_t -tgui_pci_read(int func, int addr, void *p) +tgui_pci_read(int func, int addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; switch (addr) { case 0x00: @@ -994,9 +994,9 @@ tgui_pci_read(int func, int addr, void *p) } void -tgui_pci_write(int func, int addr, uint8_t val, void *p) +tgui_pci_write(int func, int addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; switch (addr) { @@ -1064,10 +1064,10 @@ tgui_pci_write(int func, int addr, uint8_t val, void *p) } static uint8_t -tgui_ext_linear_read(uint32_t addr, void *p) +tgui_ext_linear_read(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; cycles -= video_timing_read_b; @@ -1087,9 +1087,9 @@ tgui_ext_linear_read(uint32_t addr, void *p) } static uint8_t -tgui_ext_read(uint32_t addr, void *p) +tgui_ext_read(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; addr = (addr & svga->banked_mask) + svga->read_bank; @@ -1097,10 +1097,10 @@ tgui_ext_read(uint32_t addr, void *p) } static void -tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p) +tgui_ext_linear_write(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; int c; uint8_t fg[2] = { tgui->ext_gdc_regs[4], tgui->ext_gdc_regs[5] }; uint8_t bg[2] = { tgui->ext_gdc_regs[1], tgui->ext_gdc_regs[2] }; @@ -1171,10 +1171,10 @@ tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p) } static void -tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p) +tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; int c; uint8_t fg[2] = { tgui->ext_gdc_regs[4], tgui->ext_gdc_regs[5] }; uint8_t bg[2] = { tgui->ext_gdc_regs[1], tgui->ext_gdc_regs[2] }; @@ -1247,33 +1247,33 @@ tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p) } static void -tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *p) +tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *priv) { - tgui_ext_linear_writew(addr, val, p); + tgui_ext_linear_writew(addr, val, priv); } static void -tgui_ext_write(uint32_t addr, uint8_t val, void *p) +tgui_ext_write(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; addr = (addr & svga->banked_mask) + svga->read_bank; tgui_ext_linear_write(addr, val, svga); } static void -tgui_ext_writew(uint32_t addr, uint16_t val, void *p) +tgui_ext_writew(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; addr = (addr & svga->banked_mask) + svga->read_bank; tgui_ext_linear_writew(addr, val, svga); } static void -tgui_ext_writel(uint32_t addr, uint32_t val, void *p) +tgui_ext_writel(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; addr = (addr & svga->banked_mask) + svga->read_bank; @@ -1995,9 +1995,9 @@ tgui_accel_command(int count, uint32_t cpu_dat, tgui_t *tgui) } static void -tgui_accel_out(uint16_t addr, uint8_t val, void *p) +tgui_accel_out(uint16_t addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; switch (addr) { case 0x2122: @@ -2339,17 +2339,17 @@ tgui_accel_out(uint16_t addr, uint8_t val, void *p) } static void -tgui_accel_out_w(uint16_t addr, uint16_t val, void *p) +tgui_accel_out_w(uint16_t addr, uint16_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; tgui_accel_out(addr, val, tgui); tgui_accel_out(addr + 1, val >> 8, tgui); } static void -tgui_accel_out_l(uint16_t addr, uint32_t val, void *p) +tgui_accel_out_l(uint16_t addr, uint32_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; switch (addr) { case 0x2124: /*Long version of Command and ROP together*/ @@ -2369,9 +2369,9 @@ tgui_accel_out_l(uint16_t addr, uint32_t val, void *p) } static uint8_t -tgui_accel_in(uint16_t addr, void *p) +tgui_accel_in(uint16_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; switch (addr) { case 0x2120: /*Status*/ @@ -2622,23 +2622,23 @@ tgui_accel_in(uint16_t addr, void *p) } static uint16_t -tgui_accel_in_w(uint16_t addr, void *p) +tgui_accel_in_w(uint16_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; return tgui_accel_in(addr, tgui) | (tgui_accel_in(addr + 1, tgui) << 8); } static uint32_t -tgui_accel_in_l(uint16_t addr, void *p) +tgui_accel_in_l(uint16_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; return tgui_accel_in_w(addr, tgui) | (tgui_accel_in_w(addr + 2, tgui) << 16); } static void -tgui_accel_write(uint32_t addr, uint8_t val, void *p) +tgui_accel_write(uint32_t addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; if ((svga->crtc[0x36] & 0x03) == 0x02) { @@ -2989,18 +2989,18 @@ tgui_accel_write(uint32_t addr, uint8_t val, void *p) } static void -tgui_accel_write_w(uint32_t addr, uint16_t val, void *p) +tgui_accel_write_w(uint32_t addr, uint16_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; tgui_accel_write(addr, val, tgui); tgui_accel_write(addr + 1, val >> 8, tgui); } static void -tgui_accel_write_l(uint32_t addr, uint32_t val, void *p) +tgui_accel_write_l(uint32_t addr, uint32_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; switch (addr & 0xff) { @@ -3026,9 +3026,9 @@ tgui_accel_write_l(uint32_t addr, uint32_t val, void *p) } static uint8_t -tgui_accel_read(uint32_t addr, void *p) +tgui_accel_read(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; if ((svga->crtc[0x36] & 0x03) == 0x02) { @@ -3288,24 +3288,26 @@ tgui_accel_read(uint32_t addr, void *p) } static uint16_t -tgui_accel_read_w(uint32_t addr, void *p) +tgui_accel_read_w(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; + return tgui_accel_read(addr, tgui) | (tgui_accel_read(addr + 1, tgui) << 8); } static uint32_t -tgui_accel_read_l(uint32_t addr, void *p) +tgui_accel_read_l(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; + return tgui_accel_read_w(addr, tgui) | (tgui_accel_read_w(addr + 2, tgui) << 16); } static void -tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *p) +tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; if (tgui->write_blitter) { tgui_accel_command(8, val << 24, tgui); @@ -3314,10 +3316,10 @@ tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *p) } static void -tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *p) +tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; if (tgui->write_blitter) tgui_accel_command(16, (((val & 0xff00) >> 8) | ((val & 0x00ff) << 8)) << 16, tgui); @@ -3326,10 +3328,10 @@ tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *p) } static void -tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *p) +tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; - tgui_t *tgui = (tgui_t *) svga->p; + svga_t *svga = (svga_t *) priv; + tgui_t *tgui = (tgui_t *) svga->priv; if (tgui->write_blitter) tgui_accel_command(32, ((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24), tgui); @@ -3338,63 +3340,63 @@ tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *p) } static void -tgui_mmio_write(uint32_t addr, uint8_t val, void *p) +tgui_mmio_write(uint32_t addr, uint8_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - tgui_accel_out(addr, val, p); + tgui_accel_out(addr, val, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - tgui_accel_write(addr, val, p); + tgui_accel_write(addr, val, priv); else - tgui_out(addr, val, p); + tgui_out(addr, val, priv); } static void -tgui_mmio_write_w(uint32_t addr, uint16_t val, void *p) +tgui_mmio_write_w(uint32_t addr, uint16_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - tgui_accel_out_w(addr, val, p); + tgui_accel_out_w(addr, val, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - tgui_accel_write_w(addr, val, p); + tgui_accel_write_w(addr, val, priv); else { - tgui_out(addr, val & 0xff, p); - tgui_out(addr + 1, val >> 8, p); + tgui_out(addr, val & 0xff, priv); + tgui_out(addr + 1, val >> 8, priv); } } static void -tgui_mmio_write_l(uint32_t addr, uint32_t val, void *p) +tgui_mmio_write_l(uint32_t addr, uint32_t val, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - tgui_accel_out_l(addr, val, p); + tgui_accel_out_l(addr, val, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - tgui_accel_write_l(addr, val, p); + tgui_accel_write_l(addr, val, priv); else { - tgui_out(addr, val & 0xff, p); - tgui_out(addr + 1, val >> 8, p); - tgui_out(addr + 2, val >> 16, p); - tgui_out(addr + 3, val >> 24, p); + tgui_out(addr, val & 0xff, priv); + tgui_out(addr + 1, val >> 8, priv); + tgui_out(addr + 2, val >> 16, priv); + tgui_out(addr + 3, val >> 24, priv); } } static uint8_t -tgui_mmio_read(uint32_t addr, void *p) +tgui_mmio_read(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint8_t ret = 0xff; @@ -3402,49 +3404,49 @@ tgui_mmio_read(uint32_t addr, void *p) addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - ret = tgui_accel_in(addr, p); + ret = tgui_accel_in(addr, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - ret = tgui_accel_read(addr, p); + ret = tgui_accel_read(addr, priv); else - ret = tgui_in(addr, p); + ret = tgui_in(addr, priv); return ret; } static uint16_t -tgui_mmio_read_w(uint32_t addr, void *p) +tgui_mmio_read_w(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint16_t ret = 0xffff; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - ret = tgui_accel_in_w(addr, p); + ret = tgui_accel_in_w(addr, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - ret = tgui_accel_read_w(addr, p); + ret = tgui_accel_read_w(addr, priv); else - ret = tgui_in(addr, p) | (tgui_in(addr + 1, p) << 8); + ret = tgui_in(addr, priv) | (tgui_in(addr + 1, priv) << 8); return ret; } static uint32_t -tgui_mmio_read_l(uint32_t addr, void *p) +tgui_mmio_read_l(uint32_t addr, void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_t *svga = &tgui->svga; uint32_t ret = 0xffffffff; addr &= 0x0000ffff; if (((svga->crtc[0x36] & 0x03) == 0x00) && (addr >= 0x2100 && addr <= 0x21ff)) - ret = tgui_accel_in_l(addr, p); + ret = tgui_accel_in_l(addr, priv); else if (((svga->crtc[0x36] & 0x03) > 0x00) && (addr <= 0xff)) - ret = tgui_accel_read_l(addr, p); + ret = tgui_accel_read_l(addr, priv); else - ret = tgui_in(addr, p) | (tgui_in(addr + 1, p) << 8) | (tgui_in(addr + 2, p) << 16) | (tgui_in(addr + 3, p) << 24); + ret = tgui_in(addr, priv) | (tgui_in(addr + 1, priv) << 8) | (tgui_in(addr + 2, priv) << 16) | (tgui_in(addr + 3, priv) << 24); return ret; } @@ -3556,9 +3558,9 @@ tgui96xx_available(void) } void -tgui_close(void *p) +tgui_close(void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_close(&tgui->svga); @@ -3571,17 +3573,17 @@ tgui_close(void *p) } void -tgui_speed_changed(void *p) +tgui_speed_changed(void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; svga_recalctimings(&tgui->svga); } void -tgui_force_redraw(void *p) +tgui_force_redraw(void *priv) { - tgui_t *tgui = (tgui_t *) p; + tgui_t *tgui = (tgui_t *) priv; tgui->svga.fullchange = changeframecount; } diff --git a/src/video/vid_tvga.c b/src/video/vid_tvga.c index 5cac5fb06..8483bbd33 100644 --- a/src/video/vid_tvga.c +++ b/src/video/vid_tvga.c @@ -74,9 +74,9 @@ static uint8_t crtc_mask[0x40] = { static void tvga_recalcbanking(tvga_t *tvga); void -tvga_out(uint16_t addr, uint8_t val, void *p) +tvga_out(uint16_t addr, uint8_t val, void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; svga_t *svga = &tvga->svga; uint8_t old; @@ -199,9 +199,9 @@ tvga_out(uint16_t addr, uint8_t val, void *p) } uint8_t -tvga_in(uint16_t addr, void *p) +tvga_in(uint16_t addr, void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; svga_t *svga = &tvga->svga; if (((addr & 0xFFF0) == 0x3D0 || (addr & 0xFFF0) == 0x3B0) && !(svga->miscout & 1)) @@ -261,7 +261,7 @@ tvga_recalcbanking(tvga_t *tvga) void tvga_recalctimings(svga_t *svga) { - tvga_t *tvga = (tvga_t *) svga->p; + tvga_t *tvga = (tvga_t *) svga->priv; int clksel; int high_res_256 = 0; @@ -458,9 +458,9 @@ tvga9000b_nec_sv9000_available(void) } void -tvga_close(void *p) +tvga_close(void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; svga_close(&tvga->svga); @@ -468,17 +468,17 @@ tvga_close(void *p) } void -tvga_speed_changed(void *p) +tvga_speed_changed(void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; svga_recalctimings(&tvga->svga); } void -tvga_force_redraw(void *p) +tvga_force_redraw(void *priv) { - tvga_t *tvga = (tvga_t *) p; + tvga_t *tvga = (tvga_t *) priv; tvga->svga.fullchange = changeframecount; } diff --git a/src/video/vid_tvp3026_ramdac.c b/src/video/vid_tvp3026_ramdac.c index 8a59f6e01..da75543ca 100644 --- a/src/video/vid_tvp3026_ramdac.c +++ b/src/video/vid_tvp3026_ramdac.c @@ -550,9 +550,9 @@ tvp3026_hwcursor_draw(svga_t *svga, int displine) } float -tvp3026_getclock(int clock, void *p) +tvp3026_getclock(int clock, void *priv) { - tvp3026_ramdac_t *ramdac = (tvp3026_ramdac_t *) p; + tvp3026_ramdac_t *ramdac = (tvp3026_ramdac_t *) priv; int n; int m; int pl; diff --git a/src/video/vid_vga.c b/src/video/vid_vga.c index ac26c2b5d..43b8a2750 100644 --- a/src/video/vid_vga.c +++ b/src/video/vid_vga.c @@ -35,9 +35,9 @@ static video_timings_t timing_ps1_svga_isa = { .type = VIDEO_ISA, .write_b = 6, static video_timings_t timing_ps1_svga_mca = { .type = VIDEO_MCA, .write_b = 6, .write_w = 8, .write_l = 16, .read_b = 6, .read_w = 8, .read_l = 16 }; void -vga_out(uint16_t addr, uint8_t val, void *p) +vga_out(uint16_t addr, uint8_t val, void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; svga_t *svga = &vga->svga; uint8_t old; @@ -69,14 +69,17 @@ vga_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } uint8_t -vga_in(uint16_t addr, void *p) +vga_in(uint16_t addr, void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; svga_t *svga = &vga->svga; uint8_t temp; @@ -157,9 +160,9 @@ vga_available(void) } void -vga_close(void *p) +vga_close(void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; svga_close(&vga->svga); @@ -167,17 +170,17 @@ vga_close(void *p) } void -vga_speed_changed(void *p) +vga_speed_changed(void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; svga_recalctimings(&vga->svga); } void -vga_force_redraw(void *p) +vga_force_redraw(void *priv) { - vga_t *vga = (vga_t *) p; + vga_t *vga = (vga_t *) priv; vga->svga.fullchange = changeframecount; } diff --git a/src/video/vid_voodoo.c b/src/video/vid_voodoo.c index 6544246be..610e15e6c 100644 --- a/src/video/vid_voodoo.c +++ b/src/video/vid_voodoo.c @@ -149,9 +149,9 @@ voodoo_recalc(voodoo_t *voodoo) } static uint16_t -voodoo_readw(uint32_t addr, void *p) +voodoo_readw(uint32_t addr, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; addr &= 0xffffff; @@ -184,9 +184,9 @@ voodoo_readw(uint32_t addr, void *p) } static uint32_t -voodoo_readl(uint32_t addr, void *p) +voodoo_readl(uint32_t addr, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; uint32_t temp = 0xffffffff; int fifo_size; voodoo->rd_count++; @@ -394,9 +394,9 @@ voodoo_readl(uint32_t addr, void *p) } static void -voodoo_writew(uint32_t addr, uint16_t val, void *p) +voodoo_writew(uint32_t addr, uint16_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; voodoo->wr_count++; addr &= 0xffffff; @@ -407,9 +407,9 @@ voodoo_writew(uint32_t addr, uint16_t val, void *p) } static void -voodoo_writel(uint32_t addr, uint32_t val, void *p) +voodoo_writel(uint32_t addr, uint32_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; voodoo->wr_count++; @@ -670,32 +670,32 @@ voodoo_writel(uint32_t addr, uint32_t val, void *p) } static uint16_t -voodoo_snoop_readw(uint32_t addr, void *p) +voodoo_snoop_readw(uint32_t addr, void *priv) { - voodoo_set_t *set = (voodoo_set_t *) p; + voodoo_set_t *set = (voodoo_set_t *) priv; return voodoo_readw(addr, set->voodoos[0]); } static uint32_t -voodoo_snoop_readl(uint32_t addr, void *p) +voodoo_snoop_readl(uint32_t addr, void *priv) { - voodoo_set_t *set = (voodoo_set_t *) p; + voodoo_set_t *set = (voodoo_set_t *) priv; return voodoo_readl(addr, set->voodoos[0]); } static void -voodoo_snoop_writew(uint32_t addr, uint16_t val, void *p) +voodoo_snoop_writew(uint32_t addr, uint16_t val, void *priv) { - voodoo_set_t *set = (voodoo_set_t *) p; + voodoo_set_t *set = (voodoo_set_t *) priv; voodoo_writew(addr, val, set->voodoos[0]); voodoo_writew(addr, val, set->voodoos[1]); } static void -voodoo_snoop_writel(uint32_t addr, uint32_t val, void *p) +voodoo_snoop_writel(uint32_t addr, uint32_t val, void *priv) { - voodoo_set_t *set = (voodoo_set_t *) p; + voodoo_set_t *set = (voodoo_set_t *) priv; voodoo_writel(addr, val, set->voodoos[0]); voodoo_writel(addr, val, set->voodoos[1]); @@ -747,14 +747,16 @@ voodoo_recalcmapping(voodoo_set_t *set) } uint8_t -voodoo_pci_read(int func, int addr, void *p) +voodoo_pci_read(int func, int addr, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; if (func) return 0; - // voodoo_log("Voodoo PCI read %08X PC=%08x\n", addr, cpu_state.pc); +#if 0 + voodoo_log("Voodoo PCI read %08X PC=%08x\n", addr, cpu_state.pc); +#endif switch (addr) { case 0x00: @@ -806,14 +808,16 @@ voodoo_pci_read(int func, int addr, void *p) } void -voodoo_pci_write(int func, int addr, uint8_t val, void *p) +voodoo_pci_write(int func, int addr, uint8_t val, void *priv) { - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; if (func) return; - // voodoo_log("Voodoo PCI write %04X %02X PC=%08x\n", addr, val, cpu_state.pc); +#if 0 + voodoo_log("Voodoo PCI write %04X %02X PC=%08x\n", addr, val, cpu_state.pc); +#endif switch (addr) { case 0x04: @@ -844,9 +848,9 @@ voodoo_pci_write(int func, int addr, uint8_t val, void *p) } static void -voodoo_speed_changed(void *p) +voodoo_speed_changed(void *priv) { - voodoo_set_t *voodoo_set = (voodoo_set_t *) p; + voodoo_set_t *voodoo_set = (voodoo_set_t *) priv; voodoo_pixelclock_update(voodoo_set->voodoos[0]); voodoo_set->voodoos[0]->read_time = pci_nonburst_time + pci_burst_time * ((voodoo_set->voodoos[0]->fbiInit4 & 1) ? 2 : 1); @@ -858,13 +862,15 @@ voodoo_speed_changed(void *p) voodoo_set->voodoos[1]->write_time = pci_nonburst_time + pci_burst_time * ((voodoo_set->voodoos[1]->fbiInit1 & 2) ? 1 : 0); voodoo_set->voodoos[1]->burst_time = pci_burst_time * ((voodoo_set->voodoos[1]->fbiInit1 & 2) ? 2 : 1); } - // voodoo_log("Voodoo read_time=%i write_time=%i burst_time=%i %08x %08x\n", voodoo->read_time, voodoo->write_time, voodoo->burst_time, voodoo->fbiInit1, voodoo->fbiInit4); +#if 0 + voodoo_log("Voodoo read_time=%i write_time=%i burst_time=%i %08x %08x\n", voodoo->read_time, voodoo->write_time, voodoo->burst_time, voodoo->fbiInit1, voodoo->fbiInit4); +#endif } static void -voodoo_force_blit(void *p) +voodoo_force_blit(void *priv) { - voodoo_set_t *voodoo_set = (voodoo_set_t *) p; + voodoo_set_t *voodoo_set = (voodoo_set_t *) priv; thread_wait_mutex(voodoo_set->voodoos[0]->force_blit_mutex); if (voodoo_set->voodoos[0]->can_blit) { @@ -1261,9 +1267,9 @@ voodoo_card_close(voodoo_t *voodoo) } void -voodoo_close(void *p) +voodoo_close(void *priv) { - voodoo_set_t *voodoo_set = (voodoo_set_t *) p; + voodoo_set_t *voodoo_set = (voodoo_set_t *) priv; if (voodoo_set->nr_cards == 2) voodoo_card_close(voodoo_set->voodoos[1]); diff --git a/src/video/vid_voodoo_banshee.c b/src/video/vid_voodoo_banshee.c index 4fcd6af61..0b3a3a043 100644 --- a/src/video/vid_voodoo_banshee.c +++ b/src/video/vid_voodoo_banshee.c @@ -315,7 +315,7 @@ banshee_update_irqs(banshee_t *banshee) static void banshee_vblank_start(svga_t *svga) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; if (banshee->vblank_irq >= 0) { banshee->vblank_irq = 1; banshee_update_irqs(banshee); @@ -460,7 +460,7 @@ banshee_updatemapping(banshee_t *banshee) static void banshee_render_16bpp_tiled(svga_t *svga) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; uint32_t *p = &((uint32_t *) svga->monitor->target_buffer->line[svga->displine + svga->y_add])[svga->x_add]; uint32_t addr; int drawn = 0; @@ -500,7 +500,7 @@ banshee_render_16bpp_tiled(svga_t *svga) static void banshee_recalctimings(svga_t *svga) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; voodoo_t *voodoo = banshee->voodoo; /*7 R/W Horizontal Retrace End bit 5. - @@ -1981,7 +1981,7 @@ banshee_write_linear_l(uint32_t addr, uint32_t val, void *priv) void banshee_hwcursor_draw(svga_t *svga, int displine) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; int x; int x_off; int xx; @@ -2329,7 +2329,7 @@ voodoo_generate_vb_filters(voodoo_t *voodoo, int fcr, int fcg) static void banshee_overlay_draw(svga_t *svga, int displine) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; voodoo_t *voodoo = banshee->voodoo; uint32_t *p; int x; @@ -2581,7 +2581,7 @@ banshee_set_overlay_addr(void *priv, UNUSED(uint32_t addr)) static void banshee_vsync_callback(svga_t *svga) { - banshee_t *banshee = (banshee_t *) svga->p; + banshee_t *banshee = (banshee_t *) svga->priv; voodoo_t *voodoo = banshee->voodoo; voodoo->retrace_count++; diff --git a/src/video/vid_voodoo_texture.c b/src/video/vid_voodoo_texture.c index d02041d16..8b8f1366d 100644 --- a/src/video/vid_voodoo_texture.c +++ b/src/video/vid_voodoo_texture.c @@ -585,12 +585,12 @@ flush_texture_cache(voodoo_t *voodoo, uint32_t dirty_addr, int tmu) } void -voodoo_tex_writel(uint32_t addr, uint32_t val, void *p) +voodoo_tex_writel(uint32_t addr, uint32_t val, void *priv) { int lod; int s; int t; - voodoo_t *voodoo = (voodoo_t *) p; + voodoo_t *voodoo = (voodoo_t *) priv; int tmu; if (addr & 0x400000) diff --git a/src/video/vid_wy700.c b/src/video/vid_wy700.c index c81a41de8..6695709cc 100644 --- a/src/video/vid_wy700.c +++ b/src/video/vid_wy700.c @@ -216,16 +216,16 @@ static int cgacols[256][2][2]; static int mdacols[256][2][2]; void wy700_recalctimings(wy700_t *wy700); -void wy700_write(uint32_t addr, uint8_t val, void *p); -uint8_t wy700_read(uint32_t addr, void *p); +void wy700_write(uint32_t addr, uint8_t val, void *priv); +uint8_t wy700_read(uint32_t addr, void *priv); void wy700_checkchanges(wy700_t *wy700); static video_timings_t timing_wy700 = { .type = VIDEO_ISA, .write_b = 8, .write_w = 16, .write_l = 32, .read_b = 8, .read_w = 16, .read_l = 32 }; void -wy700_out(uint16_t addr, uint8_t val, void *p) +wy700_out(uint16_t addr, uint8_t val, void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; switch (addr) { /* These three registers are only mapped in the 3Dx range, * not the 3Bx range. */ @@ -287,9 +287,9 @@ wy700_out(uint16_t addr, uint8_t val, void *p) } uint8_t -wy700_in(uint16_t addr, void *p) +wy700_in(uint16_t addr, void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; switch (addr) { case 0x3b0: case 0x3b2: @@ -456,9 +456,9 @@ wy700_checkchanges(wy700_t *wy700) } void -wy700_write(uint32_t addr, uint8_t val, void *p) +wy700_write(uint32_t addr, uint8_t val, void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; if (wy700->wy700_mode & 0x80) /* High-res mode. */ { @@ -475,9 +475,9 @@ wy700_write(uint32_t addr, uint8_t val, void *p) } uint8_t -wy700_read(uint32_t addr, void *p) +wy700_read(uint32_t addr, void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; if (wy700->wy700_mode & 0x80) /* High-res mode. */ { addr &= 0xFFFF; @@ -745,9 +745,9 @@ wy700_hiresline(wy700_t *wy700) } void -wy700_poll(void *p) +wy700_poll(void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; int mode; if (!wy700->linepos) { @@ -959,18 +959,18 @@ wy700_init(const device_t *info) } void -wy700_close(void *p) +wy700_close(void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; free(wy700->vram); free(wy700); } void -wy700_speed_changed(void *p) +wy700_speed_changed(void *priv) { - wy700_t *wy700 = (wy700_t *) p; + wy700_t *wy700 = (wy700_t *) priv; wy700_recalctimings(wy700); } diff --git a/src/video/vid_xga.c b/src/video/vid_xga.c index e4f91bb00..350fc1c50 100644 --- a/src/video/vid_xga.c +++ b/src/video/vid_xga.c @@ -34,23 +34,27 @@ #include <86box/vid_svga_render.h> #include <86box/vid_xga_device.h> #include "cpu.h" +#include <86box/plat_unused.h> -#define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" -#define XGA2_BIOS_PATH "roms/video/xga/xga2_v300.bin" +#define XGA_BIOS_PATH "roms/video/xga/XGA_37F9576_Ver200.BIN" +#define XGA2_BIOS_PATH "roms/video/xga/xga2_v300.bin" #define INMOS_XGA_BIOS_PATH "roms/video/xga/InMOS XGA - Fairchild NM27C256Q-150.BIN" static 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 *p); -static uint8_t xga_ext_inb(uint16_t addr, void *p); +static void xga_ext_outb(uint16_t addr, uint8_t val, void *priv); +static uint8_t xga_ext_inb(uint16_t addr, void *priv); + +static void xga_writew(uint32_t addr, uint16_t val, void *priv); +static uint16_t xga_readw(uint32_t addr, void *priv); int xga_has_vga = 0; void -svga_xga_out(uint16_t addr, uint8_t val, void *p) +svga_xga_out(uint16_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *) priv; uint8_t old; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -81,14 +85,17 @@ svga_xga_out(uint16_t addr, uint8_t val, void *p) } } break; + + default: + break; } svga_out(addr, val, svga); } uint8_t -svga_xga_in(uint16_t addr, void *p) +svga_xga_in(uint16_t addr, void *priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *) priv; uint8_t temp; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -116,7 +123,9 @@ xga_updatemapping(svga_t *svga) { xga_t *xga = &svga->xga; - //pclog("OpMode = %x, linear base = %08x, aperture cntl = %d, access mode = %x, map = %x, endian reverse = %d, a5test = %d, XGA on = %d.\n", xga->op_mode, xga->linear_base, xga->aperture_cntl, xga->access_mode, svga->gdcreg[6] & 0x0c, xga->linear_endian_reverse, xga->a5_test, xga->on); +#if 0 + pclog("OpMode = %x, linear base = %08x, aperture cntl = %d, access mode = %x, map = %x, endian reverse = %d, a5test = %d, XGA on = %d.\n", xga->op_mode, xga->linear_base, xga->aperture_cntl, xga->access_mode, svga->gdcreg[6] & 0x0c, xga->linear_endian_reverse, xga->a5_test, xga->on); +#endif if (((xga->op_mode & 7) >= 4) || ((xga->op_mode & 7) == 0)) { if ((xga->aperture_cntl == 1) || (xga->aperture_cntl == 2)) { mem_mapping_disable(&svga->mapping); @@ -148,9 +157,13 @@ xga_updatemapping(svga_t *svga) vga_on = !xga->on; } } - //pclog("XGA opmode (extended) = %d, disp mode = %d, aperture = %d.\n", xga->op_mode & 7, xga->disp_cntl_2 & 7, xga->aperture_cntl); +#if 0 + pclog("XGA opmode (extended) = %d, disp mode = %d, aperture = %d.\n", xga->op_mode & 7, xga->disp_cntl_2 & 7, xga->aperture_cntl); +#endif } - //pclog("VGA on = %d.\n", vga_on); +#if 0 + pclog("VGA on = %d.\n", vga_on); +#endif } void @@ -185,16 +198,19 @@ xga_recalctimings(svga_t *svga) switch ((xga->clk_sel_1 >> 2) & 3) { case 0: if (xga->clk_sel_2 & 0x80) { - svga->clock = (cpuclock * (double) (1ull << 32)) / 41539000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 41539000.0; } else { - svga->clock = (cpuclock * (double) (1ull << 32)) / 25175000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 25175000.0; } break; case 1: - svga->clock = (cpuclock * (double) (1ull << 32)) / 28322000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 28322000.0; break; case 3: - svga->clock = (cpuclock * (double) (1ull << 32)) / 44900000.0; + svga->clock = (cpuclock * (double) (1ULL << 32)) / 44900000.0; + break; + + default: break; } } @@ -340,8 +356,8 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) case 0x51: xga->disp_cntl_2 = val; - xga->on = ((val & 7) >= 3); - vga_on = !xga->on; + xga->on = ((val & 7) >= 3); + vga_on = !xga->on; svga_recalctimings(svga); break; @@ -350,6 +366,10 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) svga_recalctimings(svga); break; + case 0x55: + xga->border_color = val; + break; + case 0x59: xga->direct_color = val; break; @@ -383,7 +403,9 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) xga->cursor_data_on = 0; } } - // pclog("Sprite POS = %d, data on = %d, idx = %d, apcntl = %d\n", xga->sprite_pos, xga->cursor_data_on, xga->sprite_pal_addr_idx, xga->aperture_cntl); +#if 0 + pclog("Sprite POS = %d, data on = %d, idx = %d, apcntl = %d\n", xga->sprite_pos, xga->cursor_data_on, xga->sprite_pal_addr_idx, xga->aperture_cntl); +#endif break; case 0x62: @@ -421,6 +443,9 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) svga->dac_pos = 0; svga->dac_addr = (svga->dac_addr + 1) & 0xff; break; + + default: + break; } break; @@ -447,16 +472,21 @@ xga_ext_out_reg(xga_t *xga, svga_t *svga, uint8_t idx, uint8_t val) xga->clk_sel_2 = val; svga_recalctimings(svga); break; + + default: + break; } } static void -xga_ext_outb(uint16_t addr, uint8_t val, void *p) +xga_ext_outb(uint16_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; - //pclog("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); +#if 0 + pclog("[%04X:%08X]: EXT OUTB = %02x, val = %02x\n", CS, cpu_state.pc, addr, val); +#endif switch (addr & 0x0f) { case 0: xga->op_mode = val; @@ -470,11 +500,11 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *p) if ((xga->disp_cntl_2 & 7) == 4) xga->aperture_cntl = 0; break; - case 6: - break; case 8: xga->ap_idx = val; - //pclog("Aperture CNTL = %d, val = %02x, up to bit6 = %02x\n", xga->aperture_cntl, val, val & 0x3f); +#if 0 + pclog("Aperture CNTL = %d, val = %02x, up to bit6 = %02x\n", xga->aperture_cntl, val, val & 0x3f); +#endif if ((xga->op_mode & 7) < 4) { xga->write_bank = xga->read_bank = 0; } else { @@ -496,15 +526,18 @@ xga_ext_outb(uint16_t addr, uint8_t val, void *p) xga->regs[xga->regs_idx] = val; xga_ext_out_reg(xga, svga, xga->regs_idx, xga->regs[xga->regs_idx]); break; + + default: + break; } } static uint8_t -xga_ext_inb(uint16_t addr, void *p) +xga_ext_inb(uint16_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; - uint8_t ret; + uint8_t ret = 0; uint8_t index; switch (addr & 0x0f) { @@ -646,6 +679,9 @@ xga_ext_inb(uint16_t addr, void *p) case 0x54: ret = xga->clk_sel_1; break; + case 0x55: + ret = xga->border_color; + break; case 0x59: ret = xga->direct_color; @@ -685,6 +721,9 @@ xga_ext_inb(uint16_t addr, void *p) svga->dac_addr = (svga->dac_addr + 1) & 0xff; ret = svga->vgapal[index].b; break; + + default: + break; } break; @@ -703,7 +742,9 @@ xga_ext_inb(uint16_t addr, void *p) break; case 0x6a: - // pclog("Sprite POS Read = %d, addr idx = %04x\n", xga->sprite_pos, xga->sprite_pal_addr_idx_prefetch); +#if 0 + pclog("Sprite POS Read = %d, addr idx = %04x\n", xga->sprite_pos, xga->sprite_pal_addr_idx_prefetch); +#endif ret = xga->sprite_data[xga->sprite_pos_prefetch]; xga->sprite_pos_prefetch = (xga->sprite_pos_prefetch + 1) & 0x3ff; break; @@ -727,9 +768,15 @@ xga_ext_inb(uint16_t addr, void *p) break; } break; + + default: + break; } - //pclog("[%04X:%08X]: EXT INB = %02x, ret = %02x\n", CS, cpu_state.pc, addr, ret); +#if 0 + pclog("[%04X:%08X]: EXT INB = %02x, ret = %02x\n", CS, cpu_state.pc, addr, ret); +#endif + return ret; } @@ -743,37 +790,17 @@ xga_ext_inb(uint16_t addr, void *p) #define READW(addr, dat) \ dat = *(uint16_t *) &xga->vram[(addr) & (xga->vram_mask)]; -#define READW_REVERSE(addr, dat) \ - dat = xga->vram[(addr + 1) & (xga->vram_mask - 1)] & 0xff; \ - dat |= (xga->vram[(addr) & (xga->vram_mask - 1)] << 8); - -#define READL(addr, dat) \ - dat = *(uint32_t *) &xga->vram[(addr) & (xga->vram_mask)]; - -#define READL_REVERSE(addr, dat) \ - dat = xga->vram[(addr + 3) & (xga->vram_mask - 3)] & 0xff; \ - dat |= (xga->vram[(addr + 2) & (xga->vram_mask - 3)] << 8); \ - dat |= (xga->vram[(addr + 1) & (xga->vram_mask - 3)] << 16); \ - dat |= (xga->vram[(addr) & (xga->vram_mask - 3)] << 24); +#define READW_INV(addr, dat) \ + dat = xga->vram[(addr + 1) & (xga->vram_mask)]; \ + dat |= (xga->vram[(addr) & (xga->vram_mask)] << 8); #define WRITEW(addr, dat) \ *(uint16_t *) &xga->vram[((addr)) & (xga->vram_mask)] = dat; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; -#define WRITEL(addr, dat) \ - *(uint32_t *) &xga->vram[((addr)) & (xga->vram_mask)] = dat; \ - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; - -#define WRITEW_REVERSE(addr, dat) \ - xga->vram[((addr + 1)) & (xga->vram_mask - 1)] = dat & 0xff; \ - xga->vram[((addr)) & (xga->vram_mask - 1)] = dat >> 8; \ - xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; - -#define WRITEL_REVERSE(addr, dat) \ - xga->vram[((addr + 3)) & (xga->vram_mask - 3)] = dat & 0xff; \ - xga->vram[((addr + 2)) & (xga->vram_mask - 3)] = dat >> 8; \ - xga->vram[((addr + 1)) & (xga->vram_mask - 3)] = dat >> 16; \ - xga->vram[((addr)) & (xga->vram_mask - 3)] = dat >> 24; \ +#define WRITEW_INV(addr, dat) \ + xga->vram[((addr + 1)) & (xga->vram_mask)] = dat & 0xff; \ + xga->vram[((addr)) & (xga->vram_mask)] = dat >> 8; \ xga->changedvram[(((addr)) & (xga->vram_mask)) >> 12] = svga->monitor->mon_changeframecount; #define ROP(mix, d, s) \ @@ -851,12 +878,12 @@ xga_ext_inb(uint16_t addr, void *p) static uint32_t xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width) { - xga_t *xga = &svga->xga; - uint32_t addr = base; - int bits; - uint32_t byte; - uint8_t px; - int skip = 0; + const xga_t *xga = &svga->xga; + uint32_t addr = base; + int bits; + uint32_t byte; + uint8_t px; + int skip = 0; if (xga->base_addr_1mb) { if (addr < xga->base_addr_1mb || (addr > (xga->base_addr_1mb + 0xfffff))) @@ -873,20 +900,21 @@ xga_accel_read_pattern_map_pixel(svga_t *svga, int x, int y, int map, uint32_t b } else { byte = mem_readb_phys(addr); } - if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) - if (xga->linear_endian_reverse) - bits = 7 - (x & 7); - else - bits = (x & 7); - else { + if (xga->linear_endian_reverse) { bits = 7 - (x & 7); + } else { + if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) + bits = (x & 7); + else { + bits = 7 - (x & 7); + } } px = (byte >> bits) & 1; return px; } static uint32_t -xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width) +xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int width, UNUSED(int usesrc)) { xga_t *xga = &svga->xga; uint32_t addr = base; @@ -912,13 +940,14 @@ xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int } else { byte = mem_readb_phys(addr); } - if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) - if (xga->linear_endian_reverse) - bits = 7 - (x & 7); - else - bits = (x & 7); - else { + if (xga->linear_endian_reverse) { bits = 7 - (x & 7); + } else { + if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) + bits = (x & 7); + else { + bits = 7 - (x & 7); + } } px = (byte >> bits) & 1; return px; @@ -934,39 +963,24 @@ xga_accel_read_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, int case 4: /*16-bit*/ addr += (y * (width << 1)); addr += (x << 1); - if (!skip) { - if (xga->accel.px_map_format[map] & 8) { - if (xga->linear_endian_reverse) { - READW(addr, byte); - } else { - READW_REVERSE(addr, byte); - } - } else { - READW(addr, byte); - } - } else { + if (xga->linear_endian_reverse) { byte = mem_readw_phys(addr); - } - return byte; - case 5: /*24-bit*/ - addr += (y * (width << 2)); - addr += (x << 2); - if (!skip) { - if ((xga->accel.px_map_format[map] & 8)) { - if (xga->linear_endian_reverse) { - READL(addr, byte); - } else { - READL_REVERSE(addr, byte); - } - } else { - READL(addr, byte); - } + if ((xga->access_mode & 7) == 4) + byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); + else if (xga->access_mode & 8) + byte = ((byte & 0xff00) >> 8) | ((byte & 0x00ff) << 8); } else { - byte = mem_readl_phys(addr); + if (!skip) { + READW(addr, byte); + } else { + byte = mem_readb_phys(addr) | (mem_readb_phys(addr + 1) << 8); + } } return byte; - } + default: + break; + } return 0; } @@ -996,13 +1010,14 @@ xga_accel_write_map_pixel(svga_t *svga, int x, int y, int map, uint32_t base, ui } else { byte = mem_readb_phys(addr); } - if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) { - if (xga->linear_endian_reverse) - mask = 1 << (7 - (x & 7)); - else - mask = 1 << (x & 7); - } else { + if (xga->linear_endian_reverse) { mask = 1 << (7 - (x & 7)); + } else { + if ((xga->accel.px_map_format[map] & 8) && !(xga->access_mode & 8)) { + mask = 1 << (x & 7); + } else { + mask = 1 << (7 - (x & 7)); + } } byte = (byte & ~mask) | ((pixel ? 0xff : 0) & mask); if (pixel & 1) { @@ -1029,34 +1044,22 @@ 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 (!skip) { - if (xga->accel.px_map_format[map] & 8) { - if (xga->linear_endian_reverse) { - WRITEW(addr, pixel); - } else { - WRITEW_REVERSE(addr, pixel); - } - } else { + if (xga->linear_endian_reverse) { + if ((xga->access_mode & 7) == 4) + pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); + else if (xga->access_mode & 8) + pixel = ((pixel & 0xff00) >> 8) | ((pixel & 0x00ff) << 8); + + mem_writew_phys(addr, pixel); + } else { + if (!skip) { WRITEW(addr, pixel); } + mem_writew_phys(addr, pixel); } - mem_writew_phys(addr, pixel); break; - case 5: /*24-bit*/ - addr += (y * (width) << 2); - addr += (x << 2); - if (!skip) { - if ((xga->accel.px_map_format[map] & 8)) { - if (xga->linear_endian_reverse) { - WRITEL(addr, pixel); - } else { - WRITEL_REVERSE(addr, pixel); - } - } else { - WRITEL(addr, pixel); - } - } - mem_writel_phys(addr, pixel); + + default: break; } } @@ -1080,11 +1083,11 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) int diry = 0; dx = xga->accel.dst_map_x & 0x1fff; - if (xga->accel.dst_map_x & 0x1800) + if (xga->accel.dst_map_x >= 0x1800) dx |= ~0x17ff; dy = xga->accel.dst_map_y & 0x1fff; - if (xga->accel.dst_map_y & 0x1800) + if (xga->accel.dst_map_y >= 0x1800) dy |= ~0x17ff; switch ((ssv >> 5) & 7) { @@ -1120,14 +1123,17 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) dirx = 1; diry = 1; break; + + default: + break; } if (xga->accel.pat_src == 8) { while (y >= 0) { if (xga->accel.command & 0xc0) { if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1146,8 +1152,8 @@ xga_short_stroke(svga_t *svga, uint8_t ssv) } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1211,18 +1217,18 @@ xga_line_draw_write(svga_t *svga) int dx; int dy; - dminor = ((int16_t) xga->accel.bres_k1); + dminor = (xga->accel.bres_k1); if (xga->accel.bres_k1 & 0x2000) dminor |= ~0x1fff; dminor >>= 1; - destxtmp = ((int16_t) xga->accel.bres_k2); + destxtmp = (xga->accel.bres_k2); if (xga->accel.bres_k2 & 0x2000) destxtmp |= ~0x1fff; dmajor = -(destxtmp - (dminor << 1)) >> 1; - err = ((int16_t) xga->accel.bres_err_term); + err = (xga->accel.bres_err_term); if (xga->accel.bres_err_term & 0x2000) destxtmp |= ~0x1fff; @@ -1239,11 +1245,11 @@ xga_line_draw_write(svga_t *svga) } dx = xga->accel.dst_map_x & 0x1fff; - if (xga->accel.dst_map_x & 0x1800) + if (xga->accel.dst_map_x >= 0x1800) dx |= ~0x17ff; dy = xga->accel.dst_map_y & 0x1fff; - if (xga->accel.dst_map_y & 0x1800) + if (xga->accel.dst_map_y >= 0x1800) dy |= ~0x17ff; if (xga->accel.octant & 0x01) { @@ -1257,8 +1263,8 @@ xga_line_draw_write(svga_t *svga) if (xga->accel.command & 0xc0) { if (steep) { if ((dx >= xga->accel.mask_map_origin_x_off) && (dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dy >= xga->accel.mask_map_origin_y_off) && (dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1274,8 +1280,8 @@ xga_line_draw_write(svga_t *svga) } } else { if ((dy >= xga->accel.mask_map_origin_x_off) && (dy <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (dx >= xga->accel.mask_map_origin_y_off) && (dx <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1292,8 +1298,8 @@ xga_line_draw_write(svga_t *svga) } } else { if (steep) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1307,8 +1313,8 @@ xga_line_draw_write(svga_t *svga) xga_accel_write_map_pixel(svga, dx, dy, xga->accel.dst_map, dstbase, dest_dat, xga->accel.px_map_width[xga->accel.dst_map] + 1); } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1); + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.src_map_x & 0xfff, xga->accel.src_map_y & 0xfff, xga->accel.src_map, srcbase, xga->accel.px_map_width[xga->accel.src_map] + 1, 1) : xga->accel.frgd_color; + dest_dat = xga_accel_read_map_pixel(svga, dy, dx, xga->accel.dst_map, dstbase, xga->accel.px_map_width[xga->accel.dst_map] + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; @@ -1350,13 +1356,6 @@ xga_line_draw_write(svga_t *svga) } } -static int16_t -xga_dst_wrap(int16_t addr) -{ - addr &= 0x1fff; - return (addr & 0x1800) == 0x1800 ? (addr | 0xf800) : addr; -} - static void xga_bitblt(svga_t *svga) { @@ -1374,7 +1373,12 @@ xga_bitblt(svga_t *svga) uint32_t srcwidth = xga->accel.px_map_width[xga->accel.src_map]; uint32_t patheight = xga->accel.px_map_height[xga->accel.pat_src]; uint32_t srcheight = xga->accel.px_map_height[xga->accel.src_map]; - int mix = 0; +#if 0 + uint32_t dstheight = xga->accel.px_map_height[xga->accel.dst_map]; +#endif + uint32_t frgdcol = xga->accel.frgd_color; + uint32_t bkgdcol = xga->accel.bkgd_color; + int mix = 0; int xdir; int ydir; @@ -1397,11 +1401,20 @@ xga_bitblt(svga_t *svga) xga->accel.sy = xga->accel.src_map_y & 0xfff; xga->accel.px = xga->accel.pat_map_x & 0xfff; xga->accel.py = xga->accel.pat_map_y & 0xfff; - xga->accel.dx = xga_dst_wrap(xga->accel.dst_map_x); - xga->accel.dy = xga_dst_wrap(xga->accel.dst_map_y); + xga->accel.dx = xga->accel.dst_map_x & 0x1fff; + if (xga->accel.dst_map_x >= 0x1800) + xga->accel.dx |= ~0x17ff; + xga->accel.dy = xga->accel.dst_map_y & 0x1fff; + if (xga->accel.dst_map_y >= 0x1800) + xga->accel.dy |= ~0x17ff; xga->accel.pattern = 0; +#if 0 + pclog("XGA bitblt linear endian reverse=%d, access_mode=%x, octanty=%d, src command = %08x, pxsrcmap=%x, pxpatmap=%x, pxdstmap=%x, srcmap=%d, patmap=%d, dstmap=%d, usesrcvramfr=%d, usevrambk=%d.\n", + xga->linear_endian_reverse, xga->access_mode & 0x0f, ydir, xga->accel.command, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.px_map_format[xga->accel.pat_src] & 0x0f, xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.src_map, xga->accel.pat_src, xga->accel.dst_map, ((xga->accel.command >> 28) & 3), ((xga->accel.command >> 30) & 3)); +#endif + if (xga->accel.pat_src == 8) { if (srcheight == 7) xga->accel.pattern = 1; @@ -1414,15 +1427,15 @@ xga_bitblt(svga_t *svga) } } } - - // pclog("Pattern Map = 8: CMD = %08x: SRCBase = %08x, DSTBase = %08x, from/to vram dir = %d, cmd dir = %06x\n", xga->accel.command, srcbase, dstbase, xga->from_to_vram, xga->accel.dir_cmd); - // pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); +#if 0 + pclog("Pattern Map = 8: CMD = %08x: SRCBase = %08x, DSTBase = %08x, from/to vram dir = %d, cmd dir = %06x\n", xga->accel.command, srcbase, dstbase, xga->from_to_vram, xga->accel.dir_cmd); + pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); +#endif while (xga->accel.y >= 0) { if (xga->accel.command & 0xc0) { if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); @@ -1431,9 +1444,8 @@ xga_bitblt(svga_t *svga) } } } else { - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; - dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : frgdcol; + dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(1, dest_dat, src_dat); @@ -1446,15 +1458,17 @@ xga_bitblt(svga_t *svga) xga->accel.sx = ((xga->accel.sx + xdir) & srcwidth) | (xga->accel.sx & ~srcwidth); else xga->accel.sx += xdir; - xga->accel.dx = xga_dst_wrap(xga->accel.dx + xdir); + xga->accel.dx += xdir; xga->accel.x--; if (xga->accel.x < 0) { xga->accel.x = (xga->accel.blt_width & 0xfff); - xga->accel.dx = xga_dst_wrap(xga->accel.dst_map_x); + xga->accel.dx = xga->accel.dst_map_x & 0x1fff; + if (xga->accel.dst_map_x >= 0x1800) + xga->accel.dx |= ~0x17ff; xga->accel.sx = xga->accel.src_map_x & 0xfff; - xga->accel.dy = xga_dst_wrap(xga->accel.dy + ydir); + xga->accel.dy += ydir; if (xga->accel.pattern) xga->accel.sy = ((xga->accel.sy + ydir) & srcheight) | (xga->accel.sy & ~srcheight); else @@ -1493,20 +1507,22 @@ xga_bitblt(svga_t *svga) } } - // pclog("Pattern Map = %d: CMD = %08x: PATBase = %08x, SRCBase = %08x, DSTBase = %08x\n", xga->accel.pat_src, xga->accel.command, patbase, srcbase, dstbase); - // pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); +#if 0 + pclog("XGA bitblt linear endian reverse=%d, octanty=%d, src command = %08x, pxsrcmap=%x, pxdstmap=%x, srcmap=%d, patmap=%d, dstmap=%d, dstwidth=%d, dstheight=%d, srcwidth=%d, srcheight=%d, dstbase=%08x, srcbase=%08x.\n", xga->linear_endian_reverse, ydir, xga->accel.command, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.src_map, xga->accel.pat_src, xga->accel.dst_map, dstwidth, dstheight, srcwidth, srcheight, dstbase, srcbase); + pclog("Pattern Map = %d: CMD = %08x: PATBase = %08x, SRCBase = %08x, DSTBase = %08x\n", xga->accel.pat_src, xga->accel.command, patbase, srcbase, dstbase); + pclog("CMD = %08x: Y = %d, X = %d, patsrc = %02x, srcmap = %d, dstmap = %d, py = %d, sy = %d, dy = %d, width0 = %d, width1 = %d, width2 = %d, width3 = %d\n", xga->accel.command, xga->accel.y, xga->accel.x, xga->accel.pat_src, xga->accel.src_map, xga->accel.dst_map, xga->accel.py, xga->accel.sy, xga->accel.dy, xga->accel.px_map_width[0], xga->accel.px_map_width[1], xga->accel.px_map_width[2], xga->accel.px_map_width[3]); +#endif while (xga->accel.y >= 0) { mix = xga_accel_read_pattern_map_pixel(svga, xga->accel.px, xga->accel.py, xga->accel.pat_src, patbase, patwidth + 1); if (xga->accel.command & 0xc0) { if ((xga->accel.dx >= xga->accel.mask_map_origin_x_off) && (xga->accel.dx <= ((xga->accel.px_map_width[0] & 0xfff) + xga->accel.mask_map_origin_x_off)) && (xga->accel.dy >= xga->accel.mask_map_origin_y_off) && (xga->accel.dy <= ((xga->accel.px_map_height[0] & 0xfff) + xga->accel.mask_map_origin_y_off))) { - if (mix) - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; - else - src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.bkgd_color; - - dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - + if (mix) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : frgdcol; + } else { + src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : bkgdcol; + } + dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(mix, dest_dat, src_dat); @@ -1515,13 +1531,12 @@ xga_bitblt(svga_t *svga) } } } else { - if (mix) - src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.frgd_color; - else - src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1) : xga->accel.bkgd_color; - - dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1); - + if (mix) { + src_dat = (((xga->accel.command >> 28) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : frgdcol; + } else { + src_dat = (((xga->accel.command >> 30) & 3) == 2) ? xga_accel_read_map_pixel(svga, xga->accel.sx, xga->accel.sy, xga->accel.src_map, srcbase, srcwidth + 1, 1) : bkgdcol; + } + dest_dat = xga_accel_read_map_pixel(svga, xga->accel.dx, xga->accel.dy, xga->accel.dst_map, dstbase, dstwidth + 1, 0); if ((xga->accel.cc_cond == 4) || ((xga->accel.cc_cond == 1) && (dest_dat > color_cmp)) || ((xga->accel.cc_cond == 2) && (dest_dat == color_cmp)) || ((xga->accel.cc_cond == 3) && (dest_dat < color_cmp)) || ((xga->accel.cc_cond == 5) && (dest_dat >= color_cmp)) || ((xga->accel.cc_cond == 6) && (dest_dat != color_cmp)) || ((xga->accel.cc_cond == 7) && (dest_dat <= color_cmp))) { old_dest_dat = dest_dat; ROP(mix, dest_dat, src_dat); @@ -1535,13 +1550,15 @@ xga_bitblt(svga_t *svga) xga->accel.px = ((xga->accel.px + xdir) & patwidth) | (xga->accel.px & ~patwidth); else xga->accel.px += xdir; - xga->accel.dx = xga_dst_wrap(xga->accel.dx + xdir); + xga->accel.dx += xdir; xga->accel.x--; if (xga->accel.x < 0) { xga->accel.y--; xga->accel.x = (xga->accel.blt_width & 0xfff); - xga->accel.dx = xga_dst_wrap(xga->accel.dst_map_x); + xga->accel.dx = xga->accel.dst_map_x & 0x1fff; + if (xga->accel.dst_map_x >= 0x1800) + xga->accel.dx |= ~0x17ff; xga->accel.sx = xga->accel.src_map_x & 0xfff; xga->accel.px = xga->accel.pat_map_x & 0xfff; @@ -1550,7 +1567,7 @@ xga_bitblt(svga_t *svga) xga->accel.py = ((xga->accel.py + ydir) & patheight) | (xga->accel.py & ~patheight); else xga->accel.py += ydir; - xga->accel.dy = xga_dst_wrap(xga->accel.dy + ydir); + xga->accel.dy += ydir; if (xga->accel.y < 0) { xga->accel.dst_map_x = xga->accel.dx; @@ -1685,7 +1702,9 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) xga->accel.short_stroke_vector3 = (xga->accel.short_stroke >> 16) & 0xff; xga->accel.short_stroke_vector4 = (xga->accel.short_stroke >> 24) & 0xff; - // pclog("1Vector = %02x, 2Vector = %02x, 3Vector = %02x, 4Vector = %02x\n", xga->accel.short_stroke_vector1, xga->accel.short_stroke_vector2, xga->accel.short_stroke_vector3, xga->accel.short_stroke_vector4); +#if 0 + pclog("1Vector = %02x, 2Vector = %02x, 3Vector = %02x, 4Vector = %02x\n", xga->accel.short_stroke_vector1, xga->accel.short_stroke_vector2, xga->accel.short_stroke_vector3, xga->accel.short_stroke_vector4); +#endif xga_short_stroke(svga, xga->accel.short_stroke_vector1); xga_short_stroke(svga, xga->accel.short_stroke_vector2); xga_short_stroke(svga, xga->accel.short_stroke_vector3); @@ -1952,39 +1971,58 @@ xga_mem_write(uint32_t addr, uint32_t val, xga_t *xga, svga_t *svga, int len) exec_command: xga->accel.octant = xga->accel.command & 0x07; xga->accel.draw_mode = xga->accel.command & 0x30; - xga->accel.mask_mode = xga->accel.command & 0xc0; xga->accel.pat_src = ((xga->accel.command >> 12) & 0x0f); xga->accel.dst_map = ((xga->accel.command >> 16) & 0x0f); xga->accel.src_map = ((xga->accel.command >> 20) & 0x0f); - // if (xga->accel.pat_src) { - // pclog("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, srcheight = %d, px = %d, py = %d, dx = %d, dy = %d, sx = %d, sy = %d, patsrc = %d, dstmap = %d, srcmap = %d, dstbase = %08x, srcbase = %08x, patbase = %08x, dstformat = %x, srcformat = %x, planemask = %08x\n", - // CS, cpu_state.pc, ((xga->accel.command >> 24) & 0x0f), xga->accel.command, xga->accel.px_map_width[xga->accel.pat_src], - // xga->accel.px_map_width[xga->accel.dst_map], xga->accel.px_map_width[xga->accel.src_map], - // xga->accel.px_map_height[xga->accel.pat_src], xga->accel.px_map_height[xga->accel.dst_map], - // xga->accel.px_map_height[xga->accel.src_map], - // xga->accel.pat_map_x, xga->accel.pat_map_y, - // xga->accel.dst_map_x, xga->accel.dst_map_y, - // xga->accel.src_map_x, xga->accel.src_map_y, - // xga->accel.pat_src, xga->accel.dst_map, xga->accel.src_map, - // xga->accel.px_map_base[xga->accel.dst_map], xga->accel.px_map_base[xga->accel.src_map], xga->accel.px_map_base[xga->accel.pat_src], - // xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); - // //pclog("\n"); - // } +#if 0 + if (xga->accel.pat_src) { + pclog("[%04X:%08X]: Accel Command = %02x, full = %08x, patwidth = %d, dstwidth = %d, srcwidth = %d, patheight = %d, dstheight = %d, srcheight = %d, px = %d, py = %d, dx = %d, dy = %d, sx = %d, sy = %d, patsrc = %d, dstmap = %d, srcmap = %d, dstbase = %08x, srcbase = %08x, patbase = %08x, dstformat = %x, srcformat = %x, planemask = %08x\n", + CS, cpu_state.pc, ((xga->accel.command >> 24) & 0x0f), xga->accel.command, xga->accel.px_map_width[xga->accel.pat_src], + xga->accel.px_map_width[xga->accel.dst_map], xga->accel.px_map_width[xga->accel.src_map], + xga->accel.px_map_height[xga->accel.pat_src], xga->accel.px_map_height[xga->accel.dst_map], + xga->accel.px_map_height[xga->accel.src_map], + xga->accel.pat_map_x, xga->accel.pat_map_y, + xga->accel.dst_map_x, xga->accel.dst_map_y, + xga->accel.src_map_x, xga->accel.src_map_y, + xga->accel.pat_src, xga->accel.dst_map, xga->accel.src_map, + xga->accel.px_map_base[xga->accel.dst_map], xga->accel.px_map_base[xga->accel.src_map], xga->accel.px_map_base[xga->accel.pat_src], + xga->accel.px_map_format[xga->accel.dst_map] & 0x0f, xga->accel.px_map_format[xga->accel.src_map] & 0x0f, xga->accel.plane_mask); + pclog("\n"); + } +#endif switch ((xga->accel.command >> 24) & 0x0f) { case 3: /*Bresenham Line Draw Read*/ - // pclog("Line Draw Read\n"); +#if 0 + pclog("Line Draw Read\n"); +#endif break; case 4: /*Short Stroke Vectors*/ +#if 0 + pclog("Short Stroke Vectors.\n"); +#endif break; case 5: /*Bresenham Line Draw Write*/ +#if 0 + pclog("Line Draw Write.\n"); +#endif xga_line_draw_write(svga); break; case 8: /*BitBLT*/ xga_bitblt(svga); break; case 9: /*Inverting BitBLT*/ - // pclog("Inverting BitBLT\n"); +#if 0 + pclog("Inverting BitBLT\n"); +#endif + break; + case 0x0a: /*Area Fill*/ +#if 0 + pclog("Area Fill.\n"); +#endif + break; + + default: break; } } else if (len == 2) { @@ -2009,42 +2047,51 @@ exec_command: goto exec_command; } break; + + default: + break; } } } static void -xga_memio_writeb(uint32_t addr, uint8_t val, void *p) +xga_memio_writeb(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 1); - // pclog("Write MEMIOB = %04x, val = %02x\n", addr & 0x7f, val); +#if 0 + pclog("Write MEMIOB = %04x, val = %02x\n", addr & 0x7f, val); +#endif } static void -xga_memio_writew(uint32_t addr, uint16_t val, void *p) +xga_memio_writew(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 2); - // pclog("Write MEMIOW = %04x, val = %04x\n", addr & 0x7f, val); +#if 0 + pclog("Write MEMIOW = %04x, val = %04x\n", addr & 0x7f, val); +#endif } static void -xga_memio_writel(uint32_t addr, uint32_t val, void *p) +xga_memio_writel(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; xga_mem_write(addr, val, xga, svga, 4); - // pclog("Write MEMIOL = %04x, val = %08x\n", addr & 0x7f, val); +#if 0 + pclog("Write MEMIOL = %04x, val = %08x\n", addr & 0x7f, val); +#endif } static uint8_t -xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) +xga_mem_read(uint32_t addr, xga_t *xga, UNUSED(svga_t *svga)) { uint8_t temp = 0; @@ -2118,6 +2165,9 @@ xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) case 0x7b: temp = xga->accel.dst_map_y >> 8; break; + + default: + break; } } @@ -2125,36 +2175,41 @@ xga_mem_read(uint32_t addr, xga_t *xga, svga_t *svga) } static uint8_t -xga_memio_readb(uint32_t addr, void *p) +xga_memio_readb(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; uint8_t temp; temp = xga_mem_read(addr, xga, svga); - // pclog("[%04X:%08X]: Read MEMIOB = %04x, temp = %02x\n", CS, cpu_state.pc, addr, temp); +#if 0 + pclog("[%04X:%08X]: Read MEMIOB = %04x, temp = %02x\n", CS, cpu_state.pc, addr, temp); +#endif + return temp; } static uint16_t -xga_memio_readw(uint32_t addr, void *p) +xga_memio_readw(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; uint16_t temp; temp = xga_mem_read(addr, xga, svga); temp |= (xga_mem_read(addr + 1, xga, svga) << 8); - // pclog("[%04X:%08X]: Read MEMIOW = %04x, temp = %04x\n", CS, cpu_state.pc, addr, temp); +#if 0 + pclog("[%04X:%08X]: Read MEMIOW = %04x, temp = %04x\n", CS, cpu_state.pc, addr, temp); +#endif return temp; } static uint32_t -xga_memio_readl(uint32_t addr, void *p) +xga_memio_readl(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; uint32_t temp; @@ -2163,7 +2218,9 @@ xga_memio_readl(uint32_t addr, void *p) temp |= (xga_mem_read(addr + 2, xga, svga) << 16); temp |= (xga_mem_read(addr + 3, xga, svga) << 24); - // pclog("Read MEMIOL = %04x, temp = %08x\n", addr, temp); +#if 0 + pclog("Read MEMIOL = %04x, temp = %08x\n", addr, temp); +#endif return temp; } @@ -2208,6 +2265,9 @@ xga_hwcursor_draw(svga_t *svga, int displine) /* Complement */ p[x_pos] ^= 0xffffff; break; + + default: + break; } } @@ -2326,9 +2386,9 @@ xga_render_16bpp(xga_t *xga, svga_t *svga) } static void -xga_write(uint32_t addr, uint8_t val, void *p) +xga_write(uint32_t addr, uint8_t val, void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; if (!xga->on) { @@ -2344,39 +2404,113 @@ xga_write(uint32_t addr, uint8_t val, void *p) cycles -= video_timing_write_b; + if (xga->access_mode & 8) { + if ((xga->access_mode & 7) == 4) + addr ^= 1; + } + xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; xga->vram[addr & xga->vram_mask] = val; } static void -xga_writeb(uint32_t addr, uint8_t val, void *p) +xga_writew(uint32_t addr, uint16_t val, void *priv) { - // pclog("[%04X:%08X]: WriteB\n", CS, cpu_state.pc); - xga_write(addr, val, p); + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + + if (!xga->on) { + svga_writew(addr, val, svga); + return; + } + + xga_write(addr, val & 0xff, svga); + xga_write(addr + 1, val >> 8, svga); } static void -xga_writew(uint32_t addr, uint16_t val, void *p) +xga_writel(uint32_t addr, uint32_t val, void *priv) { - // pclog("[%04X:%08X]: WriteW\n", CS, cpu_state.pc); - xga_write(addr, val, p); - xga_write(addr + 1, val >> 8, p); + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + + if (!xga->on) { + svga_writel(addr, val, svga); + return; + } + + xga_write(addr, val & 0xff, svga); + xga_write(addr + 1, (val >> 8) & 0xff, svga); + xga_write(addr + 2, (val >> 16) & 0xff, svga); + xga_write(addr + 3, (val >> 24) & 0xff, svga); +} + +static uint8_t +xga_read(uint32_t addr, void *priv) +{ + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint8_t ret = 0xff; + + if (!xga->on) + return svga_read(addr, svga); + + addr &= xga->banked_mask; + addr += xga->read_bank; + + if (addr >= xga->vram_size) + return ret; + + cycles -= video_timing_read_b; + + if (xga->access_mode & 8) { + if ((xga->access_mode & 7) == 4) + addr ^= 1; + } + + ret = xga->vram[addr & xga->vram_mask]; + + return ret; +} + +static uint16_t +xga_readw(uint32_t addr, void *priv) +{ + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint16_t ret = 0xffff; + + if (!xga->on) + return svga_readw(addr, svga); + + ret = xga_read(addr, svga); + ret |= (xga_read(addr + 1, svga) << 8); + + return ret; +} + +static uint32_t +xga_readl(uint32_t addr, void *priv) +{ + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint32_t ret = 0xffffffff; + + if (!xga->on) + return svga_readl(addr, svga); + + ret = xga_read(addr, svga); + ret |= (xga_read(addr + 1, svga) << 8); + ret |= (xga_read(addr + 2, svga) << 16); + ret |= (xga_read(addr + 3, svga) << 24); + + return ret; } static void -xga_writel(uint32_t addr, uint32_t val, void *p) +xga_write_linear(uint32_t addr, uint8_t val, void *priv) { - // pclog("[%04X:%08X]: WriteL\n", CS, cpu_state.pc); - xga_write(addr, val, p); - xga_write(addr + 1, val >> 8, p); - xga_write(addr + 2, val >> 16, p); - xga_write(addr + 3, val >> 24, p); -} - -static void -xga_write_linear(uint32_t addr, uint8_t val, void *p) -{ - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; if (!xga->on) { @@ -2391,122 +2525,58 @@ xga_write_linear(uint32_t addr, uint8_t val, void *p) cycles -= video_timing_write_b; + if (xga->linear_endian_reverse) { + if ((xga->access_mode & 7) == 4) { + if ((xga->accel.px_map_format[xga->accel.dst_map] & 7) == 4) + addr ^= 1; + } else if (xga->access_mode & 8) { + if ((xga->accel.px_map_format[xga->accel.dst_map] & 7) == 4) + addr ^= 1; + } + } + xga->changedvram[(addr & xga->vram_mask) >> 12] = svga->monitor->mon_changeframecount; xga->vram[addr & xga->vram_mask] = val; } static void -xga_writew_linear(uint32_t addr, uint16_t val, void *p) +xga_writew_linear(uint32_t addr, uint16_t val, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; if (!xga->on) { svga_writew_linear(addr, val, svga); return; } - if (xga->linear_endian_reverse) { - if (xga->accel.px_map_format[xga->accel.dst_map] == 0x0c) { - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - } else if (xga->accel.px_map_format[xga->accel.dst_map] == 4) { - xga_write_linear(addr + 1, val, p); - xga_write_linear(addr, val >> 8, p); - } else { - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - } - } else { - if (xga->accel.px_map_format[xga->accel.dst_map] == 0x0c) { - xga_write_linear(addr + 1, val, p); - xga_write_linear(addr, val >> 8, p); - } else if (xga->accel.px_map_format[xga->accel.dst_map] == 4) { - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - } else { - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - } - } + xga_write_linear(addr, val, priv); + xga_write_linear(addr + 1, val >> 8, priv); } static void -xga_writel_linear(uint32_t addr, uint32_t val, void *p) +xga_writel_linear(uint32_t addr, uint32_t val, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; if (!xga->on) { svga_writel_linear(addr, val, svga); return; } - xga_write_linear(addr, val, p); - xga_write_linear(addr + 1, val >> 8, p); - xga_write_linear(addr + 2, val >> 16, p); - xga_write_linear(addr + 3, val >> 24, p); + xga_write_linear(addr, val, priv); + xga_write_linear(addr + 1, val >> 8, priv); + xga_write_linear(addr + 2, val >> 16, priv); + xga_write_linear(addr + 3, val >> 24, priv); } static uint8_t -xga_read(uint32_t addr, void *p) +xga_read_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; - - if (!xga->on) - return svga_read(addr, svga); - - addr &= xga->banked_mask; - addr += xga->read_bank; - - if (addr >= xga->vram_size) - return 0xff; - - cycles -= video_timing_read_b; - - return xga->vram[addr & xga->vram_mask]; -} - -static uint8_t -xga_readb(uint32_t addr, void *p) -{ - uint8_t ret; - - ret = xga_read(addr, p); - - return ret; -} - -static uint16_t -xga_readw(uint32_t addr, void *p) -{ - uint16_t ret; - - ret = xga_read(addr, p); - ret |= (xga_read(addr + 1, p) << 8); - - return ret; -} - -static uint32_t -xga_readl(uint32_t addr, void *p) -{ - uint32_t ret; - - ret = xga_read(addr, p); - ret |= (xga_read(addr + 1, p) << 8); - ret |= (xga_read(addr + 2, p) << 16); - ret |= (xga_read(addr + 3, p) << 24); - - return ret; -} - -static uint8_t -xga_read_linear(uint32_t addr, void *p) -{ - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint8_t ret = 0xff; if (!xga->on) return svga_read_linear(addr, svga); @@ -2514,51 +2584,55 @@ xga_read_linear(uint32_t addr, void *p) addr &= svga->decode_mask; if (addr >= xga->vram_size) - return 0xff; + return ret; cycles -= video_timing_read_b; + if (xga->linear_endian_reverse) { + if ((xga->access_mode & 7) == 4) { + if ((xga->accel.px_map_format[xga->accel.dst_map] & 7) == 4) + addr ^= 1; + } else if (xga->access_mode & 8) { + if ((xga->accel.px_map_format[xga->accel.dst_map] & 7) == 4) + addr ^= 1; + } + } + return xga->vram[addr & xga->vram_mask]; } static uint16_t -xga_readw_linear(uint32_t addr, void *p) +xga_readw_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; - uint16_t ret; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint16_t ret; if (!xga->on) return svga_readw_linear(addr, svga); - if (xga->linear_endian_reverse) { - if (xga->accel.px_map_format[xga->accel.src_map] == 0x0c) { - ret = xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8); - } else if (xga->accel.px_map_format[xga->accel.src_map] == 4) { - ret = xga_read_linear(addr + 1, p) | (xga_read_linear(addr, p) << 8); - } else - ret = xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8); - } else { - if (xga->accel.px_map_format[xga->accel.src_map] == 0x0c) { - ret = xga_read_linear(addr + 1, p) | (xga_read_linear(addr, p) << 8); - } else if (xga->accel.px_map_format[xga->accel.src_map] == 4) { - ret = xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8); - } else - ret = xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8); - } + ret = xga_read_linear(addr, svga); + ret |= (xga_read_linear(addr + 1, svga) << 8); + return ret; } static uint32_t -xga_readl_linear(uint32_t addr, void *p) +xga_readl_linear(uint32_t addr, void *priv) { - svga_t *svga = (svga_t *) p; - xga_t *xga = &svga->xga; + svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint32_t ret; if (!xga->on) return svga_readl_linear(addr, svga); - return xga_read_linear(addr, p) | (xga_read_linear(addr + 1, p) << 8) | (xga_read_linear(addr + 2, p) << 16) | (xga_read_linear(addr + 3, p) << 24); + ret = xga_read_linear(addr, svga); + ret |= (xga_read_linear(addr + 1, svga) << 8); + ret |= (xga_read_linear(addr + 2, svga) << 16); + ret |= (xga_read_linear(addr + 3, svga) << 24); + + return ret; } static void @@ -2573,6 +2647,9 @@ xga_do_render(svga_t *svga) case 4: xga_render_16bpp(xga, svga); break; + + default: + break; } svga->x_add = (overscan_x >> 1); @@ -2733,14 +2810,17 @@ xga_poll(xga_t *xga, svga_t *svga) static uint8_t xga_mca_read(int port, void *priv) { - svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; - uint8_t ret = xga->pos_regs[port & 7]; + const svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; + uint8_t ret = xga->pos_regs[port & 7]; if (((port & 7) == 3) && !(ret & 1)) /*Always enable the mapping.*/ ret |= 1; - //pclog("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, port & 7, xga->pos_regs[port & 7]); +#if 0 + pclog("[%04X:%08X]: POS Read Port = %x, val = %02x\n", CS, cpu_state.pc, port & 7, xga->pos_regs[port & 7]); +#endif + return ret; } @@ -2757,8 +2837,8 @@ xga_mca_write(int port, uint8_t val, void *priv) io_removehandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga); mem_mapping_disable(&xga->bios_rom.mapping); mem_mapping_disable(&xga->memio_mapping); - xga->on = 0; - vga_on = !xga->on; + xga->on = 0; + vga_on = !xga->on; xga->linear_endian_reverse = 0; xga->a5_test = 0; @@ -2780,22 +2860,24 @@ xga_mca_write(int port, uint8_t val, void *priv) else mem_mapping_set_addr(&xga->memio_mapping, xga->rom_addr + 0x1c00 + (xga->instance * 0x80), 0x80); } - //pclog("[%04X:%08X]: POS Write Port = %x, val = %02x, linear base = %08x, instance = %d, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, xga->linear_base, xga->instance, xga->rom_addr); +#if 0 + pclog("[%04X:%08X]: POS Write Port = %x, val = %02x, linear base = %08x, instance = %d, rom addr = %05x\n", CS, cpu_state.pc, port & 7, val, xga->linear_base, xga->instance, xga->rom_addr); +#endif } static uint8_t xga_mca_feedb(void *priv) { - svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; + const svga_t *svga = (svga_t *) priv; + const xga_t *xga = &svga->xga; return xga->pos_regs[2] & 1; } static void -xga_mca_reset(void *p) +xga_mca_reset(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; xga->on = 0; @@ -2804,15 +2886,15 @@ xga_mca_reset(void *p) } static void -xga_reset(void *p) +xga_reset(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; mem_mapping_disable(&xga->bios_rom.mapping); mem_mapping_disable(&xga->memio_mapping); - xga->on = 0; - vga_on = !xga->on; + xga->on = 0; + vga_on = !xga->on; xga->linear_endian_reverse = 0; xga->a5_test = 0; } @@ -2821,8 +2903,8 @@ static uint8_t xga_pos_in(uint16_t addr, void *priv) { svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; - uint8_t ret = 0xff; + xga_t *xga = &svga->xga; + uint8_t ret = 0xff; if (xga_has_vga) { switch (addr) { @@ -2848,7 +2930,9 @@ xga_pos_in(uint16_t addr, void *priv) ret = xga->pos_regs[3]; } else ret = 0; - //pclog("POS IDX for 0103 = %d, ret = %02x.\n", xga->pos_idx & 3, ret); +#if 0 + pclog("POS IDX for 0103 = %d, ret = %02x.\n", xga->pos_idx & 3, ret); +#endif break; case 0x0104: switch (xga->pos_idx & 3) { @@ -2864,8 +2948,13 @@ xga_pos_in(uint16_t addr, void *priv) case 3: ret = 0; break; + + default: + break; } - //pclog("POS IDX for 0104 = %d, ret = %02x.\n", xga->pos_idx & 3, ret); +#if 0 + pclog("POS IDX for 0104 = %d, ret = %02x.\n", xga->pos_idx & 3, ret); +#endif break; case 0x0108: case 0x0109: @@ -2883,6 +2972,9 @@ xga_pos_in(uint16_t addr, void *priv) ret |= xga->isa_pos_enable; break; + + default: + break; } } else { switch (addr) { @@ -2917,6 +3009,9 @@ xga_pos_in(uint16_t addr, void *priv) ret |= xga->isa_pos_enable; break; + + default: + break; } } return ret; @@ -2926,7 +3021,7 @@ static void xga_pos_out(uint16_t addr, uint8_t val, void *priv) { svga_t *svga = (svga_t *) priv; - xga_t *xga = &svga->xga; + xga_t *xga = &svga->xga; if (xga_has_vga) { switch (addr) { @@ -2934,8 +3029,10 @@ xga_pos_out(uint16_t addr, uint8_t val, void *priv) xga->pos_idx = (xga->pos_idx & 0x00ff) | (val << 8); break; case 0x0107: - xga->pos_idx = (xga->pos_idx & 0xff00) | (val); - //pclog("POS IDX Write = %04x.\n", xga->pos_idx); + xga->pos_idx = (xga->pos_idx & 0xff00) | val; +#if 0 + pclog("POS IDX Write = %04x.\n", xga->pos_idx); +#endif break; case 0x0108: case 0x0109: @@ -2945,9 +3042,12 @@ xga_pos_out(uint16_t addr, uint8_t val, void *priv) case 0x010d: case 0x010e: case 0x010f: - xga->instance_num = addr & 7; + xga->instance_num = addr & 7; xga->isa_pos_enable = val & 0x08; break; + + default: + break; } } else { switch (addr) { @@ -2959,16 +3059,18 @@ xga_pos_out(uint16_t addr, uint8_t val, void *priv) case 0x010d: case 0x010e: case 0x010f: - xga->instance_num = addr & 7; + xga->instance_num = addr & 7; xga->isa_pos_enable = val & 0x08; break; + + default: + break; } } } -static void - * - xga_init(const device_t *info) +static void * +xga_init(const device_t *info) { if (svga_get_pri() == NULL) return NULL; @@ -2977,13 +3079,13 @@ static void xga_t *xga = &svga->xga; FILE *f; uint32_t temp; - uint8_t *rom = NULL; + uint8_t *rom = NULL; xga->ext_mem_addr = device_get_config_hex16("ext_mem_addr"); xga->instance_isa = device_get_config_int("instance"); - xga->type = device_get_config_int("type"); - xga->dma_channel = device_get_config_int("dma"); - xga->bus = info->flags; + xga->type = device_get_config_int("type"); + xga->dma_channel = device_get_config_int("dma"); + xga->bus = info->flags; xga->vram_size = (1024 << 10); xga->vram_mask = xga->vram_size - 1; @@ -3030,11 +3132,11 @@ static void xga->instance = (xga->pos_regs[2] & 0x0e) >> 1; xga->pos_regs[4] = 1 | 2; xga->linear_base = ((xga->pos_regs[4] & 0xfe) * 0x1000000) + (xga->instance << 22); - xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); + xga->rom_addr = 0xc0000 + (((xga->pos_regs[2] & 0xf0) >> 4) * 0x2000); } - mem_mapping_add(&xga->video_mapping, 0, 0, xga_readb, xga_readw, xga_readl, - xga_writeb, xga_writew, xga_writel, + mem_mapping_add(&xga->video_mapping, 0, 0, xga_read, xga_readw, xga_readl, + xga_write, xga_writew, xga_writel, NULL, MEM_MAPPING_EXTERNAL, svga); mem_mapping_add(&xga->linear_mapping, 0, 0, xga_read_linear, xga_readw_linear, xga_readl_linear, xga_write_linear, xga_writew_linear, xga_writel_linear, @@ -3058,15 +3160,14 @@ static void io_sethandler(0x0106, 0x0002, NULL, NULL, NULL, xga_pos_out, NULL, NULL, svga); io_sethandler(0x2100 + (xga->instance << 4), 0x0010, xga_ext_inb, NULL, NULL, xga_ext_outb, NULL, NULL, svga); - io_sethandler(0x0108, 0x0008, xga_pos_in, NULL, NULL, xga_pos_out, NULL, NULL, svga); + io_sethandler(0x0108, 0x0008, xga_pos_in, NULL, NULL, xga_pos_out, NULL, NULL, svga); mem_mapping_set_addr(&xga->memio_mapping, xga->rom_addr + 0x1c00 + (xga->instance * 0x80), 0x80); } return svga; } -static void - * - svga_xga_init(const device_t *info) +static void * +svga_xga_init(const device_t *info) { svga_t *svga = malloc(sizeof(svga_t)); memset(svga, 0, sizeof(svga_t)); @@ -3083,16 +3184,16 @@ static void svga->bpp = 8; svga->miscout = 1; - xga_has_vga = 1; - xga_enabled = 1; + xga_has_vga = 1; + xga_enabled = 1; return xga_init(info); } static void -xga_close(void *p) +xga_close(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; xga_t *xga = &svga->xga; if (svga) { @@ -3114,17 +3215,17 @@ inmos_xga_available(void) } static void -xga_speed_changed(void *p) +xga_speed_changed(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; svga_recalctimings(svga); } static void -xga_force_redraw(void *p) +xga_force_redraw(void *priv) { - svga_t *svga = (svga_t *) p; + svga_t *svga = (svga_t *) priv; svga->fullchange = svga->monitor->mon_changeframecount; } @@ -3152,7 +3253,7 @@ static const device_config_t xga_mca_configuration[] = { } }, { .name = "", .description = "", .type = CONFIG_END } -// clang-format on + // clang-format on }; static const device_config_t xga_isa_configuration[] = { @@ -3237,7 +3338,7 @@ static const device_config_t xga_isa_configuration[] = { }, }, { .name = "", .description = "", .type = CONFIG_END } -// clang-format on + // clang-format on }; const device_t xga_device = { diff --git a/src/vnc_keymap.c b/src/vnc_keymap.c index 2e5f3c0d8..599ba1d9b 100644 --- a/src/vnc_keymap.c +++ b/src/vnc_keymap.c @@ -623,21 +623,21 @@ static int keysyms_ff[] = { #ifdef ENABLE_VNC_KEYMAP_LOG int vnc_keymap_do_log = ENABLE_VNC_KEYMAP_LOG; -#endif static void -vnc_keymap_log(const char *format, ...) +vnc_keymap_log(const char *fmt, ...) { -#ifdef ENABLE_VNC_KEYMAP_LOG va_list ap; if (vnc_keymap_do_log) { - va_start(ap, format); - pclog_ex(format, ap); + va_start(ap, fmt); + pclog_ex(fmt, ap); va_end(ap); } -#endif } +#else +# define vnc_keymap_log(fmt, ...) +#endif void vnc_kbinput(int down, int k) diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 806f2b45b..a947dfb62 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -269,8 +269,8 @@ else endif ifeq ($(CLANG), y) - CPP := ${TOOL_PREFIX}clang++ - CC := ${TOOL_PREFIX}clang + CPP := clang++ + CC := clang else CPP := ${TOOL_PREFIX}g++ CC := ${TOOL_PREFIX}gcc @@ -304,17 +304,38 @@ ifeq ($(DEBUG), y) ifndef COPTIM COPTIM := -Og endif + ifndef CXXOPTIM + ifeq ($(CLANG), y) + CXXOPTIM := -Os + else + CXXOPTIM := -Og + endif + endif else DFLAGS += -g0 ifeq ($(OPTIM), y) AOPTIM := -mtune=native ifndef COPTIM - COPTIM := -O3 -ffp-contract=fast -flto + CXXOPTIM := -O3 -ffp-contract=fast -flto + endif + ifndef CXXOPTIM + ifeq ($(CLANG), y) + CXXOPTIM := -Os -ffp-contract=fast -flto + else + CXXOPTIM := -O3 -ffp-contract=fast -flto + endif endif else ifndef COPTIM COPTIM := -O3 endif + ifndef CXXOPTIM + ifeq ($(CLANG), y) + CXXOPTIM := -Os + else + CXXOPTIM := -O3 + endif + endif endif endif ifeq ($(AVX), y) @@ -531,7 +552,9 @@ CFLAGS := $(OPTS) $(DFLAGS) $(COPTIM) $(AOPTIM) \ # Add freetyp2 references through pkgconfig CFLAGS := $(CFLAGS) `pkg-config --cflags freetype2` -CXXFLAGS := $(CFLAGS) +CXXFLAGS := $(OPTS) $(DFLAGS) $(CXXOPTIM) $(AOPTIM) \ + $(AFLAGS) -fomit-frame-pointer -mstackrealign -Wall \ + -fno-strict-aliasing CFLAGS += -Werror=implicit-int -Werror=implicit-function-declaration \ -Werror=int-conversion -Werror=strict-prototypes -Werror=old-style-definition @@ -811,13 +834,21 @@ else endif ifeq ($(RTMIDI), y) - LIBS += -lrtmidi -lwinmm + ifeq ($(CLANG), y) + LIBS += -lrtmidi.dll -lwinmm + else + LIBS += -lrtmidi -lwinmm + endif endif ifeq ($(VNC), y) LIBS += $(VNCLIB) -lws2_32 endif -LIBS += -lpng -lz -lwsock32 -liphlpapi -lpsapi -lhid -lsetupapi -luxtheme -static -lstdc++ +ifeq ($(CLANG), y) + LIBS += -lpng -lz -lwsock32 -liphlpapi -lpsapi -lhid -lsetupapi -luxtheme -static -lstdc++.dll +else + LIBS += -lpng -lz -lwsock32 -liphlpapi -lpsapi -lhid -lsetupapi -luxtheme -static -lstdc++ +endif ifneq ($(X64), y) ifneq ($(ARM64), y) LIBS += -Wl,--large-address-aware diff --git a/src/win/languages/cs-CZ.rc b/src/win/languages/cs-CZ.rc index 573493163..ae7e3daf8 100644 --- a/src/win/languages/cs-CZ.rc +++ b/src/win/languages/cs-CZ.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Nastala chyba při inicializaci knihovny FluidSynth." IDS_2081 "Sběrnice" IDS_2082 "Soubor" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disketová mechanika %i (%s): %ls" IDS_2110 "Všechny obrazy (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Rozšířené sektorové obrazy (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Základní sektorové obrazy (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Obrazy magnetického toku (*.FDI)\0*.FDI\0Obrazy povrchu (*.86F;*.MFM)\0*.86F;*.MFM\0Všechny soubory (*.*)\0*.*\0" - IDS_2111 "Nastala chyba při inicializaci knihovny FreeType" IDS_2112 "Nastala chyba při inicializaci knihovny SDL, je potřeba SDL2.dll" IDS_2113 "Opravdu chcete resetovat emulovaný počítač?" IDS_2114 "Opravdu chcete ukončit 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Ujistěte se, že je nainstalován " LIB_NAME_PCAP " a používáte síťové připojení s ním kompatibilní." IDS_2131 "Neplatná konfigurace" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " je potřeba pro emulaci ESC/P tiskáren." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " je potřeba pro automatický převod PostScript dokumentů do PDF.\n\nJakékoliv dokumenty vytisknuté přes obecnou PostScriptovou tiskárnu budou uloženy jako PostScript (.ps) soubory." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " je potřeba pro MIDI výstup přes knihovnu FluidSynth." IDS_2135 "Vstup do režimu celé obrazovky" IDS_2136 "Nezobrazovat dále tuto zprávu" IDS_2137 "Neukončovat" diff --git a/src/win/languages/de-DE.rc b/src/win/languages/de-DE.rc index 0dc8a4754..5e6f38221 100644 --- a/src/win/languages/de-DE.rc +++ b/src/win/languages/de-DE.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynth konnte nicht initialisiert werden" IDS_2081 "Bus" IDS_2082 "Datei" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Diskette %i (%s): %ls" IDS_2110 "Alle Images (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Fortgeschrittene Sektorimages (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basissektorimages (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Fluximages (*.FDI)\0*.FDI\0Oberflächenimages (*.86F;*.MFM)\0*.86F;*.MFM\0Alle Dateien (*.*)\0*.*\0" - IDS_2111 "FreeType konnte nicht initialisiert werden" IDS_2112 "SDL konnte nicht initialisiert werden, die Datei SDL2.dll wird benötigt" IDS_2113 "Sind Sie sich sicher, dass Sie einen Hard-Reset für das emulierte System durchführen wollen?" IDS_2114 "Sind Sie sich sicher, dass Sie 86Box beenden wollen?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Bitte stellen Sie sicher, dass " LIB_NAME_PCAP " installiert ist und sie eine " LIB_NAME_PCAP "-kompatible Netzwerkverbindung nutzen." IDS_2131 "Ungültige Konfiguration" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " wird für die ESC/P-Druckeremulation benötigt." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " wird zur automatischen Konversion von PostScript-Dateien in das PDF-Format benötigt.\n\nSämtliche an den generischen PostScript-Drucker gesendete Dateien werden als PostScript (.ps)-Dateien gesichert." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " wird für die FluidSynth-MIDI-Ausgabe benötigt." IDS_2135 "Vollbildmodus wird aktiviert" IDS_2136 "Diese Nachricht nicht mehr anzeigen" IDS_2137 "Nicht beenden" diff --git a/src/win/languages/en-GB.rc b/src/win/languages/en-GB.rc index 299d100ad..9f6f178a6 100644 --- a/src/win/languages/en-GB.rc +++ b/src/win/languages/en-GB.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Unable to initialize FluidSynth" IDS_2081 "Bus" IDS_2082 "File" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Floppy %i (%s): %ls" IDS_2110 "All images (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Advanced sector images (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basic sector images (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Surface images (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "Unable to initialize FreeType" IDS_2112 "Unable to initialize SDL, SDL2.dll is required" IDS_2113 "Are you sure you want to hard reset the emulated machine?" IDS_2114 "Are you sure you want to exit 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Make sure " LIB_NAME_PCAP " is installed and that you are on a " LIB_NAME_PCAP "-compatible network connection." IDS_2131 "Invalid configuration" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " is required for ESC/P printer emulation." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " is required for FluidSynth MIDI output." IDS_2135 "Entering fullscreen mode" IDS_2136 "Don't show this message again" IDS_2137 "Don't exit" diff --git a/src/win/languages/en-US.rc b/src/win/languages/en-US.rc index 5c6932a62..b1163f8f3 100644 --- a/src/win/languages/en-US.rc +++ b/src/win/languages/en-US.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Unable to initialize FluidSynth" IDS_2081 "Bus" IDS_2082 "File" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Floppy %i (%s): %ls" IDS_2110 "All images (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Advanced sector images (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basic sector images (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Surface images (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "Unable to initialize FreeType" IDS_2112 "Unable to initialize SDL, SDL2.dll is required" IDS_2113 "Are you sure you want to hard reset the emulated machine?" IDS_2114 "Are you sure you want to exit 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Make sure " LIB_NAME_PCAP " is installed and that you are on a " LIB_NAME_PCAP "-compatible network connection." IDS_2131 "Invalid configuration" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " is required for ESC/P printer emulation." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " is required for automatic conversion of PostScript files to PDF.\n\nAny documents sent to the generic PostScript printer will be saved as PostScript (.ps) files." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " is required for FluidSynth MIDI output." IDS_2135 "Entering fullscreen mode" IDS_2136 "Don't show this message again" IDS_2137 "Don't exit" diff --git a/src/win/languages/es-ES.rc b/src/win/languages/es-ES.rc index 8a9e436a9..49fea1fae 100644 --- a/src/win/languages/es-ES.rc +++ b/src/win/languages/es-ES.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Incapaz de inicializar FluidSynth" IDS_2081 "Bus" IDS_2082 "Archivo" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disquete %i (%s): %ls" IDS_2110 "Todas las Imágenes (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Advanced sector images (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basic sector images (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Surface images (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "Incapaz de inicializar FreeType" IDS_2112 "Incapaz de inicializar SDL, se requiere SDL2.dll" IDS_2113 "¿Seguro que quieres resetear la máquina emulada?" IDS_2114 "¿Seguro que quieres cerrar 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Asegúrate de que " LIB_NAME_PCAP " está instalado y de que estás en una conexión de red compatible con " LIB_NAME_PCAP "." IDS_2131 "Configuración inválida" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " es necesaria para emulación de impresión ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " es necesaria para la conversión automática de archivos PostScript a PDF.\n\nCualquier documento enviado a la impresora genérica postScript se guardará como archivo PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " es necesario para salida MIDI FluidSynth." IDS_2135 "Entrando en modo pantalla completa" IDS_2136 "No mostrar más este mensaje" IDS_2137 "No salir" diff --git a/src/win/languages/fi-FI.rc b/src/win/languages/fi-FI.rc index 3f8cdf8b2..1c5cda78b 100644 --- a/src/win/languages/fi-FI.rc +++ b/src/win/languages/fi-FI.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynthin alustus epäonnistui" IDS_2081 "Väylä" IDS_2082 "Tiedosto" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u Mt (CHS: %i, %i, %i)" IDS_2109 "Levyke %i (%s): %ls" IDS_2110 "Kaikki levykuvat (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Kehittyneet sektorilevykuvat (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Perussektorilevykuvat (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux-levykuvat (*.FDI)\0*.FDI\0Pintalevykuvat (*.86F;*.MFM)\0*.86F;*.MFM\0Kaikki tiedostot (*.*)\0*.*\0" - IDS_2111 "FreeType:n alustus epäonnistui" IDS_2112 "SDL:n alustus epäonnistui. Tarvitaan SDL2.dll" IDS_2113 "Haluatko varmasti käynnistää emuloidun tietokoneen uudelleen?" IDS_2114 "Haluatko varmasti sulkea 86Boxin?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Varmista, että " LIB_NAME_PCAP " on asennettu ja että verkkoyhteytesi on " LIB_NAME_PCAP "-yhteensopiva." IDS_2131 "Virheelliset määritykset" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " vaaditaan ESC/P-tulostimen emuloimiseksi." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " vaaditaan PostScript-tiedostojen automaattiseen muuntamiseen PDF-tiedostoiksi.\n\nKaikki geneeriselle PostScript-tulostimelle lähetetyt asiakirjat tallennetaan PostScript (.ps) -tiedostoina." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " vaaditaan FluidSynth MIDI-ulostuloa varten." IDS_2135 "Siirrytään koko näytön tilaan" IDS_2136 "Älä näytä tätä viestiä uudelleen" IDS_2137 "Älä poistu" diff --git a/src/win/languages/fr-FR.rc b/src/win/languages/fr-FR.rc index f5b65a741..1d4643eeb 100644 --- a/src/win/languages/fr-FR.rc +++ b/src/win/languages/fr-FR.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Impossible d'initialiser FluidSynth" IDS_2081 "Bus" IDS_2082 "File" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u Mo (CTS: %i, %i, %i)" IDS_2109 "Disquette %i (%s): %ls" IDS_2110 "Toutes les images (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Images du secteur avancés (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Images du secteur basiques (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Images du flux (*.FDI)\0*.FDI\0Images de surface (*.86F;*.MFM)\0*.86F;*.MFM\0Tous les fichiers (*.*)\0*.*\0" - IDS_2111 "Impossible d'initialiser FreeType" IDS_2112 "Impossible d'initialiser SDL, SDL2.dll est nécessaire" IDS_2113 "Etes-vous sûr de vouloir réinitialiser la machine émulée ?" IDS_2114 "Etes-vous sûr de vouloir quitter 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Assurez-vous que " LIB_NAME_PCAP " est installé et que vou utilisez une connexion réseau compatible avec " LIB_NAME_PCAP "." IDS_2131 "Configuration non valide" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " est nécessaire pour l'émulation de l'imprimante ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " est nécessair pour la conversion automatique des fichiers PostScript dans PDF.\n\nTous les documents envoyés à l'imprimante générique PostScript seront sauvés comme des fichiers PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " est nécessaire pour la sortie MIDI FluidSynth." IDS_2135 "Entrer en mode plein écran" IDS_2136 "Ne pas montrer ce message à nouveau" IDS_2137 "Ne pas sortir" diff --git a/src/win/languages/hr-HR.rc b/src/win/languages/hr-HR.rc index 743e14b6f..5225ff969 100644 --- a/src/win/languages/hr-HR.rc +++ b/src/win/languages/hr-HR.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Nije moguće inicijalizirati FluidSynth" IDS_2081 "Bus" IDS_2082 "Datoteka" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disketa %i (%s): %ls" IDS_2110 "Sve slike (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Napredne sektorske slike (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Osnovne sektorske slike (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux slike (*.FDI)\0*.FDI\0Površinske slike (*.86F;*.MFM)\0*.86F;*.MFM\0Sve datoteke (*.*)\0*.*\0" - IDS_2111 "Nije moguće inicijalizirati FreeType" IDS_2112 "Nije moguće inicijalizirati SDL, SDL2.dll je potrebno" IDS_2113 "Jeste li sigurni da želite hard resetirati emulirani sistem?" IDS_2114 "Jeste li sigurni da želite zatvoriti 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Provjerite je li " LIB_NAME_PCAP " instaliran i jeste li na mreži, kompadibilnoj s " LIB_NAME_PCAP "." IDS_2131 "Nevažeća konfiguracija" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " je potrebno za emuliranje ESC/P pisača." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " je potrebno za automatsku konverziju PostScript datoteke u PDF datoteke.\n\nSvi dokumenti poslani na generički PostScript pisač bit će spremljeni kao PostScript (.ps) datoteke." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " je potrebno za FluidSynth MIDI izlaz." IDS_2135 "Ulazim u cijelozaslonski način" IDS_2136 "Ne pokazi više ovu poruku" IDS_2137 "Ne izlazi" diff --git a/src/win/languages/hu-HU.rc b/src/win/languages/hu-HU.rc index b4fc976d6..aa7e06eff 100644 --- a/src/win/languages/hu-HU.rc +++ b/src/win/languages/hu-HU.rc @@ -439,7 +439,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Nem sikerült a FluidSynth inicializálása" IDS_2081 "Busz" IDS_2082 "Fájl" IDS_2083 "C" @@ -470,7 +469,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Floppy %i (%s): %ls" IDS_2110 "Minden képfájl (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Továbbfejlesztett szektor képek (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Alapvető szektor képek (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux képekfájlok (*.FDI)\0*.FDI\0Felületi képfájlok (*.86F;*.MFM)\0*.86F;*.MFM\0Minden fájl (*.*)\0*.*\0" - IDS_2111 "A FreeType inicializálása nem lehetséges" IDS_2112 "Az SDL inicializálása nem lehetséges, az SDL2.dll fájl szükséges" IDS_2113 "Biztosan szeretné újraindítani az emulált gépet?" IDS_2114 "Biztos benne, hogy ki szeretne lépni a 86Box-ból?" @@ -497,23 +495,11 @@ BEGIN IDS_2130 "Győződjön meg hogy a(z) " LIB_NAME_PCAP " telepítve van és jelenleg a " LIB_NAME_PCAP "-kompatibilis kapcsolatot használja." IDS_2131 "Érvénytelen konfiguráció" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " szükséges az ESC/P nyomtató emulációhoz." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " szükséges a PostScript fájlok PDF formátumba való automatikus konvertálásához.\n\nAz általános PostScript nyomtatóra küldött dokumentumok PostScript (.ps) fájlként kerülnek mentésre." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " szükséges a FluidSynth MIDI kimenethez." IDS_2135 "Teljes képernyős módra váltás" IDS_2136 "Ne jelenítse meg újra ezt az üzenetet " IDS_2137 "Ne lépjen ki" diff --git a/src/win/languages/it-IT.rc b/src/win/languages/it-IT.rc index c5a726062..f546fc1d4 100644 --- a/src/win/languages/it-IT.rc +++ b/src/win/languages/it-IT.rc @@ -435,7 +435,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Impossibile inizializzare FluidSynth" IDS_2081 "Bus" IDS_2082 "File" IDS_2083 "C" @@ -466,7 +465,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Floppy %i (%s): %ls" IDS_2110 "Tutte le immagini (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Immagini da settori avanzati (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Imagini da settori basilari (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Immagini flusso (*.FDI)\0*.FDI\0Immagini da superficie (*.86F;*.MFM)\0*.86F;*.MFM\0Tutti i file (*.*)\0*.*\0" - IDS_2111 "Impossibile inizializzare FreeType" IDS_2112 "Impossibile inizializzare SDL, SDL2.dll è necessario" IDS_2113 "Sei sicuro di voler riavviare la macchina emulata?" IDS_2114 "Sei sicuro di voler uscire da 86Box?" @@ -494,23 +492,11 @@ BEGIN IDS_2130 "Controlla se " LIB_NAME_PCAP " è installato e che tu sia connesso ad una connessione " LIB_NAME_PCAP " compatibile." IDS_2131 "Configurazione invalida" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " è richesto per l'emuazione di stampanti ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " è richiesto per la conversione automatica di file PostScript a file PDF.\n\nQualsiasi documento mandato alla stampante generica PostScript sarà salvato come file PostScript. (.ps)" -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " è richiesto per l'output FluidSynth MIDI." IDS_2135 "Entrando nella modalità schermo intero" IDS_2136 "Non mostrare più questo messaggio" IDS_2137 "Non uscire" diff --git a/src/win/languages/ja-JP.rc b/src/win/languages/ja-JP.rc index 36e42e357..fb5106134 100644 --- a/src/win/languages/ja-JP.rc +++ b/src/win/languages/ja-JP.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynthが初期化できません" IDS_2081 "バス" IDS_2082 "ファイル" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "フロッピー %i (%s): %ls" IDS_2110 "すべてのイメージ (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0アドバンスドセクターイメージ (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0基本セクターイメージ (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0フラックスイメージ (*.FDI)\0*.FDI\0表面イメージ (*.86F;*.MFM)\0*.86F;*.MFM\0すべてのファイル (*.*)\0*.*\0" - IDS_2111 "FreeTypeが初期化できません" IDS_2112 "SDLが初期化できません。SDL2.dllが必要です" IDS_2113 "使用中のマシンをハードリセットしますか?" IDS_2114 "86Boxを終了しますか?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 LIB_NAME_PCAP "がインストールされてるか、" LIB_NAME_PCAP "に対応したネットワークに接続されてるか確認してください。" IDS_2131 "不正な設定です" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "ESC/Pプリンタのエミュレーションには" LIB_NAME_FREETYPE "が必要です。" -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 "PostScriptファイルをPDFに自動変換するには" LIB_NAME_GS "が必要です。\n\n汎用PostScriptプリンターに送信されたドキュメントは、PostScript(.ps)ファイルとして保存されます。" -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "FluidSynthのMIDI出力には" LIB_NAME_FLUIDSYNTH "が必要です。" IDS_2135 "フルスクリーンに切り替えています" IDS_2136 "今後、このメッセージを表示しない" IDS_2137 "終了しない" diff --git a/src/win/languages/ko-KR.rc b/src/win/languages/ko-KR.rc index 14fff915e..4fd952c38 100644 --- a/src/win/languages/ko-KR.rc +++ b/src/win/languages/ko-KR.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynth를 초기화할 수 없습니다" IDS_2081 "버스" IDS_2082 "파일" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "플로피 %i (%s): %ls" IDS_2110 "모든 이미지 (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0어드밴스드 섹터 이미지 (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0기본 섹터 이미지 (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0플럭스 이미지 (*.FDI)\0*.FDI\0표면 이미지 (*.86F;*.MFM)\0*.86F;*.MFM\0모든 파일 (*.*)\0*.*\0" - IDS_2111 "FreeType을 초기화할 수 없습니다" IDS_2112 "SDL을 초기화할 수 없습니다. SDL2.dll이 필요합니다" IDS_2113 "실행중인 머신을 재시작하시겠습니까?" IDS_2114 "86Box를 끝내시겠습니까?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 LIB_NAME_PCAP "이 설치되었는지 " LIB_NAME_PCAP "에 대응하는 네트워크에 접속되어 있는지 확인해 주세요." IDS_2131 "올바르지 않은 설정입니다" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "ESC/P 프린터 에뮬레이션에 " LIB_NAME_FREETYPE "이(가) 필요합니다." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS "은(는) PostScript 파일을 PDF로 자동변환하는 데에 필요합니다.\n\n표준 PostScript 프린터로 보내신 임의의 문서는 PostScript (.ps) 파일로 저장됩니다." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "FluidSynth의 MIDI 출력에 " LIB_NAME_FLUIDSYNTH "이(가) 필요합니다." IDS_2135 "전체 화면으로 전환" IDS_2136 "이 메시지 그만 보기" IDS_2137 "끝내지 않기" diff --git a/src/win/languages/pl-PL.rc b/src/win/languages/pl-PL.rc index 0cbadf296..442a225ed 100644 --- a/src/win/languages/pl-PL.rc +++ b/src/win/languages/pl-PL.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Nie można zainicjować FluidSynth" IDS_2081 "Magistrala" IDS_2082 "Plik" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Dyskietka %i (%s): %ls" IDS_2110 "Wszystkie obrazy (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Zaawansowane obrazy sektorów (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Podstawowe obrazy sektorów (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Obrazy powierzchniowe (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "Nie można zainicjować FreeType" IDS_2112 "Nie można zainicjować SDL, wymagany SDL2.dll" IDS_2113 "Jesteś pewien że chcesz wykonać twardy reset emulowanej maszyny?" IDS_2114 "Jesteś pewien że chcesz zakończyć 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Sprawdź, czy " LIB_NAME_PCAP " jest zainstalowany i czy posiadasz połączenie sieciowe kompatybilne z " LIB_NAME_PCAP "." IDS_2131 "Nieprawidłowa konfiguracja" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " jest wymagany do emulacji drukarki ESC-P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " jest wymagany do automatycznej konwersji plików PostScript do PDF.\n\nDokumenty wysłane do ogólnej drukarki PostScript zostaną zapisane jako pliki PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " jest wymagany dla wyjścia FluidSynth MIDI." IDS_2135 "Przechodzenie do trybu pełnoekranowego" IDS_2136 "Nie pokazuj więcej tego komunikatu" IDS_2137 "Nie kończ" diff --git a/src/win/languages/pt-BR.rc b/src/win/languages/pt-BR.rc index ceb530c43..db85ed021 100644 --- a/src/win/languages/pt-BR.rc +++ b/src/win/languages/pt-BR.rc @@ -26,7 +26,7 @@ BEGIN MENUITEM "&Reinicialização completa...", IDM_ACTION_HRESET MENUITEM "&Ctrl+Alt+Del\tCtrl+F12", IDM_ACTION_RESET_CAD MENUITEM SEPARATOR - MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC + MENUITEM "Ctrl+Alt+&Esc", IDM_ACTION_CTRL_ALT_ESC MENUITEM SEPARATOR MENUITEM "&Pausar", IDM_ACTION_PAUSE MENUITEM SEPARATOR @@ -311,10 +311,10 @@ END #define STR_NET_TYPE "Tipo de rede:" #define STR_PCAP "Dispositivo PCap:" #define STR_NET "Adaptador de rede:" -#define STR_NET1 "Network card 1:" -#define STR_NET2 "Network card 2:" -#define STR_NET3 "Network card 3:" -#define STR_NET4 "Network card 4:" +#define STR_NET1 "Placa de rede 1:" +#define STR_NET2 "Placa de rede 2:" +#define STR_NET3 "Placa de rede 3:" +#define STR_NET4 "Placa de rede 4:" #define STR_COM1 "Dispositivo COM1:" #define STR_COM2 "Dispositivo COM2:" @@ -332,10 +332,10 @@ END #define STR_PARALLEL2 "Porta paralela 2" #define STR_PARALLEL3 "Porta paralela 3" #define STR_PARALLEL4 "Porta paralela 4" -#define STR_SERIAL_PASS1 "Serial port passthrough 1" -#define STR_SERIAL_PASS2 "Serial port passthrough 2" -#define STR_SERIAL_PASS3 "Serial port passthrough 3" -#define STR_SERIAL_PASS4 "Serial port passthrough 4" +#define STR_SERIAL_PASS1 "Encaminhamento de porta serial 1" +#define STR_SERIAL_PASS2 "Encaminhamento de porta serial 2" +#define STR_SERIAL_PASS3 "Encaminhamento de porta serial 3" +#define STR_SERIAL_PASS4 "Encaminhamento de porta serial 4" #define STR_HDC "Controlador HD:" #define STR_FDC "Controlador FD:" @@ -437,7 +437,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Não foi possível inicializar o FluidSynth" IDS_2081 "Barramento" IDS_2082 "Arquivo" IDS_2083 "CI" @@ -468,7 +467,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disquete %i (%s): %ls" IDS_2110 "Todas as imagens (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Imagens de setor avançado (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Imagens de setor básico (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Imagens de fluxo (*.FDI)\0*.FDI\0Imagens de superfície (*.86F;*.MFM)\0*.86F;*.MFM\0Todos os arquivos (*.*)\0*.*\0" - IDS_2111 "Não foi possível inicializar o FreeType" IDS_2112 "Não é possível inicializar o SDL, é necessário o SDL2.dll" IDS_2113 "Tem certeza de que deseja reiniciar completamente a máquina emulada?" IDS_2114 "Tem certeza de que deseja sair do 86Box?" @@ -496,23 +494,11 @@ BEGIN IDS_2130 "Certifique-se de que " LIB_NAME_PCAP " esteja instalado e que você tenha uma conexão de rede compatível com " LIB_NAME_PCAP "." IDS_2131 "Configuração inválida" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " é necessário para emulação de impressora ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " é necessário para a conversão automática de arquivos PostScript para PDF.\n\nQualquer documento enviado para a impressora genérica PostScript será salvo como arquivos PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " é necessário para a saída MIDI FluidSynth." IDS_2135 "Entrando no modo de tela cheia" IDS_2136 "Não exibir esta mensagem novamente" IDS_2137 "Não sair" @@ -540,13 +526,13 @@ BEGIN IDS_2159 "Reinicialização completa" IDS_2160 "Desligamento por ACPI" IDS_2161 "Configurações" - IDS_2162 "Type" - IDS_2163 "No Dynarec" - IDS_2164 "Old Dynarec" - IDS_2165 "New Dynarec" - IDS_2166 "Video card #2 ""%hs"" is not available due to missing ROMs in the roms/video directory. Disabling the second video card." - IDS_2167 "Failed to initialize network driver" - IDS_2168 "The network configuration will be switched to the null driver" + IDS_2162 "Tipo" + IDS_2163 "Sem recompilador dinâmico" + IDS_2164 "Recompilador dinâmico antigo" + IDS_2165 "Novo recompilador dinâmico" + IDS_2166 "A placa de vídeo #2 ""%hs"" não está disponível devido à ausência de ROMs no diretório roms/video. Desabilitando a segunda placa de vídeo." + IDS_2167 "Falha ao inicializar o driver de rede" + IDS_2168 "A configuração de rede será alterada para o driver nulo" END STRINGTABLE DISCARDABLE diff --git a/src/win/languages/pt-PT.rc b/src/win/languages/pt-PT.rc index c1dd53ca5..00f5af336 100644 --- a/src/win/languages/pt-PT.rc +++ b/src/win/languages/pt-PT.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Não foi possível inicializar o FluidSynth" IDS_2081 "Barramento" IDS_2082 "Ficheiro" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CCS: %i, %i, %i)" IDS_2109 "Disquete %i (%s): %ls" IDS_2110 "Todas as imagens (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Imagens avançadas de sector (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Imagens básicas de sector (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Imagens de fluxo (*.FDI)\0*.FDI\0Imagens de superfície (*.86F;*.MFM)\0*.86F;*.MFM\0Todos os ficheiros (*.*)\0*.*\0" - IDS_2111 "Não foi possível inicializar o FreeType" IDS_2112 "Não foi possível inicializar o SDL. O ficheiro SDL2.dll é necessário!" IDS_2113 "Tem a certeza de que quer um reinício completo da máquina emulada?" IDS_2114 "Tem a certeza de que quer sair do 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Certifique-se de que a biblioteca " LIB_NAME_PCAP " está instalada e de que está a utilizar uma ligação de rede compatível com a biblioteca " LIB_NAME_PCAP "." IDS_2131 "Configuração inválida" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " é requerida para a emulação de impressora ESC/P." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " é requerido para a conversão automática de ficheiros PostScript para ficheiros PDF.\n\nQualquer documento enviado para a impressora PostScript genérica será gravado como um ficheiro PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " é necessário para a saída MIDI FluidSynth MIDI." IDS_2135 "A entrar no modo de ecrã cheio" IDS_2136 "Não mostrar mais esta mensagem" IDS_2137 "Não sair" diff --git a/src/win/languages/ru-RU.rc b/src/win/languages/ru-RU.rc index 8b3e4fbc3..458b0e874 100644 --- a/src/win/languages/ru-RU.rc +++ b/src/win/languages/ru-RU.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Невозможно инициализировать FluidSynth" IDS_2081 "Шина" IDS_2082 "Файл" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u МБ (CHS: %i, %i, %i)" IDS_2109 "Дисковод %i (%s): %ls" IDS_2110 "Все образы (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Расширенные образы секторов (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Основные образы секторов (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Образы Flux (*.FDI)\0*.FDI\0Образы Surface (*.86F;*.MFM)\0*.86F;*.MFM\0Все файлы (*.*)\0*.*\0" - IDS_2111 "Невозможно инициализировать FreeType" IDS_2112 "Невозможно инициализировать SDL, требуется SDL2.dll" IDS_2113 "Вы уверены, что хотите выполнить холодную перезагрузку эмулируемой машины?" IDS_2114 "Вы уверены, что хотите выйти из 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Убедитесь, что " LIB_NAME_PCAP " установлен и ваше сетевое соединение, совместимо с " LIB_NAME_PCAP "." IDS_2131 "Недопустимая конфигурация" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "Для эмуляции принтера ESC/P требуется " LIB_NAME_FREETYPE "." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " требуется для автоматического преобразования файлов PostScript в PDF.\n\nВсе документы, отправленные на общий принтер PostScript, будут сохранены в виде файлов PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "Для FluidSynth MIDI-вывода требуется " LIB_NAME_FLUIDSYNTH "." IDS_2135 "Вход в полноэкранный режим" IDS_2136 "Больше не показывать это сообщение" IDS_2137 "Не выходить" diff --git a/src/win/languages/sl-SI.rc b/src/win/languages/sl-SI.rc index 439c97330..f9d2fb82a 100644 --- a/src/win/languages/sl-SI.rc +++ b/src/win/languages/sl-SI.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Ne morem inicializirati FluidSynth" IDS_2081 "Vodilo" IDS_2082 "Datoteka" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disketa %i (%s): %ls" IDS_2110 "Vse slike (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Napredne sektorske slike (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Osnovne sektorske slike (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Tokovne slike (*.FDI)\0*.FDI\0Površinske slike (*.86F;*.MFM)\0*.86F;*.MFM\0Vse datoteke (*.*)\0*.*\0" - IDS_2111 "Ne morem inicializirati FreeType" IDS_2112 "Ne morem inicializirati SDL, potrebna je knjižica SDL2.dll" IDS_2113 "Ste prepričani, da želite ponovno zagnati emulirani sistem?" IDS_2114 "Ste prepričani, da želite zapreti 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Prepičajte se, da je nameščen " LIB_NAME_PCAP " in da ste na omrežni povezavi, združljivi z " LIB_NAME_PCAP IDS_2131 "Neveljavna konfiguracija" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " je potreben za emuliranje ESC/P tiskalnika." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " je potreben za samodejno pretvorbo PostScript datotek v PDF.\n\nVsi dokumenti, poslani generičnemu PostScript tiskalniku bodo shranjeni kot PostScript (.ps) datoteke." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " je potreben za FluidSynth MIDI izhod." IDS_2135 "Preklapljam v celozaslonski način" IDS_2136 "Ne pokaži več tega sporočila" IDS_2137 "Prekliči izhod" diff --git a/src/win/languages/tr-TR.rc b/src/win/languages/tr-TR.rc index a9a6bbbbc..cb45eab74 100644 --- a/src/win/languages/tr-TR.rc +++ b/src/win/languages/tr-TR.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "FluidSynth başlatılamadı" IDS_2081 "Veri yolu" IDS_2082 "Dosya" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "Disket %i (%s): %ls" IDS_2110 "Tüm imajlar (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Gelişmiş sektör imajları (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Basit sektör imajları (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux images (*.FDI)\0*.FDI\0Yüzey imajları (*.86F;*.MFM)\0*.86F;*.MFM\0All files (*.*)\0*.*\0" - IDS_2111 "FreeType başlatılamadı" IDS_2112 "SDL başlatılamadı, SDL2.dll gerekmektedir" IDS_2113 "Emüle edilen makineyi yeniden başlatmak istediğinizden emin misiniz?" IDS_2114 "86Box'tan çıkmak istediğinize emin misiniz?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "" LIB_NAME_PCAP " kurulu olduğundan ve " LIB_NAME_PCAP "-uyumlu bir internet ağında bulunduğunuzdan emin olun." IDS_2131 "Geçersiz konfigürasyon" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 LIB_NAME_FREETYPE " ESC/P yazıcı emülasyonu için gereklidir." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " PostScript dosyalarının otomatik olarak PDF dosyalarına çevirilmesi için gereklidir.\n\nGenel PostScript yazıcısına gönderilen tüm dökümanlar PostScript (.ps) dosyaları olarak kaydedilecektir." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 LIB_NAME_FLUIDSYNTH " FluidSynth MIDI çıkışı için gereklidir." IDS_2135 "Tam ekran moduna geçiliyor" IDS_2136 "Bu mesajı bir daha gösterme" IDS_2137 "Çıkış yapma" diff --git a/src/win/languages/uk-UA.rc b/src/win/languages/uk-UA.rc index 49f5573e7..e282e467b 100644 --- a/src/win/languages/uk-UA.rc +++ b/src/win/languages/uk-UA.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "Неможливо ініціалізувати FluidSynth" IDS_2081 "Шина" IDS_2082 "Файл" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u МБ (CHS: %i, %i, %i)" IDS_2109 "Дисковод %i (%s): %ls" IDS_2110 "Усі образи (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0Розширені образи секторів (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0Основні образи секторів (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Образи Flux (*.FDI)\0*.FDI\0Образи Surface (*.86F;*.MFM)\0*.86F;*.MFM\0Усі файли (*.*)\0*.*\0" - IDS_2111 "Неможливо ініціалізувати FreeType" IDS_2112 "Неможливо ініціалізувати SDL, потрібно SDL2.dll" IDS_2113 "Ви впевнені, що хочете виконати холодне перезавантаження емульованої машини?" IDS_2114 "Ви впевнені, що хочете вийти з 86Box?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "Переконайтесь, що " LIB_NAME_PCAP " встановлений і ваше мережеве з'єднання, сумісне з " LIB_NAME_PCAP "." IDS_2131 "Неприпустима конфігурація" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "Для емуляції принтера ESC/P потрібно " LIB_NAME_FREETYPE "." -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " потрібно для автоматичного перетворення файлів PostScript в PDF.\n\nсі документи, відправлені на загальний принтер PostScript, будуть збережені у вигляді файлів PostScript (.ps)." -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "Для FluidSynth MIDI-висновку потрібно " LIB_NAME_FLUIDSYNTH "." IDS_2135 "Вхід у повноекранний режим" IDS_2136 "Більше не показувати це повідомлення" IDS_2137 "Не виходити" diff --git a/src/win/languages/zh-CN.rc b/src/win/languages/zh-CN.rc index 807f5f3a0..3320af15f 100644 --- a/src/win/languages/zh-CN.rc +++ b/src/win/languages/zh-CN.rc @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "无法初始化 FluidSynth" IDS_2081 "总线" IDS_2082 "文件" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "软盘 %i (%s): %ls" IDS_2110 "所有镜像 (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0高级扇区镜像 (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0基本扇区镜像 (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux 镜像 (*.FDI)\0*.FDI\0表面镜像 (*.86F;*.MFM)\0*.86F;*.MFM\0所有文件 (*.*)\0*.*\0" - IDS_2111 "无法初始化 FreeType" IDS_2112 "无法初始化 SDL,需要 SDL2.dll" IDS_2113 "确定要硬重置模拟器吗?" IDS_2114 "确定要退出 86Box 吗?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "请确认 " LIB_NAME_PCAP " 已安装且使用兼容 " LIB_NAME_PCAP " 的网络连接。" IDS_2131 "无效配置" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "ESC/P 打印机模拟需要" LIB_NAME_FREETYPE -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " 是将 PostScript 文件转换为 PDF 所需要的库。\n\n使用通用 PostScript 打印机打印的文档将被保存为 PostScript (.ps) 文件。" -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "FluidSynth MIDI 输出需要" LIB_NAME_FLUIDSYNTH IDS_2135 "正在进入全屏模式" IDS_2136 "不要再显示此消息" IDS_2137 "不退出" diff --git a/src/win/languages/zh-TW.rc b/src/win/languages/zh-TW.rc index 76d40d828..4c73ffb6d 100644 --- a/src/win/languages/zh-TW.rc +++ b/src/win/languages/zh-TW.rc @@ -109,7 +109,7 @@ BEGIN MENUITEM SEPARATOR MENUITEM "擷圖(&C)\tCtrl+F11", IDM_ACTION_SCREENSHOT MENUITEM SEPARATOR - MENUITEM "首選項(&P)...", IDM_PREFERENCES + MENUITEM "偏好設定(&P)...", IDM_PREFERENCES #ifdef DISCORD MENUITEM "啟用 Discord 整合(&D)", IDM_DISCORD #endif @@ -240,7 +240,7 @@ END // Dialog // -#define STR_PREFERENCES "首選項" +#define STR_PREFERENCES "偏好設定" #define STR_SND_GAIN "音量增益" #define STR_NEW_FLOPPY "新增映像" #define STR_CONFIG "設定" @@ -293,10 +293,10 @@ END #define STR_JOY3 "搖桿 3..." #define STR_JOY4 "搖桿 4..." -#define STR_SOUND1 "音訊卡 1:" -#define STR_SOUND2 "音訊卡 2:" -#define STR_SOUND3 "音訊卡 3:" -#define STR_SOUND4 "音訊卡 4:" +#define STR_SOUND1 "音效卡 1:" +#define STR_SOUND2 "音效卡 2:" +#define STR_SOUND3 "音效卡 3:" +#define STR_SOUND4 "音效卡 4:" #define STR_MIDI_OUT "MIDI 輸出裝置:" #define STR_MIDI_IN "MIDI 輸入裝置:" #define STR_MPU401 "獨立 MPU-401" @@ -357,7 +357,7 @@ END #define STR_SPECIFY "指定(&S)..." #define STR_SECTORS "磁區(S):" #define STR_HEADS "磁頭(H):" -#define STR_CYLS "柱面(C):" +#define STR_CYLS "磁柱(C):" #define STR_SIZE_MB "大小 (MB):" #define STR_TYPE "類型:" #define STR_IMG_FORMAT "映像格式:" @@ -434,7 +434,6 @@ END STRINGTABLE DISCARDABLE BEGIN - IDS_2080 "無法初始化 FluidSynth" IDS_2081 "匯流排" IDS_2082 "檔案" IDS_2083 "C" @@ -465,7 +464,6 @@ BEGIN IDS_2108 "%u MB (CHS: %i, %i, %i)" IDS_2109 "軟碟 %i (%s): %ls" IDS_2110 "所有映像 (*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF)\0*.0??;*.1??;*.??0;*.86F;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.JSON;*.TD0;*.*FD?;*.MFM;*.XDF\0進階磁區映像 (*.IMD;*.JSON;*.TD0)\0*.IMD;*.JSON;*.TD0\0基本磁區映像 (*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?)\0*.0??;*.1??;*.??0;*.BIN;*.CQ?;*.D??;*.FLP;*.HDM;*.IM?;*.XDF;*.*FD?\0Flux 映像 (*.FDI)\0*.FDI\0表面映像 (*.86F;*.MFM)\0*.86F;*.MFM\0所有檔案 (*.*)\0*.*\0" - IDS_2111 "無法初始化 FreeType" IDS_2112 "無法初始化 SDL,需要 SDL2.dll" IDS_2113 "確定要硬重設模擬器嗎?" IDS_2114 "確定要退出 86Box 嗎?" @@ -493,23 +491,11 @@ BEGIN IDS_2130 "請確認 " LIB_NAME_PCAP " 已安裝且使用相容 " LIB_NAME_PCAP " 的網路連線。" IDS_2131 "無效設定" #ifdef _WIN32 -#define LIB_NAME_FREETYPE "freetype.dll" -#else -#define LIB_NAME_FREETYPE "libfreetype" -#endif - IDS_2132 "ESC/P 印表機模擬需要" LIB_NAME_FREETYPE -#ifdef _WIN32 #define LIB_NAME_GS "gsdll32.dll" #else #define LIB_NAME_GS "libgs" #endif IDS_2133 LIB_NAME_GS " 是將 PostScript 檔案轉換為 PDF 所需要的庫。\n\n使用通用 PostScript 印表機列印的文件將被儲存為 PostScript (.ps) 檔案。" -#ifdef _WIN32 -#define LIB_NAME_FLUIDSYNTH "libfluidsynth.dll" -#else -#define LIB_NAME_FLUIDSYNTH "libfluidsynth" -#endif - IDS_2134 "FluidSynth MIDI 輸出需要" LIB_NAME_FLUIDSYNTH IDS_2135 "正在進入全螢幕模式" IDS_2136 "不要再顯示此消息" IDS_2137 "不退出" diff --git a/src/win/win_media_menu.c b/src/win/win_media_menu.c index 93d7396ae..9e5603442 100644 --- a/src/win/win_media_menu.c +++ b/src/win/win_media_menu.c @@ -544,6 +544,10 @@ media_menu_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) int ret = 0; int wp = 0; +#ifdef __clang__ + BROWSEINFO bi; +#endif + id = LOWORD(wParam) & 0x00ff; switch (LOWORD(wParam) & 0xff00) { @@ -651,10 +655,15 @@ media_menu_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_CDROM_DIR: +#ifndef __clang__ BROWSEINFO bi = { .hwndOwner = hwnd, .ulFlags = BIF_EDITBOX }; +#else + bi.hwndOwner = hwnd; + bi.ulFlags = BIF_EDITBOX; +#endif OleInitialize(NULL); int old_dopause = dopause; plat_pause(1); diff --git a/src/win/win_ui.c b/src/win/win_ui.c index e9485f7ee..deb2eb6ec 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -1493,7 +1493,7 @@ ui_init(int nCmdShow) if (!fs_off_signal && video_fullscreen && keyboard_isfsexit()) { /* Signal "exit fullscreen mode". */ fs_off_signal = 1; - } else if (fs_off_signal && video_fullscreen && keyboard_isfsexit_down()) { + } else if (fs_off_signal && video_fullscreen && keyboard_isfsexit_up()) { plat_setfullscreen(0); fs_off_signal = 0; } @@ -1501,7 +1501,7 @@ ui_init(int nCmdShow) if (!fs_on_signal && !video_fullscreen && keyboard_isfsenter()) { /* Signal "enter fullscreen mode". */ fs_on_signal = 1; - } else if (fs_on_signal && !video_fullscreen && keyboard_isfsenter_down()) { + } else if (fs_on_signal && !video_fullscreen && keyboard_isfsenter_up()) { plat_setfullscreen(1); fs_on_signal = 0; } diff --git a/vcpkg.json b/vcpkg.json index 890aeed46..f9cf6783c 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,7 +8,8 @@ "freetype", "libpng", "sdl2", - "rtmidi" + "rtmidi", + "libslirp" ], "features": { "qt-ui": { @@ -46,12 +47,6 @@ "libmt32emu" ] }, - "slirp": { - "description": "Slirp network support", - "dependencies": [ - "libslirp" - ] - }, "openal": { "description": "OpenAL sound backend", "dependencies": [