Guest User

Untitled

a guest
Nov 24th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %ifndef __FILE_BL_PRINT__
  2. %define __FILE_BL_PRINT__
  3.  
  4. ;INT 0x10 is a BIOS video interrupt.
  5. ;Register al = ASCII value of character to display
  6. ;Register ah = 0x0E is Teletype mode (tell BIOS that we want to print one character on screen)
  7. ;Register bl = Text Attribute (foreground and background color of character to be displayed)
  8. ;Register bh = Page Number (0x00 for most cases)
  9.  
  10. ;0x0 => (  0,  0,  0) => black                ;0x0 => (  0,  0,  0) => black
  11. ;0x1 => (  0,  0,168) => dark blue            ;0x8 => ( 87, 87, 87) => dark grey
  12. ;0x2 => (  0,168,  0) => dark green           ;0x7 => (168,168,168) => light grey
  13. ;0x3 => (  0,168,168) => dark cyan            ;0xF => (255,255,255) => white
  14. ;0x4 => (168,  0,  0) => dark red
  15. ;0x5 => (168,  0,168) => dark magenta         ;0x4 => (168,  0,  0) => dark red
  16. ;0x6 => (168, 87,  0) => dark orange/brown    ;0xC => (255, 87, 87) => light red
  17. ;0x7 => (168,168,168) => light grey
  18. ;0x8 => ( 87, 87, 87) => dark grey            ;0x6 => (168, 87,  0) => dark orange/brown
  19. ;0x9 => ( 87, 87,255) => light blue
  20. ;0xA => ( 87,255, 87) => light green          ;0xE => (255,255, 87) => light yellow
  21. ;0xB => ( 87,255,255) => light cyan
  22. ;0xC => (255, 87, 87) => light red            ;0x2 => (  0,168,  0) => dark green
  23. ;0xD => (255, 87,255) => light magenta        ;0xA => ( 87,255, 87) => light green
  24. ;0xE => (255,255, 87) => light yellow
  25. ;0xF => (255,255,255) => white                ;0x1 => (  0,  0,168) => dark blue
  26.                                               ;0x9 => ( 87, 87,255) => light blue
  27.  
  28.                                               ;0x3 => (  0,168,168) => dark cyan
  29.                                               ;0xB => ( 87,255,255) => light cyan
  30.  
  31.                                               ;0x5 => (168,  0,168) => dark magenta
  32.                                               ;0xD => (255, 87,255) => light magenta
  33.  
  34. %define SET_COLOR_L(TEXT,BG) mov  ah, (BG<<4)|TEXT
  35. %macro PRINT 3
  36.     mov   esi, %1
  37.     SET_COLOR_L(%2,%3)
  38.     call  print_string
  39. %endmacro
  40. %macro CURSOR_SET_X 1
  41.     mov  byte [xpos], %1
  42. %endmacro
  43. %macro CURSOR_SET_Y 1
  44.     mov  byte [ypos], %1
  45. %endmacro
  46. %macro CURSOR_ADD_X 1
  47.     add  byte [xpos], %1
  48. %endmacro
  49. %macro CURSOR_ADD_Y 1
  50.     add  byte [ypos], %1
  51. %endmacro
  52. %macro CURSOR_SET 2
  53.     CURSOR_SET_X %1
  54.     CURSOR_SET_Y %2
  55. %endmacro
  56.  
  57. ;Prints a filled line of color AL on the row ypos
  58. ;   Modifies AX(AH,AL),BX(BH,BL), DI,SI
  59. ;print_fill_line:
  60. ;   mov  bl, al
  61. ;   shl  al, 4
  62. ;   or   al, bl
  63. ;   mov  ah, al
  64. ;   mov  al, 33      ; space character
  65.  
  66. ;   mov  bl, [xpos]  ; save xpos
  67.  
  68. ;   xor  bh, bh
  69. ;   .loop:
  70. ;       call print_character
  71.  
  72. ;       inc  bh
  73. ;       CURSOR_ADD_X 1
  74.  
  75. ;       cmp  bh, 80
  76. ;       jl   .loop
  77.  
  78. ;   CURSOR_SET_X bl  ; restore xpos
  79. ;   ret
  80. ;Prints the string in SI starting at (xpos,ypos)
  81. ;   Modifies AX(AL), DI,SI, xpos,ypos
  82. print_string:
  83.     .dochar:
  84.         lodsb  ; load string char from SI to AL, and inc SI
  85.  
  86.         cmp  al, 13
  87.         je   .carriage
  88.         cmp  al, 10
  89.         je   .newline
  90.         cmp  al, 0
  91.         je   .return
  92.  
  93.         call  print_character
  94.  
  95.         CURSOR_ADD_X 1
  96.  
  97.         jmp .dochar
  98.     .carriage:
  99.         CURSOR_SET_X 0
  100.         jmp  .dochar
  101.     .newline:
  102.         CURSOR_ADD_Y 1
  103.         jmp  .dochar
  104.     .return:
  105.         ret
  106. ;Prints the color/character in AH/AL at (xpos,ypos)
  107. ;   Modifies DI
  108. print_character:
  109.     push   ax
  110.     push   bx
  111.  
  112.     xor    di, di           ; stosw uses ES:DI to store, so DI=0 is the start of video memory
  113.  
  114.     movzx  ax, byte [xpos]
  115.     shl    ax, 1            ; times 2 because each position is a color/character of 16 bits
  116.     add    di, ax           ; add x offset
  117.  
  118.     movzx  ax, byte [ypos]
  119.     mov    bx, 160          ; 2 bytes (char/attrib)
  120.     mul    bx               ; for 80 columns
  121.     add    di, ax           ; add y offset
  122.  
  123.     pop   bx
  124.     pop   ax
  125.  
  126.     stosw                   ; write color/character in AX to ES:DI
  127.     ret
  128. ;Prints the contents of AX at (xpos,ypos) in hex
  129. ;   Modifies DI,SI
  130. ;print_reg_ax_hex:
  131. ;   push  ax
  132. ;   mov   bx, ax
  133.  
  134. ;   SET_COLOR_L(0x0,0xF)
  135.  
  136. ;   mov  dx, 0
  137.  
  138. ;   xor  cl, cl
  139. ;   .do_hexit:
  140. ;       mov    esi, str_hex
  141. ;       mov    dl, bh
  142. ;       shr    dl, 4
  143. ;       add    si, dx
  144. ;       lodsb                   ; load string char from SI to AL, and inc SI
  145. ;       call   print_character
  146. ;       shl    bx, 4
  147.  
  148. ;       inc  cl
  149. ;       CURSOR_ADD_X 1
  150.  
  151. ;       cmp  cl, 4
  152. ;       jl   .do_hexit
  153.  
  154. ;   pop  ax
  155. ;   ret
  156.  
  157. ;   str_hex  db "0123456789ABCDEF"
  158.  
  159. xpos  db 0
  160. ypos  db 0
  161.  
  162. %endif
Advertisement
Add Comment
Please, Sign In to add comment