@@ -1711,7 +1711,17 @@ public unsafe ushort XMPHeaderCRC
17111711 Utilities . Convert16bitUnsignedInteger ( ref xmpHeader . checksum [ 0 ] , ref xmpHeader . checksum [ 1 ] , value ) ;
17121712 }
17131713 }
1714-
1714+ public unsafe ushort ExpoCRC
1715+ {
1716+ get
1717+ {
1718+ return Utilities . ConvertBytes ( rawExpo . checksum [ 0 ] , rawExpo . checksum [ 1 ] ) ;
1719+ }
1720+ set
1721+ {
1722+ Utilities . Convert16bitUnsignedInteger ( ref rawExpo . checksum [ 0 ] , ref rawExpo . checksum [ 1 ] , value ) ;
1723+ }
1724+ }
17151725 public FormFactorEnum ? FormFactor
17161726 {
17171727 get
@@ -1982,6 +1992,31 @@ public byte[] GetXMPHeaderBytes()
19821992
19831993 return bytes ;
19841994 }
1995+ public byte [ ] GetEXPOBytes ( )
1996+ {
1997+ byte [ ] bytes = new byte [ EXPOSize ] ;
1998+
1999+ // Convert raw SPD to byte array.
2000+ IntPtr ptr = IntPtr . Zero ;
2001+ try
2002+ {
2003+ int expoSize = Marshal . SizeOf < RawEXPO > ( ) ;
2004+ ptr = Marshal . AllocHGlobal ( expoSize ) ;
2005+ Marshal . StructureToPtr ( rawExpo , ptr , true ) ;
2006+ Marshal . Copy ( ptr , bytes , 0 , expoSize ) ;
2007+ }
2008+ catch ( Exception e )
2009+ {
2010+ MessageBox . Show ( e . Message , "Failed to save SPD data" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
2011+ return null ;
2012+ }
2013+ finally
2014+ {
2015+ Marshal . FreeHGlobal ( ptr ) ;
2016+ }
2017+
2018+ return bytes ;
2019+ }
19852020
19862021 public void UpdateXMPHeaderCRC ( )
19872022 {
@@ -1990,6 +2025,12 @@ public void UpdateXMPHeaderCRC()
19902025 XMPHeaderCRC = Utilities . Crc16 ( rawXmpHeaderBytes . Take ( 0x3D + 1 ) . ToArray ( ) ) ;
19912026 }
19922027
2028+ public void UpdateEXPOCRC ( ) {
2029+ // Update EXPO CRC
2030+ var expoBytes = GetEXPOBytes ( ) ;
2031+ ExpoCRC = Utilities . Crc16 ( expoBytes . Take ( 0x7D + 1 ) . ToArray ( ) ) ;
2032+ }
2033+
19932034 public void UpdateCrc ( )
19942035 {
19952036 // Update JEDEC block checksum
@@ -2022,6 +2063,11 @@ public void UpdateCrc()
20222063 xmp [ 4 ] . UpdateCrc ( ) ;
20232064 }
20242065 }
2066+
2067+ if ( expoFound )
2068+ {
2069+ UpdateEXPOCRC ( ) ;
2070+ }
20252071 }
20262072
20272073 public byte [ ] GetBytes ( )
@@ -2075,8 +2121,9 @@ public byte[] GetBytes()
20752121 // EXPO takes XMP profile 3 and user profile 1
20762122 if ( expoFound )
20772123 {
2078- byte [ ] expo1Bytes = EXPO1 . GetBytes ( ) ;
2079- Array . Copy ( expo1Bytes , 0 , bytes , EXPO . EXPOOffset , expo1Bytes . Length ) ;
2124+ rawExpo . profile1 = EXPO1 . rawEXPOProfile ;
2125+ byte [ ] expoBytes = GetEXPOBytes ( ) ;
2126+ Array . Copy ( expoBytes , 0 , bytes , EXPOOffset , expoBytes . Length ) ;
20802127 }
20812128 else
20822129 {
0 commit comments