Last active
October 5, 2016 08:20
-
-
Save toptensoftware/51cffedbb4158bbbb508c98d5b9a64da to your computer and use it in GitHub Desktop.
Connecting the CPU to the Global Heap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Read a byte from the global heap | |
| public byte ReadByte(ushort seg, ushort offset) | |
| { | |
| // Crack the selector | |
| var sel = GetSelector(seg); | |
| try | |
| { | |
| // Read it | |
| return sel.allocation.buffer[((seg >> 3) - sel.selectorIndex) << 16 | offset]; | |
| } | |
| catch (NullReferenceException) | |
| { | |
| throw new Sharp86.SegmentNotPresentException(); | |
| } | |
| catch (IndexOutOfRangeException) | |
| { | |
| throw new Sharp86.GeneralProtectionFaultException(); | |
| } | |
| } | |
| // Write a byte to the global heap | |
| public void WriteByte(ushort seg, ushort offset, byte value) | |
| { | |
| // Crack the selector | |
| var sel = GetSelector(seg); | |
| // Don't allow writes to read-only/code selectors | |
| if (sel.readOnly || sel.isCode) | |
| throw new Sharp86.GeneralProtectionFaultException(); | |
| try | |
| { | |
| // Write it | |
| sel.allocation.buffer[((seg >> 3) - sel.selectorIndex) << 16 | offset] = value; | |
| } | |
| catch (NullReferenceException) | |
| { | |
| throw new Sharp86.SegmentNotPresentException(); | |
| } | |
| catch (IndexOutOfRangeException) | |
| { | |
| throw new Sharp86.GeneralProtectionFaultException(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment