From c64822680c4960c680243496db6c740ab1918a50 Mon Sep 17 00:00:00 2001 From: Asnivor Date: Wed, 9 Oct 2024 09:16:56 +0100 Subject: [PATCH] [CPCHawk] Some CRTC code tidy --- .../AmstradCPC/Hardware/CRTC.Type0.cs | 62 ++++++++ .../AmstradCPC/Hardware/CRTC.Type1.cs | 54 +++++++ .../AmstradCPC/Hardware/CRTC.Type2.cs | 54 +++++++ .../AmstradCPC/Hardware/CRTC.Type3.cs | 62 ++++++++ .../AmstradCPC/Hardware/CRTC.Type4.cs | 61 ++++++++ .../Computers/AmstradCPC/Hardware/CRTC.cs | 139 +++--------------- 6 files changed, 317 insertions(+), 115 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type0.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type0.cs index 3bc6feb7a2..a9fc46ab3f 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type0.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type0.cs @@ -239,6 +239,68 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } } + + /// + /// R3l: CRTC-type horizontal sync width independent helper function + /// + protected override int R3_HorizontalSyncWidth + { + get + { + // Bits 3..0 define Horizontal Sync Width + // on CRTC0, a zero value means no HSYNC is generated + return Register[R3_SYNC_WIDTHS] & 0x0F; + } + } + + /// + /// R3h: CRTC-type vertical sync width independent helper function + /// + protected override int R3_VerticalSyncWidth + { + get + { + // Bits 7..4 define Vertical Sync Width + // on CRTC0 if 0 is programmed this gives 16 lines of VSYNC + return ((Register[R3_SYNC_WIDTHS] >> 4) & 0x0F) == 0 ? 16 : Register[R3_SYNC_WIDTHS] >> 4 & 0x0F; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_CUDISP + { + get + { + // CRTC0 + // Bits 7..6 define the skew (delay) of the CUDISP signal + // 00 = 0 + // 01 = 1 + // 10 = 2 + // 11 = non-output + return (Register[R8_INTERLACE_MODE] >> 6) & 0x03; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_DISPTMG + { + get + { + // CRTC0 + // Bits 5..4 define the skew (delay) of the DISPTMG signal + // 00 = 0 + // 01 = 1 + // 10 = 2 + // 11 = non-output + return ((Register[R8_INTERLACE_MODE] & 0b0011_0000) >> 4) & 0x03; + } + } + + /// /// Attempts to read from the currently selected register /// diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type1.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type1.cs index ef0fcffffb..129bf4c5af 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type1.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type1.cs @@ -244,6 +244,60 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } } + + /// + /// R3l: CRTC-type horizontal sync width independent helper function + /// + protected override int R3_HorizontalSyncWidth + { + get + { + // Bits 3..0 define Horizontal Sync Width + // on CRTC1, a zero value means no HSYNC is generated + return Register[R3_SYNC_WIDTHS] & 0x0F; + } + } + + /// + /// R3h: CRTC-type vertical sync width independent helper function + /// + protected override int R3_VerticalSyncWidth + { + get + { + // Bits 7..4 are ignored + // on CRTC1 VSYNC is fixed at 16 lines + return 16; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_CUDISP + { + get + { + // CRTC1 + // Bits 7..6 are ignored + return 0; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_DISPTMG + { + get + { + // CRTC1 + // Bits 5..4 are ignored + return 0; + } + } + + /// /// Attempts to read from the currently selected register /// diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type2.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type2.cs index 8542e90b25..63d2886612 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type2.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type2.cs @@ -241,6 +241,60 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } } + + /// + /// R3l: CRTC-type horizontal sync width independent helper function + /// + protected override int R3_HorizontalSyncWidth + { + get + { + // Bits 3..0 define Horizontal Sync Width + // on CRTC2, a zero value means 16 characters of HSYNC are generated + return (Register[R3_SYNC_WIDTHS] & 0x0F) == 0 ? 16 : Register[R3_SYNC_WIDTHS] & 0x0F; + } + } + + /// + /// R3h: CRTC-type vertical sync width independent helper function + /// + protected override int R3_VerticalSyncWidth + { + get + { + // Bits 7..4 are ignored + // on CRTC2 VSYNC is fixed at 16 lines + return 16; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_CUDISP + { + get + { + // CRTC2 + // Bits 7..6 are ignored + return 0; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_DISPTMG + { + get + { + // CRTC2 + // Bits 5..4 are ignored + return 0; + } + } + + /// /// Attempts to read from the currently selected register /// diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type3.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type3.cs index c586855ae8..8d5cab6dac 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type3.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type3.cs @@ -239,6 +239,68 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } } + + /// + /// R3l: CRTC-type horizontal sync width independent helper function + /// + protected override int R3_HorizontalSyncWidth + { + get + { + // Bits 3..0 define Horizontal Sync Width + // on CRTC3, a zero value means 16 characters of HSYNC are generated + return (Register[R3_SYNC_WIDTHS] & 0x0F) == 0 ? 16 : Register[R3_SYNC_WIDTHS] & 0x0F; + } + } + + /// + /// R3h: CRTC-type vertical sync width independent helper function + /// + protected override int R3_VerticalSyncWidth + { + get + { + // Bits 7..4 define Vertical Sync Width + // on CRTC3 if 0 is programmed this gives 16 lines of VSYNC + return ((Register[R3_SYNC_WIDTHS] >> 4) & 0x0F) == 0 ? 16 : Register[R3_SYNC_WIDTHS] >> 4 & 0x0F; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_CUDISP + { + get + { + // CRTC3 + // Bits 7..6 define the skew (delay) of the CUDISP signal + // 00 = 0 + // 01 = 1 + // 10 = 2 + // 11 = non-output + return (Register[R8_INTERLACE_MODE] >> 6) & 0x03; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_DISPTMG + { + get + { + // CRTC3 + // Bits 5..4 define the skew (delay) of the DISPTMG signal + // 00 = 0 + // 01 = 1 + // 10 = 2 + // 11 = non-output + return ((Register[R8_INTERLACE_MODE] & 0b0011_0000) >> 4) & 0x03; + } + } + + /// /// Attempts to read from the currently selected register /// diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type4.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type4.cs index 78cd3a2cc9..4d30634320 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type4.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.Type4.cs @@ -240,6 +240,67 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } } + + /// + /// R3l: CRTC-type horizontal sync width independent helper function + /// + protected override int R3_HorizontalSyncWidth + { + get + { + // Bits 3..0 define Horizontal Sync Width + // on CRTC4, a zero value means 16 characters of HSYNC are generated + return (Register[R3_SYNC_WIDTHS] & 0x0F) == 0 ? 16 : Register[R3_SYNC_WIDTHS] & 0x0F; + } + } + + /// + /// R3h: CRTC-type vertical sync width independent helper function + /// + protected override int R3_VerticalSyncWidth + { + get + { + // Bits 7..4 define Vertical Sync Width + // on CRTC4 if 0 is programmed this gives 16 lines of VSYNC + return ((Register[R3_SYNC_WIDTHS] >> 4) & 0x0F) == 0 ? 16 : Register[R3_SYNC_WIDTHS] >> 4 & 0x0F; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_CUDISP + { + get + { + // CRTC4 + // Bits 7..6 define the skew (delay) of the CUDISP signal + // 00 = 0 + // 01 = 1 + // 10 = 2 + // 11 = non-output + return (Register[R8_INTERLACE_MODE] >> 6) & 0x03; + } + } + + /// + /// R8: CRTC-type CUDISP Active Display Skew helper function + /// + protected override int R8_Skew_DISPTMG + { + get + { + // CRTC4 + // Bits 5..4 define the skew (delay) of the DISPTMG signal + // 00 = 0 + // 01 = 1 + // 10 = 2 + // 11 = non-output + return ((Register[R8_INTERLACE_MODE] & 0b0011_0000) >> 4) & 0x03; + } + } + /// /// Attempts to read from the currently selected register /// diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.cs index 6f67da5719..7ae24c4dcf 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/CRTC.cs @@ -349,7 +349,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC protected byte StatusRegister; /// - /// CRTC-type horizontal total independent helper function + /// R0: CRTC-type horizontal total independent helper function /// protected virtual int R0_HorizontalTotal { @@ -361,7 +361,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } /// - /// CRTC-type horizontal displayed independent helper function + /// R1: CRTC-type horizontal displayed independent helper function /// protected virtual int R1_HorizontalDisplayed { @@ -373,7 +373,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } /// - /// CRTC-type horizontal sync position independent helper function + /// R2: CRTC-type horizontal sync position independent helper function /// protected virtual int R2_HorizontalSyncPosition { @@ -385,71 +385,17 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } /// - /// CRTC-type horizontal sync width independent helper function + /// R3l: CRTC-type horizontal sync width independent helper function /// - protected virtual int R3_HorizontalSyncWidth - { - get - { - int swr; - - // Bits 3..0 define Horizontal Sync Width - int sw = Register[R3_SYNC_WIDTHS] & 0x0F; - - switch (CrtcType) - { - case 0: - case 1: - // If 0 is programmed no HSYNC is generated - swr = sw; - break; - case 2: - case 3: - case 4: - default: - // If 0 is programmed this gives a HSYNC width of 16 - swr = sw > 0 ? sw : 16; - break; - } - - return swr; - } - } + protected virtual int R3_HorizontalSyncWidth { get; } /// - /// CRTC-type vertical sync width independent helper function + /// R3h: CRTC-type vertical sync width independent helper function /// - protected virtual int R3_VerticalSyncWidth - { - get - { - int swr; - - //Bits 7..4 define Vertical Sync Width - int sw = (Register[R3_SYNC_WIDTHS] >> 4) & 0x0F; - - switch (CrtcType) - { - case 0: - case 3: - case 4: - default: - // If 0 is programmed this gives 16 lines of VSYNC - swr = sw > 0 ? sw : 16; - break; - case 1: - case 2: - // Vertical Sync is fixed at 16 lines - swr = 16; - break; - } - - return swr; - } - } + protected virtual int R3_VerticalSyncWidth { get; } /// - /// CRTC-type vertical total independent helper function + /// R4: CRTC-type vertical total independent helper function /// protected virtual int R4_VerticalTotal { @@ -461,7 +407,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } /// - /// CRTC-type vertical total adjust independent helper function + /// R5: CRTC-type vertical total adjust independent helper function /// protected virtual int R5_VerticalTotalAdjust { @@ -473,7 +419,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } /// - /// CRTC-type vertical displayed independent helper function + /// R6: CRTC-type vertical displayed independent helper function /// protected virtual int R6_VerticalDisplayed { @@ -485,7 +431,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } /// - /// CRTC-type vertical sync position independent helper function + /// R7: CRTC-type vertical sync position independent helper function /// protected virtual int R7_VerticalSyncPosition { @@ -497,68 +443,31 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } /// - /// CRTC-type DISPTMG Active Display Skew helper function + /// R8: CRTC-type CUDISP Active Display Skew helper function /// - protected virtual int R8_Skew - { - get - { - int skew = 0; - switch (CrtcType) - { - case 0: - // For Hitachi HD6845: - // 0 = no skew - // 1 = one-character skew - // 2 = two-character skew - // 3 = non-output - skew = (Register[R8_INTERLACE_MODE] >> 4) & 0x03; - break; - case 1: - // skew not implemented - break; - case 2: - // skew not implemented - break; - default: - return skew; - } - return skew; - } - } + protected virtual int R8_Skew_CUDISP { get; } /// - /// CRTC-type Interlace Mode helper function + /// R8: CRTC-type DISPTMG Active Display Skew helper function + /// + protected virtual int R8_Skew_DISPTMG { get; } + + /// + /// R8: CRTC-type Interlace Mode helper function /// protected virtual int R8_Interlace { get { - int interlace = 0; - switch (CrtcType) - { - - case 0: - case 1: - case 2: - // 0 = Non-interlace - // 1 = Interlace SYNC Raster Scan - // 2 = Interlace SYNC and Video Raster Scan - interlace = Register[R8_INTERLACE_MODE] & 0x03; - if (!interlace.Bit(0)) - { - interlace = 0; - } - break; - default: - break; - } - return interlace; + // 0 = Non-interlace + // 1 = Interlace SYNC Raster Scan + // 2 = Interlace SYNC and Video Raster Scan + return Register[R8_INTERLACE_MODE] & 0x03; } } /// - /// Max Scanlines + /// R9: Max Scanlines /// protected virtual int R9_MaxScanline {