diff --git a/src/disk/hdd_image.c b/src/disk/hdd_image.c index eff860804..bccf13374 100644 --- a/src/disk/hdd_image.c +++ b/src/disk/hdd_image.c @@ -499,20 +499,16 @@ hdd_image_read(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) int non_transferred_sectors = mvhd_read_sectors(hdd_images[id].vhd, sector, count, buffer); hdd_images[id].pos = sector + count - non_transferred_sectors - 1; } else { - int i; - if (fseeko64(hdd_images[id].file, ((uint64_t)(sector) << 9LL) + hdd_images[id].base, SEEK_SET) == -1) { fatal("Hard disk image %i: Read error during seek\n", id); return; } - for (i = 0; i < count; i++) { - if (feof(hdd_images[id].file)) - break; - - hdd_images[id].pos = sector + i; - fread(buffer + (i << 9), 1, 512, hdd_images[id].file); + size_t num_read = fread(buffer, 512, count, hdd_images[id].file); + if (num_read != count) { + fatal("Hard disk image %i: Read error\n", id); } + hdd_images[id].pos = sector + num_read; } } @@ -555,20 +551,16 @@ hdd_image_write(uint8_t id, uint32_t sector, uint32_t count, uint8_t *buffer) int non_transferred_sectors = mvhd_write_sectors(hdd_images[id].vhd, sector, count, buffer); hdd_images[id].pos = sector + count - non_transferred_sectors - 1; } else { - int i; - if (fseeko64(hdd_images[id].file, ((uint64_t)(sector) << 9LL) + hdd_images[id].base, SEEK_SET) == -1) { fatal("Hard disk image %i: Write error during seek\n", id); return; } - for (i = 0; i < count; i++) { - if (feof(hdd_images[id].file)) - break; - - hdd_images[id].pos = sector + i; - fwrite(buffer + (i << 9), 512, 1, hdd_images[id].file); + size_t num_write = fwrite(buffer, 512, count, hdd_images[id].file); + if (num_write != count) { + fatal("Hard disk image %i: Write error\n", id); } + hdd_images[id].pos = sector + num_write; } } diff --git a/src/port_6x.c b/src/port_6x.c index dafa5d987..62b1558fb 100644 --- a/src/port_6x.c +++ b/src/port_6x.c @@ -71,70 +71,75 @@ port_6x_write(uint16_t port, uint8_t val, void *priv) } } - static uint8_t -port_6x_read(uint16_t port, void *priv) +port_61_read_simple(uint16_t port, void *priv) { - port_6x_t *dev = (port_6x_t *) priv; - uint8_t ret = 0xff; + uint8_t ret = ppi.pb & 0x1f; - port &= 3; - - if ((port == 3) && (dev->flags & PORT_6X_MIRROR)) - port = 1; - - switch (port) { - case 1: - if (dev->flags & PORT_6X_EXT_REF) { - ret = ppi.pb & 0x0f; - - if (dev->refresh) - ret |= 0x10; - } else - ret = ppi.pb & 0x1f; - - if (ppispeakon) - ret |= 0x20; - - if (dev->flags & PORT_6X_TURBO) - ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00); - break; - case 2: - if (dev->flags & PORT_6X_SWA) { - /* SWA on Olivetti M240 mainboard (off=1) */ - ret = 0x00; - if (ppi.pb & 0x8) { - /* Switches 4, 5 - floppy drives (number) */ - int i, fdd_count = 0; - for (i = 0; i < FDD_NUM; i++) { - if (fdd_get_flags(i)) - fdd_count++; - } - if (!fdd_count) - ret |= 0x00; - else - ret |= ((fdd_count - 1) << 2); - /* Switches 6, 7 - monitor type */ - if (video_is_mda()) - ret |= 0x3; - else if (video_is_cga()) - ret |= 0x2; /* 0x10 would be 40x25 */ - else - ret |= 0x0; - } else { - /* bit 2 always on */ - ret |= 0x4; - /* Switch 8 - 8087 FPU. */ - if (hasfpu) - ret |= 0x02; - } - } - break; - } + if (ppispeakon) + ret |= 0x20; return(ret); } +static uint8_t +port_61_read(uint16_t port, void *priv) +{ + port_6x_t *dev = (port_6x_t *) priv; + uint8_t ret = 0xff; + + if (dev->flags & PORT_6X_EXT_REF) { + ret = ppi.pb & 0x0f; + + if (dev->refresh) + ret |= 0x10; + } else + ret = ppi.pb & 0x1f; + + if (ppispeakon) + ret |= 0x20; + + if (dev->flags & PORT_6X_TURBO) + ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00); + + return(ret); +} + +static uint8_t +port_62_read(uint16_t port, void *priv) +{ + uint8_t ret = 0xff; + + /* SWA on Olivetti M240 mainboard (off=1) */ + ret = 0x00; + if (ppi.pb & 0x8) { + /* Switches 4, 5 - floppy drives (number) */ + int i, fdd_count = 0; + for (i = 0; i < FDD_NUM; i++) { + if (fdd_get_flags(i)) + fdd_count++; + } + if (!fdd_count) + ret |= 0x00; + else + ret |= ((fdd_count - 1) << 2); + /* Switches 6, 7 - monitor type */ + if (video_is_mda()) + ret |= 0x3; + else if (video_is_cga()) + ret |= 0x2; /* 0x10 would be 40x25 */ + else + ret |= 0x0; + } else { + /* bit 2 always on */ + ret |= 0x4; + /* Switch 8 - 8087 FPU. */ + if (hasfpu) + ret |= 0x02; + } + + return(ret); +} static void port_6x_refresh(void *priv) @@ -165,10 +170,19 @@ port_6x_init(const device_t *info) dev->flags = info->local & 0xff; - io_sethandler(0x0061, 3, port_6x_read, NULL, NULL, port_6x_write, NULL, NULL, dev); + if (!(dev->flags & PORT_6X_TURBO) || (dev->flags & PORT_6X_EXT_REF)) + io_sethandler(0x0061, 1, port_61_read_simple, NULL, NULL, port_6x_write, NULL, NULL, dev); + else + io_sethandler(0x0061, 1, port_61_read, NULL, NULL, port_6x_write, NULL, NULL, dev); + + if (dev->flags & PORT_6X_SWA) + io_sethandler(0x0062, 1, port_62_read, NULL, NULL, NULL, NULL, NULL, dev); + + if (dev->flags & PORT_6X_MIRROR) + io_sethandler(0x0063, 1, port_61_read, NULL, NULL, port_6x_write, NULL, NULL, dev); if (dev->flags & PORT_6X_EXT_REF) - timer_add(&dev->refresh_timer, port_6x_refresh, dev, 1); + timer_add(&dev->refresh_timer, port_6x_refresh, dev, 1); return dev; } diff --git a/src/qt/sdl_joystick.cpp b/src/qt/sdl_joystick.cpp index 0e7bfd619..ab72145c3 100644 --- a/src/qt/sdl_joystick.cpp +++ b/src/qt/sdl_joystick.cpp @@ -107,6 +107,8 @@ void joystick_process() { int c, d; + if (!joystick_type) return; + SDL_JoystickUpdate(); for (c = 0; c < joysticks_present; c++) {