Merge pull request #2441 from elyosh/optim001

Various small performance optimisations
This commit is contained in:
Miran Grča
2022-07-10 16:21:40 +02:00
committed by GitHub
3 changed files with 83 additions and 75 deletions

View File

@@ -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); int non_transferred_sectors = mvhd_read_sectors(hdd_images[id].vhd, sector, count, buffer);
hdd_images[id].pos = sector + count - non_transferred_sectors - 1; hdd_images[id].pos = sector + count - non_transferred_sectors - 1;
} else { } else {
int i;
if (fseeko64(hdd_images[id].file, ((uint64_t)(sector) << 9LL) + hdd_images[id].base, SEEK_SET) == -1) { 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); fatal("Hard disk image %i: Read error during seek\n", id);
return; return;
} }
for (i = 0; i < count; i++) { size_t num_read = fread(buffer, 512, count, hdd_images[id].file);
if (feof(hdd_images[id].file)) if (num_read != count) {
break; fatal("Hard disk image %i: Read error\n", id);
hdd_images[id].pos = sector + i;
fread(buffer + (i << 9), 1, 512, hdd_images[id].file);
} }
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); int non_transferred_sectors = mvhd_write_sectors(hdd_images[id].vhd, sector, count, buffer);
hdd_images[id].pos = sector + count - non_transferred_sectors - 1; hdd_images[id].pos = sector + count - non_transferred_sectors - 1;
} else { } else {
int i;
if (fseeko64(hdd_images[id].file, ((uint64_t)(sector) << 9LL) + hdd_images[id].base, SEEK_SET) == -1) { 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); fatal("Hard disk image %i: Write error during seek\n", id);
return; return;
} }
for (i = 0; i < count; i++) { size_t num_write = fwrite(buffer, 512, count, hdd_images[id].file);
if (feof(hdd_images[id].file)) if (num_write != count) {
break; fatal("Hard disk image %i: Write error\n", id);
hdd_images[id].pos = sector + i;
fwrite(buffer + (i << 9), 512, 1, hdd_images[id].file);
} }
hdd_images[id].pos = sector + num_write;
} }
} }

View File

@@ -71,20 +71,23 @@ port_6x_write(uint16_t port, uint8_t val, void *priv)
} }
} }
static uint8_t
port_61_read_simple(uint16_t port, void *priv)
{
uint8_t ret = ppi.pb & 0x1f;
if (ppispeakon)
ret |= 0x20;
return(ret);
}
static uint8_t static uint8_t
port_6x_read(uint16_t port, void *priv) port_61_read(uint16_t port, void *priv)
{ {
port_6x_t *dev = (port_6x_t *) priv; port_6x_t *dev = (port_6x_t *) priv;
uint8_t ret = 0xff; uint8_t ret = 0xff;
port &= 3;
if ((port == 3) && (dev->flags & PORT_6X_MIRROR))
port = 1;
switch (port) {
case 1:
if (dev->flags & PORT_6X_EXT_REF) { if (dev->flags & PORT_6X_EXT_REF) {
ret = ppi.pb & 0x0f; ret = ppi.pb & 0x0f;
@@ -98,9 +101,15 @@ port_6x_read(uint16_t port, void *priv)
if (dev->flags & PORT_6X_TURBO) if (dev->flags & PORT_6X_TURBO)
ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00); ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00);
break;
case 2: return(ret);
if (dev->flags & PORT_6X_SWA) { }
static uint8_t
port_62_read(uint16_t port, void *priv)
{
uint8_t ret = 0xff;
/* SWA on Olivetti M240 mainboard (off=1) */ /* SWA on Olivetti M240 mainboard (off=1) */
ret = 0x00; ret = 0x00;
if (ppi.pb & 0x8) { if (ppi.pb & 0x8) {
@@ -128,14 +137,10 @@ port_6x_read(uint16_t port, void *priv)
if (hasfpu) if (hasfpu)
ret |= 0x02; ret |= 0x02;
} }
}
break;
}
return(ret); return(ret);
} }
static void static void
port_6x_refresh(void *priv) port_6x_refresh(void *priv)
{ {
@@ -165,7 +170,16 @@ port_6x_init(const device_t *info)
dev->flags = info->local & 0xff; 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) 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);

View File

@@ -107,6 +107,8 @@ void joystick_process()
{ {
int c, d; int c, d;
if (!joystick_type) return;
SDL_JoystickUpdate(); SDL_JoystickUpdate();
for (c = 0; c < joysticks_present; c++) for (c = 0; c < joysticks_present; c++)
{ {