public static Process CreateProcess(ThreadStartMethod MainMethod, FOS_System.String Name, bool UserMode, bool CreateHeap) { #if PROCESSMANAGER_TRACE BasicConsole.WriteLine("Creating process object..."); #endif return new Process(MainMethod, ProcessIdGenerator++, Name, UserMode, CreateHeap); }
/// <summary> /// Attempts to find the specified directory within any file system. /// </summary> /// <param name="directoryName">The full path and name of the directory to find.</param> /// <returns>The directory or null if it isn't found.</returns> public static Directory Find(FOS_System.String directoryName) { FileSystemMapping theMapping = FileSystemManager.GetMapping(directoryName); if (theMapping == null) { return null; } directoryName = theMapping.RemoveMappingPrefix(directoryName); directoryName = directoryName.ToUpper(); Base baseListing = theMapping.TheFileSystem.GetListing(directoryName); if (baseListing == null) { return null; } else { if (baseListing is Directory) { return (Directory)baseListing; } else { return null; } } }
/// <summary> /// Opens the specified file. /// </summary> /// <param name="fileName">The full path to the file to open.</param> /// <returns>The file listing or null if not found.</returns> public static File Open(FOS_System.String fileName) { FileSystemMapping theMapping = FileSystemManager.GetMapping(fileName); if(theMapping == null) { return null; } fileName = theMapping.RemoveMappingPrefix(fileName); fileName = fileName.ToUpper(); Base baseListing = theMapping.TheFileSystem.GetListing(fileName); if (baseListing == null) { return null; } else { if (baseListing is File) { return (File)baseListing; } else { return null; } } }
/// <summary> /// Initializes a new base listing. /// </summary> /// <param name="aFileSystem">The file system to which the listing belongs.</param> /// <param name="parent">The parent directory of the listing.</param> /// <param name="aName">The name of the listing.</param> /// <param name="isDirectory">Whether the listing is a directory or not.</param> protected Base(FileSystem aFileSystem, Directory parent, FOS_System.String aName, bool isDirectory) { TheFileSystem = aFileSystem; Name = aName; IsDirectory = isDirectory; Parent = parent; }
public static void AddDeviceAddedListener(DeviceAddedHandler aHandler, FOS_System.Object aState) { DeviceAddedListeners.Add(new DeviceAddedListener() { handler = aHandler, state = aState }); }
public static byte[] GetASCIIBytes(FOS_System.String asciiString) { byte[] result = new byte[asciiString.length]; for(int i = 0; i < asciiString.length; i++) { result[i] = (byte)asciiString[i]; } return result; }
/// <summary> /// Parses a string as an signed decimal integer. /// </summary> /// <param name="str">The string to parse.</param> /// <returns>The parsed int.</returns> public static int Parse_DecimalSigned(FOS_System.String str) { bool neg = str.StartsWith("-"); int result = (int)Parse_DecimalUnsigned(str, (neg ? 1 : 0)); if (neg) { result *= -1; } return result; }
public static unsafe FOS_System.String Concat(FOS_System.String str1, FOS_System.String str2) { FOS_System.String newStr = New(str1.length + str2.length); for (int i = 0; i < str1.length; i++) { newStr[i] = str1[i]; } for (int i = 0; i < str2.length; i++) { newStr[i + str1.length] = str2[i]; } return newStr; }
public Process(ThreadStartMethod MainMethod, uint AnId, FOS_System.String AName, bool userMode) { #if PROCESS_TRACE BasicConsole.WriteLine("Constructing process object..."); #endif Id = AnId; Name = AName; UserMode = userMode; #if PROCESS_TRACE BasicConsole.WriteLine("Creating thread..."); #endif CreateThread(MainMethod); }
/// <summary> /// Parses a string as an unsigned decimal integer. /// </summary> /// <param name="str">The string to parse.</param> /// <param name="offset">The offset into the string at which to start parsing.</param> /// <returns>The parsed uint.</returns> public static uint Parse_DecimalUnsigned(FOS_System.String str, int offset) { uint result = 0; for(int i = offset; i < str.length; i++) { char c = str[i]; if (c < '0' || c > '9') { break; } result *= 10; result += (uint)(c - '0'); } return result; }
protected void OutputExceptionInfo(FOS_System.Exception Ex) { if (Ex != null) { console.WarningColour(); console.WriteLine(Ex.Message); if (Ex is FOS_System.Exceptions.PageFaultException) { console.WriteLine(((FOS_System.String)" - Address: ") + ((FOS_System.Exceptions.PageFaultException)Ex).address); console.WriteLine(((FOS_System.String)" - Error code: ") + ((FOS_System.Exceptions.PageFaultException)Ex).errorCode); } console.DefaultColour(); } else { console.WriteLine("No current exception."); } }
public bool Push(FOS_System.Object obj) { AccessLock.Enter(); try { if (WriteIdx == ReadIdx && ReadIdx != -1) { if (ThrowExceptions) { ExceptionMethods.Throw(new Exceptions.OverflowException("Circular buffer cannot Push because the buffer is full.")); } return false; } WriteIdx++; if (WriteIdx == _array.Length) { if (ReadIdx == -1) { WriteIdx--; if (ThrowExceptions) { ExceptionMethods.Throw(new Exceptions.OverflowException("Circular buffer cannot Push because the buffer is full.")); } return false; } WriteIdx = 0; } _array[WriteIdx] = obj; return true; } finally { AccessLock.Exit(); } }
public void Push(FOS_System.Object val) { if ((BackIdx != 0 && FrontIdx == BackIdx - 1) || (BackIdx == 0 && FrontIdx == InternalArray.Length - 1)) { // Queue full if (CanExpand) { Expand(InternalArray.Length); } else { return; } } InternalArray[FrontIdx++] = val; if (FrontIdx >= InternalArray.Length) { FrontIdx = 0; } }
private static void BasicConsole_SecondaryOutput(FOS_System.String str) { Hardware.IO.Serial.Serial.COM1.Write(str); }
public void Add(FOS_System.Object obj) { //If the next index to insert an item at is beyond the capacity of // the array, we need to expand the array. if (nextIndex >= _array.Length) { ExpandCapacity(ExpandAmount); } //Insert the object at the next index in the internal array then increment // next index _array[nextIndex] = obj; nextIndex++; }
private static void IRQHandler(FOS_System.Object state) { ((PATAPI)state).IRQHandler(); }
/// <summary> /// Sets the message to "Overflow exception." /// </summary> public OverflowException(FOS_System.String message) : base("Overflow exception. " + message) { }
public static Process CreateProcess(ThreadStartMethod MainMethod, FOS_System.String Name, bool UserMode) { return CreateProcess(MainMethod, Name, UserMode, false); }
/// <summary> /// Determines whether the specified path starts with this /// mapping's prefix. /// </summary> /// <param name="aPath">The path to check.</param> /// <returns> /// Whether the specified path starts with this /// mapping's prefix. /// </returns> public bool PathMatchesMapping(FOS_System.String aPath) { return aPath.ToUpper().StartsWith(prefix); }
/// <summary> /// The internal wait interrupt handler static wrapper. /// </summary> /// <param name="state">The PIT object state.</param> private static void SignalWait(FOS_System.Object state) { ((PIT)state).SignalWait(); }
public static unsafe void Write(FOS_System.String str) { if (!Initialised) return; //If string is null, just don't write anything if (str == null) { //Do not make this throw an exception. The BasicConsole // is largely a debugging tool - it should be reliable, // robust and not throw exceptions. return; } if (PrimaryOutputEnabled) { int strLength = str.length; int maxOffset = rows * cols; //This block shifts the video memory up the required number of lines. if (offset + strLength > maxOffset) { int amountToShift = (offset + strLength) - maxOffset; amountToShift = amountToShift + (80 - (amountToShift % 80)); offset -= amountToShift; char* vidMemPtr_Old = vidMemBasePtr; char* vidMemPtr_New = vidMemBasePtr + amountToShift; char* maxVidMemPtr = vidMemBasePtr + (cols * rows); while (vidMemPtr_New < maxVidMemPtr) { vidMemPtr_Old[0] = vidMemPtr_New[0]; vidMemPtr_Old++; vidMemPtr_New++; } } //This block outputs the string in the current foreground / background colours. char* vidMemPtr = vidMemBasePtr + offset; char* strPtr = str.GetCharPointer(); while (strLength > 0) { vidMemPtr[0] = (char)((*strPtr & 0x00FF) | colour); strLength--; vidMemPtr++; strPtr++; offset++; } } if (SecondaryOutput != null && SecondaryOutputEnabled) { SecondaryOutput(str); } }
/// <summary> /// The internal timer 0 interrupt handler static wrapper. /// </summary> /// <param name="state">The PIT object state.</param> protected static void InterruptHandler(FOS_System.Object state) { ((PIT)state).InterruptHandler(); }
/// <summary> /// Creates a new exception with specified message. /// </summary> /// <param name="aMessage">The exception message.</param> public Exception(FOS_System.String aMessage) : base() { Message = aMessage; }
public void Remove(FOS_System.Object obj) { //Determines whether we should be setting the array entries // to null or not. After we have removed an item and shifted // existing items up in the array, all remaining unused entries // must be set to null. bool setObjectToNull = false; //Store the current index. There is no point looping through the whole capacity // of the array, but we must at least loop through everything that has been set // including the last entry even after higher entries have been shifted or removed. //Note: It would be invalid to use nextIndex+1 because that assumes an entry will // be removed but if the object to remove is not in the list, it will not be // found and so nextIndex+1 would over-run the capacity of the list. int origNextIndex = nextIndex; //Loop through all items in the array that have had a value set. for (int i = 0; i < origNextIndex; i++) { //There are two scenarios here: // 1) We are searching from the start of the list until we find // the item to be removed. Until we find the item, we don't need // to make any changes to the internal array. // 2) Or, we have found the item to be removed and are in the process // of shifting entries up 1 in the array to remove the item. if (_array[i] == obj || setObjectToNull) { //If we are not setting objects to null, then "_array[i] == obj" must // have been true i.e. the current search index is the index of the // object to be removed. //Note: This if block is just a more efficient way of writing: // if (_array[i] == obj) if (!setObjectToNull) { //Removing the object reduces the total count of objects by 1 nextIndex--; } //We should now start shifting objects and setting entries to null setObjectToNull = true; //If we are still within the (new) count of objects then simply shift the // next object up one in the list if (i < nextIndex) { //Set current index to next value in the list. _array[i] = _array[i + 1]; } else { //Otherwise, just set the entry to null. // This ensures values aren't randomly left with entries // in the top of the list. _array[i] = null; } } } }
public override int RegisterHandler(Devices.TimerHandler handler, long TimeoutNS, bool Recurring, FOS_System.Object state) { return RegisterHandler(new PITHandler(handler, state, TimeoutNS, Recurring)); }
public int IndexOf(FOS_System.Object obj) { //This is a straight forward search. Other search algorithms // may be faster but quite frankly who cares. Optimising the compiler // ASM output would have a far greater effect than changing this // nice, simple algorithm. for (int i = 0; i < nextIndex; i++) { if(_array[i] == obj) { return i; } } //As per C# (perhaps C?) standard (convention?) return -1; }
/// <summary> /// Initialises a recurring new PIT handler. /// </summary> /// <param name="HandleOnTrigger">The method to call when the timeout expires.</param> /// <param name="aState">The state object to pass to the handler.</param> /// <param name="NanosecondsTimeout">The timeout, in nanoseconds.</param> /// <param name="NanosecondsLeft">The intial timeout value, in nanoseconds.</param> public PITHandler(Devices.TimerHandler HandleOnTrigger, FOS_System.Object aState, long NanosecondsTimeout, uint NanosecondsLeft) { this.HandleTrigger = HandleOnTrigger; this.NanosecondsTimeout = NanosecondsTimeout; this.NSRemaining = NanosecondsLeft; this.Recurring = true; this.state = aState; }
/// <summary> /// Removes the mapping's prefix from the specified path. /// </summary> /// <param name="aPath">The path to remove the prefix from.</param> /// <returns>The path without the prefix.</returns> public FOS_System.String RemoveMappingPrefix(FOS_System.String aPath) { return aPath.Substring(prefix.length, aPath.length - prefix.length); }
public static unsafe void WriteLine(FOS_System.String str) { if (!Initialised) return; if (str == null) { return; } if (PrimaryOutputEnabled) { //This block shifts the video memory up the required number of lines. if (offset == cols * rows) { char* vidMemPtr_Old = vidMemBasePtr; char* vidMemPtr_New = vidMemBasePtr + cols; char* maxVidMemPtr = vidMemBasePtr + (cols * rows); while (vidMemPtr_New < maxVidMemPtr) { vidMemPtr_Old[0] = vidMemPtr_New[0]; vidMemPtr_Old++; vidMemPtr_New++; } offset -= cols; } } //This outputs the string Write(str); if (PrimaryOutputEnabled) { //This block "writes" the new line by filling in the remainder (if any) of the // line with blank characters and correct background colour. int diff = offset; while (diff > cols) { diff -= cols; } diff = cols - diff; char* vidMemPtr = vidMemBasePtr + offset; while (diff > 0) { vidMemPtr[0] = bg_colour; diff--; vidMemPtr++; offset++; } } if (SecondaryOutput != null && SecondaryOutputEnabled) { SecondaryOutput("\r\n"); } }
/// <summary> /// Initializes a new file system mapping. /// </summary> /// <param name="aPrefix">The prefix to map.</param> /// <param name="aFileSystem">The file system to map.</param> public FileSystemMapping(FOS_System.String aPrefix, FileSystem aFileSystem) { prefix = aPrefix; theFileSystem = aFileSystem; }