Example #1
0
        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);
            }
        }