@@ -10,48 +10,41 @@ namespace Cosmos.Core
1010 /// </summary>
1111 public class MemoryBlock
1212 {
13- /// <summary>
14- /// Create new instance of the <see cref="MemoryBlock"/> class.
15- /// </summary>
16- /// <param name="aBase">A base.</param>
17- /// <param name="aByteSize">A size.</param>
18- public MemoryBlock ( uint aBase , uint aByteSize )
19- {
20- Base = aBase ;
21- Size = aByteSize ;
22- Bytes = new MemoryBlock08 ( aBase , aByteSize ) ;
23- Words = new MemoryBlock16 ( aBase , aByteSize ) ;
24- DWords = new MemoryBlock32 ( aBase , aByteSize ) ;
25- }
26-
27- #region Properties
28-
2913 /// <summary>
3014 /// Memory block base address.
3115 /// </summary>
32- public uint Base { get ; internal set ; }
33-
16+ public readonly uint Base ;
3417 /// <summary>
3518 /// Memory block size.
3619 /// </summary>
37- public uint Size { get ; internal set ; }
20+ public readonly uint Size ;
3821
3922 /// <summary>
4023 /// Bytes memory block.
4124 /// </summary>
4225 public readonly MemoryBlock08 Bytes ;
43-
4426 /// <summary>
4527 /// Words memory block.
4628 /// </summary>
4729 public readonly MemoryBlock16 Words ;
48-
4930 /// <summary>
5031 /// DWords memory block.
5132 /// </summary>
5233 public readonly MemoryBlock32 DWords ;
5334
54- #endregion
35+ /// <summary>
36+ /// Create new instance of the <see cref="MemoryBlock"/> class.
37+ /// </summary>
38+ /// <param name="aBase">A base.</param>
39+ /// <param name="aByteSize">A size.</param>
40+ public MemoryBlock ( uint aBase , uint aByteSize )
41+ {
42+ Base = aBase ;
43+ Size = aByteSize ;
44+ Bytes = new MemoryBlock08 ( aBase , aByteSize ) ;
45+ Words = new MemoryBlock16 ( aBase , aByteSize ) ;
46+ DWords = new MemoryBlock32 ( aBase , aByteSize ) ;
47+ }
5548
5649 //TODO: Fill all these methods with fast ASM
5750 //TODO: Make an attribute that can be applied to methods to tell the copmiler to inline them to save
@@ -83,8 +76,6 @@ public unsafe uint this[uint aByteOffset]
8376 }
8477 }
8578
86- #region Methods
87-
8879 /// <summary>
8980 /// Fill memory block.
9081 /// </summary>
@@ -192,8 +183,7 @@ unsafe public void Copy(uint aByteOffset, uint[] aData, int aIndex, int aCount)
192183 // TODO thow exception if aStart and aCount are not in bound. I've tried to do this but Bochs dies :-(
193184 uint * xDest = ( uint * ) ( Base + aByteOffset ) ;
194185
195- fixed ( uint * aDataPtr = aData )
196- {
186+ fixed ( uint * aDataPtr = aData ) {
197187 MemoryOperations . Copy ( xDest , aDataPtr + aIndex , aCount ) ;
198188 }
199189 }
@@ -244,7 +234,7 @@ public void Copy(int[] aData)
244234 /// <exception cref="OverflowException">Thrown if aData length in greater then Int32.MaxValue.</exception>
245235 public void Copy ( int [ ] aData , int aIndex , int aCount )
246236 {
247- if ( aData . Length < aCount )
237+ if ( aData . Length < aCount )
248238 {
249239 throw new IndexOutOfRangeException ( ) ;
250240 }
@@ -280,20 +270,6 @@ public unsafe void Copy(ManagedMemoryBlock block)
280270 MemoryOperations . Copy ( xDest , aDataPtr , ( int ) block . Size ) ;
281271 }
282272
283- /// <summary>
284- /// Swaps the internal pointer for a replacement and the replacement becomes the current pointer.
285- /// </summary>
286- /// <param name="toSwap">The pointer value to swap with.</param>
287- /// <param name="newSize">The new size that the memory block should have.</param>
288- public unsafe void Swap ( ref uint toSwap , uint newSize , out uint oldSize )
289- {
290- // Assign the old size to the output size and set the new block size.
291- ( oldSize , Size ) = ( Size , newSize ) ;
292-
293- // Swap both pointer values.
294- ( Base , toSwap ) = ( toSwap , Base ) ;
295- }
296-
297273 /// <summary>
298274 /// Move bytes array down the memory block.
299275 /// </summary>
@@ -330,7 +306,7 @@ public void MoveUp(uint aDest, uint aSrc, uint aCount)
330306 /// <exception cref="Exception">Thrown on memory access violation.</exception>
331307 public unsafe void Read8 ( byte [ ] aBuffer )
332308 {
333- if ( aBuffer . Length >= Size )
309+ if ( aBuffer . Length >= Size )
334310 {
335311 throw new Exception ( "Memory access violation" ) ;
336312 }
@@ -348,7 +324,7 @@ public unsafe void Read8(byte[] aBuffer)
348324 /// <exception cref="Exception">Thrown on memory access violation.</exception>
349325 public unsafe void Write8 ( byte [ ] aBuffer )
350326 {
351- if ( aBuffer . Length >= Size )
327+ if ( aBuffer . Length >= Size )
352328 {
353329 throw new Exception ( "Memory access violation" ) ;
354330 }
@@ -366,7 +342,7 @@ public unsafe void Write8(byte[] aBuffer)
366342 /// <exception cref="Exception">Thrown on memory access violation.</exception>
367343 public unsafe void Read16 ( ushort [ ] aBuffer )
368344 {
369- if ( aBuffer . Length >= Size )
345+ if ( aBuffer . Length >= Size )
370346 {
371347 throw new Exception ( "Memory access violation" ) ;
372348 }
@@ -384,7 +360,7 @@ public unsafe void Read16(ushort[] aBuffer)
384360 /// <exception cref="Exception">Thrown on memory access violation.</exception>
385361 public unsafe void Write16 ( ushort [ ] aBuffer )
386362 {
387- if ( aBuffer . Length >= Size )
363+ if ( aBuffer . Length >= Size )
388364 {
389365 throw new Exception ( "Memory access violation" ) ;
390366 }
@@ -402,7 +378,7 @@ public unsafe void Write16(ushort[] aBuffer)
402378 /// <exception cref="Exception">Thrown on memory access violation.</exception>
403379 public unsafe void Read32 ( uint [ ] aBuffer )
404380 {
405- if ( aBuffer . Length >= Size )
381+ if ( aBuffer . Length >= Size )
406382 {
407383 throw new Exception ( "Memory access violation" ) ;
408384 }
@@ -420,7 +396,7 @@ public unsafe void Read32(uint[] aBuffer)
420396 /// <exception cref="Exception">Thrown on memory access violation.</exception>
421397 public unsafe void Write32 ( uint [ ] aBuffer )
422398 {
423- if ( aBuffer . Length >= Size )
399+ if ( aBuffer . Length >= Size )
424400 {
425401 throw new Exception ( "Memory access violation" ) ;
426402 }
@@ -458,7 +434,6 @@ public uint[] ToArray()
458434 return ToArray ( 0 , 0 , ( int ) Size ) ;
459435 }
460436
461- #endregion
462437 }
463438
464439 /// <summary>
0 commit comments