PageRenderTime 33ms CodeModel.GetById 15ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/nbl/include/io16.inc

https://code.google.com/p/nepheliad-os/
Pascal | 103 lines | 99 code | 4 blank | 0 comment | 2 complexity | 31df2a65fdfda8ad4a168415f5d68064 MD5 | raw file
  1;=============================================================================;
  2;                       NEPHELIAD BOOT LOADER                                 ;
  3;=============================================================================;
  4; File: include/io16.inc                                                      ;
  5; Created: 10/19/2011                                                         ;
  6; Updated: 10/19/2011                                                         ;
  7; Author(s):                                                                  ;
  8;   * Sean M. Kell <sean.michael.kell@gmail.com>                              ;
  9;-----------------------------------------------------------------------------;
 10; Provides functions for input / output in 16-bit real mode.                  ;
 11;-----------------------------------------------------------------------------;
 12; Change Log:                                                                 ;
 13;   Version 0.01:                                                             ;
 14;     * 10/19/2011 - Initial creation.                                        ;
 15;       - Includes functions for writing a string, or character to the screen ;
 16;         using BIOS interrupt 0x10, function 0x0E.                           ;
 17;-----------------------------------------------------------------------------;
 18; Copyright (c) 2011 Sean M. Kell                                             ;
 19;                                                                             ;
 20; All rights reserved.                                                        ;
 21;=============================================================================;
 22CR      equ   0x0D
 23LF      equ   0x0A
 24
 25;=============================================================================;
 26; writechr()                                                                  ;
 27;-----------------------------------------------------------------------------;
 28; al - the character to write                                                 ;
 29;-----------------------------------------------------------------------------;
 30; Writes a character to the screen.                                           ;
 31;-----------------------------------------------------------------------------;
 32writechr:
 33        pushfd
 34        pushad
 35        xor     bx, bx
 36        mov     ah, 0x0E
 37        int     0x10
 38        popad
 39        popfd
 40        ret
 41
 42writenl:
 43        pushfd
 44        pushad
 45        mov     al, CR
 46        call    writechr
 47        mov     al, LF
 48        call    writechr
 49        popad
 50        popfd
 51        ret
 52        
 53;=============================================================================;
 54; writestr()                                                                  ;
 55;-----------------------------------------------------------------------------;
 56; si - points to the string to be written                                     ;
 57;-----------------------------------------------------------------------------;
 58; Writes a string to the screen.                                              ;
 59;=============================================================================;
 60writestr:
 61        pushfd
 62        pushad
 63.loop:  lodsb
 64        cmp   al, 0
 65        je    .done
 66        call  writechr
 67        jmp   .loop
 68.done:  popad
 69        popfd
 70        ret
 71        
 72writehex2:
 73        pushfd
 74        pushad
 75        rol     eax, 24
 76        mov     cx, 2
 77        jmp     short writehex_common
 78writehex4:
 79        pushfd
 80        pushad
 81        rol     eax, 16
 82        mov     cx, 4
 83        jmp     short writehex_common
 84writehex8:
 85        pushfd
 86        pushad
 87        mov     cx, 8
 88writehex_common:
 89.loop:  rol     eax, 4
 90        push    eax
 91        and     al, 0x0F
 92        cmp     al, 10
 93        jae     .high
 94.low:   add     al, '0'
 95        jmp     short .ischar
 96.high:  add     al, 'A'-10
 97.ischar:    
 98        call    writechr
 99        pop     eax
100        loop    .loop
101        popad
102        popfd
103        ret