From 16589b558fd0ff16e39c4a1811209f1f345d0126 Mon Sep 17 00:00:00 2001 From: ekeeke Date: Fri, 19 Jan 2024 00:01:02 +0100 Subject: [PATCH] [Core/CD] improved accuracy of CDC transfer to Main-CPU (resp. Sub-CPU) when destination is set to Sub-CPU (resp. Main-CPU) (verified on real hardware, cf. Krikzz's mcd-verificator) --- core/cd_hw/cdc.c | 8 ++++---- core/cd_hw/cdc.h | 7 +++++-- core/cd_hw/scd.c | 2 +- core/mem68k.c | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/core/cd_hw/cdc.c b/core/cd_hw/cdc.c index 1679a16..db6efa6 100644 --- a/core/cd_hw/cdc.c +++ b/core/cd_hw/cdc.c @@ -2,7 +2,7 @@ * Genesis Plus * CD data controller (LC8951x compatible) * - * Copyright (C) 2012-2023 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2012-2024 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -769,13 +769,13 @@ unsigned char cdc_reg_r(void) return data; } -unsigned short cdc_host_r(void) +unsigned short cdc_host_r(uint8 cpu_access) { /* read CDC buffered data (gate-array register $08) */ uint16 data = scd.regs[0x08>>1].w; - /* check if host data transfer is enabled */ - if (scd.regs[0x04>>1].byte.h & 0x40) + /* check if host data transfer is started for selected CPU */ + if ((scd.regs[0x04>>1].byte.h & 0x47) == cpu_access) { /* check if EDT bit (gate-array register $04) is set (host data transfer is finished) */ if (scd.regs[0x04>>1].byte.h & 0x80) diff --git a/core/cd_hw/cdc.h b/core/cd_hw/cdc.h index fe85e6a..a33af9d 100644 --- a/core/cd_hw/cdc.h +++ b/core/cd_hw/cdc.h @@ -2,7 +2,7 @@ * Genesis Plus * CD data controller (LC8951x compatible) * - * Copyright (C) 2012-2023 Eke-Eke (Genesis Plus GX) + * Copyright (C) 2012-2024 Eke-Eke (Genesis Plus GX) * * Redistribution and use of this code or any derivative works are permitted * provided that the following conditions are met: @@ -40,6 +40,9 @@ #define cdc scd.cdc_hw +#define CDC_MAIN_CPU_ACCESS 0x42 +#define CDC_SUB_CPU_ACCESS 0x43 + /* CDC hardware */ typedef struct { @@ -67,6 +70,6 @@ extern void cdc_dma_update(void); extern void cdc_decoder_update(uint32 header); extern void cdc_reg_w(unsigned char data); extern unsigned char cdc_reg_r(void); -extern unsigned short cdc_host_r(void); +extern unsigned short cdc_host_r(uint8 cpu_access); #endif diff --git a/core/cd_hw/scd.c b/core/cd_hw/scd.c index 76d0095..0fb03a8 100644 --- a/core/cd_hw/scd.c +++ b/core/cd_hw/scd.c @@ -680,7 +680,7 @@ static unsigned int scd_read_word(unsigned int address) /* CDC host data (word access only ?) */ if (address == 0x08) { - return cdc_host_r(); + return cdc_host_r(CDC_SUB_CPU_ACCESS); } /* LED & RESET status */ diff --git a/core/mem68k.c b/core/mem68k.c index cae39b0..43f9bb7 100644 --- a/core/mem68k.c +++ b/core/mem68k.c @@ -537,7 +537,7 @@ unsigned int ctrl_io_read_word(unsigned int address) { s68k_sync(); } - return cdc_host_r(); + return cdc_host_r(CDC_MAIN_CPU_ACCESS); } /* H-INT vector (word access only ?) */