diff --git a/src/86box.c b/src/86box.c index 277d842b4..f8c3365ef 100644 --- a/src/86box.c +++ b/src/86box.c @@ -224,6 +224,8 @@ int other_ide_present = 0; /* IDE control int other_scsi_present = 0; /* SCSI controllers from non-SCSI cards are present */ +int is_pcjr = 0; /* The current machine is PCjr. */ + // Accelerator key array struct accelKey acc_keys[NUM_ACCELS]; diff --git a/src/game/gameport.c b/src/game/gameport.c index 5bbfe8aac..3025ee5eb 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -252,7 +252,7 @@ gameport_write(UNUSED(uint16_t addr), UNUSED(uint8_t val), void *priv) /* Notify the interface. */ joystick->intf->write(joystick->dat); - cycles -= ISA_CYCLES(8); + cycles -= ISA_CYCLES((8 << is_pcjr)); } static uint8_t @@ -268,7 +268,7 @@ gameport_read(UNUSED(uint16_t addr), void *priv) /* Merge axis state with button state. */ uint8_t ret = joystick->state | joystick->intf->read(joystick->dat); - cycles -= ISA_CYCLES(8); + cycles -= ISA_CYCLES((8 << is_pcjr)); return ret; } diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index bba99b555..55ba98567 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -154,9 +154,10 @@ extern int confirm_reset; /* (C) enable reset confirmation */ extern int confirm_exit; /* (C) enable exit confirmation */ extern int confirm_save; /* (C) enable save confirmation */ extern int enable_discord; /* (C) enable Discord integration */ -extern int force_10ms; /* (C) force 10ms CPU frame interval */ +extern int force_10ms; /* (C) force 10ms CPU frame interval */ extern int other_ide_present; /* IDE controllers from non-IDE cards are present */ extern int other_scsi_present; /* SCSI controllers from non-SCSI cards are present */ +extern int is_pcjr; /* The current machine is PCjr. */ extern int hard_reset_pending; extern int fixed_size_x; diff --git a/src/include/86box/mem.h b/src/include/86box/mem.h index 53001b8db..8710fca51 100644 --- a/src/include/86box/mem.h +++ b/src/include/86box/mem.h @@ -483,6 +483,8 @@ extern void mem_remap_top_nomid(int kb); extern void umc_smram_recalc(uint32_t start, int set); +extern void pcjr_waitstates(void *); + extern mem_mapping_t *read_mapping[MEM_MAPPINGS_NO]; extern mem_mapping_t *write_mapping[MEM_MAPPINGS_NO]; diff --git a/src/machine/m_pcjr.c b/src/machine/m_pcjr.c index 30a5e609a..092c00b8f 100644 --- a/src/machine/m_pcjr.c +++ b/src/machine/m_pcjr.c @@ -829,6 +829,8 @@ machine_pcjr_init(UNUSED(const machine_t *model)) pcjr = calloc(1, sizeof(pcjr_t)); + is_pcjr = 1; + pic_init_pcjr(); pit_common_init(0, pit_irq0_timer_pcjr, NULL); diff --git a/src/machine/machine.c b/src/machine/machine.c index 6a86b785f..66bffdbd2 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -123,6 +123,8 @@ machine_init_ex(int m) pci_flags = 0x00000000; } + is_pcjr = 0; + /* All good, boot the machine! */ if (machines[m].init) ret = machines[m].init(&machines[m]); diff --git a/src/mem/mem.c b/src/mem/mem.c index fa749002c..a544f333c 100644 --- a/src/mem/mem.c +++ b/src/mem/mem.c @@ -1840,6 +1840,9 @@ mem_read_ram(uint32_t addr, UNUSED(void *priv)) mem_log("Read B %02X from %08X\n", ram[addr], addr); #endif + if (is_pcjr) + pcjr_waitstates(NULL); + if (cpu_use_exec) addreadlookup(mem_logical_addr, addr); @@ -2100,6 +2103,9 @@ mem_write_ram(uint32_t addr, uint8_t val, UNUSED(void *priv)) if ((addr >= 0xa0000) && (addr <= 0xbffff)) mem_log("Write B %02X to %08X\n", val, addr); #endif + if (is_pcjr) + pcjr_waitstates(NULL); + if (cpu_use_exec) { addwritelookup(mem_logical_addr, addr); mem_write_ramb_page(addr, val, &pages[addr >> 12]); diff --git a/src/video/vid_pcjr.c b/src/video/vid_pcjr.c index 2b3eb730a..b4a2d24db 100644 --- a/src/video/vid_pcjr.c +++ b/src/video/vid_pcjr.c @@ -35,6 +35,8 @@ #include <86box/video.h> #include <86box/vid_cga.h> #include <86box/vid_cga_comp.h> +#include <86box/plat_unused.h> +#include "cpu.h" #include <86box/m_pcjr.h> @@ -194,6 +196,16 @@ vid_in(uint16_t addr, void *priv) return ret; } +void +pcjr_waitstates(UNUSED(void *priv)) +{ + int ws_array[16] = { 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 }; + int ws; + + ws = ws_array[cycles & 0xf]; + cycles -= ws; +} + static void vid_write(uint32_t addr, uint8_t val, void *priv) { @@ -202,6 +214,8 @@ vid_write(uint32_t addr, uint8_t val, void *priv) if (pcjr->memctrl == -1) return; + pcjr_waitstates(NULL); + pcjr->b8000[addr & 0x3fff] = val; } @@ -213,6 +227,8 @@ vid_read(uint32_t addr, void *priv) if (pcjr->memctrl == -1) return 0xff; + pcjr_waitstates(NULL); + return (pcjr->b8000[addr & 0x3fff]); }