Optimize port_6x
Try to avoid branching as this is a hot path in some machines About 250% speedup
This commit is contained in:
132
src/port_6x.c
132
src/port_6x.c
@@ -71,70 +71,75 @@ port_6x_write(uint16_t port, uint8_t val, void *priv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint8_t
|
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 = ppi.pb & 0x1f;
|
||||||
uint8_t ret = 0xff;
|
|
||||||
|
|
||||||
port &= 3;
|
if (ppispeakon)
|
||||||
|
ret |= 0x20;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(ret);
|
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
|
static void
|
||||||
port_6x_refresh(void *priv)
|
port_6x_refresh(void *priv)
|
||||||
@@ -165,10 +170,19 @@ 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);
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user