biosfunc.S 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* biosfunc.S -- real-mode BIOS and convenience functions. */
  2. .file "biosfunc.S"
  3. .code16
  4. /*
  5. * The following convenience functions are only available
  6. * in real mode through BIOS:
  7. *
  8. * void clrscr() # clear display
  9. * void curshome() # move cursor home (0:0)
  10. * void puts(%si) # display string
  11. * void putc(%al) # display char
  12. *
  13. * use this libary like this:
  14. * .include biosfunc.S
  15. */
  16. /* clrscr() -- clear dislay */
  17. clrscr:
  18. /*
  19. * clrscr() clears the video buffer, using a special case in
  20. * the BIOS function "SCROLL UP WINDOW". Note that this
  21. * function is only available in real mode, and that some
  22. * buggy BIOSes destroy the base pointer %bp, so we better
  23. * temporarily save it on the stack.
  24. */
  25. pushw %bp # BIOS call below *can* destroy %BP
  26. movb $0x06, %ah # BIOS function "SCROLL UP WINDOW"
  27. movb $0x0, %al # nr. of lines to scroll (00=clear window)
  28. movb $0x7, %bh # attr. to fill new lines at bottom
  29. movw $0x0, %cx # CH,CL: row,column upper left corner (00:00)
  30. movw $0x184f, %dx # DH,DL: row,column lower right corner (24:79)
  31. int $0x10 # call BIOS
  32. popw %bp
  33. retw
  34. /* curshome() -- set cursor position to 0:0 */
  35. curshome:
  36. /*
  37. * curshome() moves the cursor to position 0:0 (top:left),
  38. * using the BIOS function "SET CURSOR POSITION". This
  39. * function is only available in real mode.
  40. */
  41. movb $0x02, %ah # BIOS function "SET CURSOR POSITION"
  42. movb $0x0, %bh # page number 0
  43. movw $0x0, %dx # DH=0 row, DL=0 col
  44. int $0x10 # call BIOS
  45. retw
  46. /* puts(%si) -- display 0-terminated string via putc() */
  47. puts:
  48. /*
  49. * puts() repeatedly loads a byte from the buffer pointed
  50. * to by %si into %al, and displays that byte by calling
  51. * putc(%al), until a \0-byte is encountered. The buffer
  52. * should thus be \0-terminated, like a regular C-string.
  53. */
  54. lodsb # Load next byte from %si buffer into %al
  55. cmpb $0x0, %al # %al == 0?
  56. je puts1 # Yes: end of string!
  57. callw putc # No: Display current char
  58. jmp puts # Proceed next char
  59. puts1: retw
  60. /* putc(%al) -- output char %al via BIOS call int 10h, func 0Eh */
  61. putc:
  62. /*
  63. * putc(%al) displays the byte %al on the default video
  64. * buffer, using the BIOS function "TELETYPE OUTPUT".
  65. * This function interprets some but not all control
  66. * characters correctly, but it doesn't matter all too
  67. * much in this simple example. This BIOS function is
  68. * only available in real mode.
  69. */
  70. movw $0x7, %bx # BH: page 0, BL: attribute 7 (normal white)
  71. movb $0xe, %ah # BIOS function "TELETYPE OUTPUT"
  72. int $0x10 # call BIOS
  73. retw