/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. ;=============================================================================;
  22. CR equ 0x0D
  23. LF equ 0x0A
  24. ;=============================================================================;
  25. ; writechr() ;
  26. ;-----------------------------------------------------------------------------;
  27. ; al - the character to write ;
  28. ;-----------------------------------------------------------------------------;
  29. ; Writes a character to the screen. ;
  30. ;-----------------------------------------------------------------------------;
  31. writechr:
  32. pushfd
  33. pushad
  34. xor bx, bx
  35. mov ah, 0x0E
  36. int 0x10
  37. popad
  38. popfd
  39. ret
  40. writenl:
  41. pushfd
  42. pushad
  43. mov al, CR
  44. call writechr
  45. mov al, LF
  46. call writechr
  47. popad
  48. popfd
  49. ret
  50. ;=============================================================================;
  51. ; writestr() ;
  52. ;-----------------------------------------------------------------------------;
  53. ; si - points to the string to be written ;
  54. ;-----------------------------------------------------------------------------;
  55. ; Writes a string to the screen. ;
  56. ;=============================================================================;
  57. writestr:
  58. pushfd
  59. pushad
  60. .loop: lodsb
  61. cmp al, 0
  62. je .done
  63. call writechr
  64. jmp .loop
  65. .done: popad
  66. popfd
  67. ret
  68. writehex2:
  69. pushfd
  70. pushad
  71. rol eax, 24
  72. mov cx, 2
  73. jmp short writehex_common
  74. writehex4:
  75. pushfd
  76. pushad
  77. rol eax, 16
  78. mov cx, 4
  79. jmp short writehex_common
  80. writehex8:
  81. pushfd
  82. pushad
  83. mov cx, 8
  84. writehex_common:
  85. .loop: rol eax, 4
  86. push eax
  87. and al, 0x0F
  88. cmp al, 10
  89. jae .high
  90. .low: add al, '0'
  91. jmp short .ischar
  92. .high: add al, 'A'-10
  93. .ischar:
  94. call writechr
  95. pop eax
  96. loop .loop
  97. popad
  98. popfd
  99. ret