Annotation of truecrypt/boot/windows/bootconsoleio.cpp, revision 1.1

1.1     ! root        1: /*
        !             2:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
        !             3: 
        !             4:  Governed by the TrueCrypt License 2.4 the full text of which is contained
        !             5:  in the file License.txt included in TrueCrypt binary and source code
        !             6:  distribution packages.
        !             7: */
        !             8: 
        !             9: #include "Platform.h"
        !            10: #include "Bios.h"
        !            11: #include "BootConsoleIo.h"
        !            12: #include "BootDebug.h"
        !            13: 
        !            14: 
        !            15: static int ScreenOutputDisabled = 0;
        !            16: 
        !            17: void DisableScreenOutput ()
        !            18: {
        !            19:        ++ScreenOutputDisabled;
        !            20: }
        !            21: 
        !            22: 
        !            23: void EnableScreenOutput ()
        !            24: {
        !            25:        --ScreenOutputDisabled;
        !            26: }
        !            27: 
        !            28: 
        !            29: void PrintChar (char c)
        !            30: {
        !            31: #ifdef TC_TRACING_ENABLED
        !            32:        WriteDebugPort (c);
        !            33: #endif
        !            34: 
        !            35:        if (ScreenOutputDisabled)
        !            36:                return;
        !            37: 
        !            38:        __asm
        !            39:        {
        !            40:                xor bx, bx
        !            41:                mov al, c
        !            42:                mov ah, 0xe
        !            43:                int 0x10
        !            44:        }
        !            45: }
        !            46: 
        !            47: 
        !            48: void PrintCharAtCusor (char c)
        !            49: {
        !            50:        __asm
        !            51:        {
        !            52:                xor bx, bx
        !            53:                mov al, c
        !            54:                mov cx, 1
        !            55:                mov ah, 0xa
        !            56:                int 0x10
        !            57:        }
        !            58: }
        !            59: 
        !            60: 
        !            61: void Print (const char *str)
        !            62: {
        !            63:        char c;
        !            64:        while (c = *str++)
        !            65:                PrintChar (c);
        !            66: }
        !            67: 
        !            68: 
        !            69: void Print (uint32 number)
        !            70: {
        !            71:        char str[12];
        !            72:        int pos = 0;
        !            73:        while (number >= 10)
        !            74:        {
        !            75:                str[pos++] = (number % 10) + '0';
        !            76:                number /= 10;
        !            77:        }
        !            78:        str[pos] = (number % 10) + '0';
        !            79:        
        !            80:        while (pos >= 0)
        !            81:                PrintChar (str[pos--]);
        !            82: }
        !            83: 
        !            84: 
        !            85: void Print (const uint64 &number)
        !            86: {
        !            87:        if (number.HighPart == 0)
        !            88:                Print (number.LowPart);
        !            89:        else
        !            90:                PrintHex (number);
        !            91: }
        !            92: 
        !            93: 
        !            94: void PrintHex (byte b)
        !            95: {
        !            96:        PrintChar (((b >> 4) >= 0xA ? 'A' - 0xA : '0') + (b >> 4));
        !            97:        PrintChar (((b & 0xF) >= 0xA ? 'A' - 0xA : '0') + (b & 0xF));
        !            98: }
        !            99: 
        !           100: 
        !           101: void PrintHex (uint16 data)
        !           102: {
        !           103:        PrintHex (byte (data >> 8));
        !           104:        PrintHex (byte (data));
        !           105: }
        !           106: 
        !           107: 
        !           108: void PrintHex (uint32 data)
        !           109: {
        !           110:        PrintHex (uint16 (data >> 16));
        !           111:        PrintHex (uint16 (data));
        !           112: }
        !           113: 
        !           114: 
        !           115: void PrintHex (const uint64 &data)
        !           116: {
        !           117:        PrintHex (data.HighPart);
        !           118:        PrintHex (data.LowPart);
        !           119: }
        !           120: 
        !           121: void PrintRepeatedChar (char c, int n)
        !           122: {
        !           123:        while (n-- > 0)
        !           124:                PrintChar (c);
        !           125: }
        !           126: 
        !           127: 
        !           128: void PrintEndl ()
        !           129: {
        !           130:        Print ("\r\n");
        !           131: }
        !           132: 
        !           133: 
        !           134: void PrintEndl (int cnt)
        !           135: {
        !           136:        while (cnt-- > 0)
        !           137:                PrintEndl ();
        !           138: }
        !           139: 
        !           140: 
        !           141: void Beep ()
        !           142: {
        !           143:        PrintChar (7);
        !           144: }
        !           145: 
        !           146: 
        !           147: void ClearScreen ()
        !           148: {
        !           149:        __asm
        !           150:        {
        !           151:                mov bh, 7
        !           152:                xor cx, cx
        !           153:                mov dx, 0x184f
        !           154:                mov ax, 0x600
        !           155:                int 0x10
        !           156: 
        !           157:                xor bh, bh
        !           158:                xor dx, dx
        !           159:                mov ah, 2
        !           160:                int 0x10
        !           161:        }
        !           162: }
        !           163: 
        !           164: 
        !           165: void PrintBackspace ()
        !           166: {
        !           167:        PrintChar (TC_BIOS_CHAR_BACKSPACE);
        !           168:        PrintCharAtCusor (' ');
        !           169: }
        !           170: 
        !           171: 
        !           172: void PrintError (const char *message, bool beep, bool newLine)
        !           173: {
        !           174:        Print ("Error: ");
        !           175:        Print (message);
        !           176:        
        !           177:        if (newLine)
        !           178:                PrintEndl();
        !           179: 
        !           180:        if (beep)
        !           181:                Beep();
        !           182: }
        !           183: 
        !           184: 
        !           185: byte GetShiftFlags ()
        !           186: {
        !           187:        byte flags;
        !           188:        __asm
        !           189:        {
        !           190:                mov ah, 2
        !           191:                int 0x16
        !           192:                mov flags, al
        !           193:        }
        !           194: 
        !           195:        return flags;
        !           196: }
        !           197: 
        !           198: 
        !           199: byte GetKeyboardChar (byte *scanCode)
        !           200: {
        !           201:        byte asciiCode;
        !           202:        byte scan;
        !           203:        __asm
        !           204:        {
        !           205:                mov ah, 0
        !           206:                int 0x16
        !           207:                mov asciiCode, al
        !           208:                mov scan, ah
        !           209:        }
        !           210:        
        !           211:        if (scanCode)
        !           212:                *scanCode = scan;
        !           213: 
        !           214:        return asciiCode;
        !           215: }
        !           216: 
        !           217: 
        !           218: bool IsKeyboardCharAvailable ()
        !           219: {
        !           220:        bool available = false;
        !           221:        __asm
        !           222:        {
        !           223:                mov ah, 1
        !           224:                int 0x16
        !           225:                jz not_avail
        !           226:                mov available, true
        !           227:        not_avail:
        !           228:        }
        !           229: 
        !           230:        return available;
        !           231: }
        !           232: 
        !           233: 
        !           234: bool IsPrintable (char c)
        !           235: {
        !           236:        return c >= ' ' && c <= '~';
        !           237: }
        !           238: 
        !           239: 
        !           240: int GetString (char *buffer, size_t bufferSize)
        !           241: {
        !           242:        byte c;
        !           243:        byte scanCode;
        !           244:        size_t pos = 0;
        !           245: 
        !           246:        while (pos < bufferSize)
        !           247:        {
        !           248:                c = GetKeyboardChar (&scanCode);
        !           249: 
        !           250:                if (scanCode == TC_BIOS_KEY_ENTER)
        !           251:                        break;
        !           252:                
        !           253:                if (scanCode == TC_BIOS_KEY_ESC)
        !           254:                        return 0;
        !           255: 
        !           256:                buffer[pos++] = c;
        !           257:                PrintChar (IsPrintable (c) ? c : ' ');
        !           258:        }
        !           259: 
        !           260:        return pos;
        !           261: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.