Advertisement
Ham62

DrawString.asm

Mar 6th, 2016
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; DrawString routine for transparent ;
  3. ; background text on Screen 13h      ;
  4. ;                                    ;
  5. ; (C) Copyright Graham Downey 2016   ;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. ORG 0h
  9.  
  10. ;DB 0CCh    ;INT 3
  11.  
  12. PUSHA
  13. PUSH ES
  14. PUSH DS
  15.  
  16.             ;INT 10h function AX=1130h will return a pointer
  17. MOV AX, 1130h       ;to a font table
  18.             ;BH=3 is the 8x8 base characters table (0-127)
  19. MOV BH, 03h     ;BH=4 is the 8x8 extended characters table (128-255)
  20.  
  21. INT 10h         ;On return:
  22.             ;CX = bytes per character of on-screen font
  23.             ;DL = rows (less 1)
  24.             ;ES:BP = pointer to font table
  25.  
  26. MOV AX, ES      ;We want the font table to be ES:SI
  27. MOV ES, AX
  28. MOV SI, BP      ;Font table is now ES:SI
  29.  
  30.  
  31. MOV BP, SP      ;Point BP to stack
  32.  
  33.             ;Start pos in VRAM is [StartX + (StartY*320)]
  34. MOV DX, WORD [BP+16+18] ;Set start Y pos
  35. IMUL AX, DX, 320
  36. ADD AX, WORD [BP+14+18] ;Add start X pos
  37. MOV DI, AX      ;Set DI to position to begin drawing
  38. MOV AX, 0A000h      ;Set Screen segment
  39. MOV DS, AX      ;Screen is now DS:DI
  40.  
  41. MOV BX, WORD [BP+6+18]  ;Get String Color
  42. MOV CX, WORD [BP+8+18]  ;Get String Length
  43. MOV FS, WORD [BP+10+18] ;Get String Segment
  44. MOV BP, WORD [BP+12+18] ;Get String Address
  45.             ;String is now FS:BP
  46.  
  47. ReadChar:
  48. MOV AH, 00h
  49. MOV AL, BYTE [FS:BP]    ;Read a char from the string
  50. SHL AX, 3       ;Multiply character by 8 (8 bytes per char)
  51. MOV DX, SI      ;Save start position of font table
  52. ADD SI, AX      ;Move table pointer to character we just read
  53.  
  54. MOV BH, 8       ;8 lines per char
  55.  
  56. .NextLine:
  57. MOV AL, [ES:SI]     ;Read a row of pixels from the char
  58.  
  59. .Pixel1:
  60. TEST AL, 1      ;Is there a pixel at bit 1?
  61. JZ .Pixel2      ;No? Jump to pixel 2
  62. MOV [DI+7], BL      ;Draw pixel 1
  63.  
  64. .Pixel2:
  65. TEST AL, 2      ;Is there a pixel at bit 2?
  66. JZ .Pixel3      ;No? jump to pixel 3
  67.  
  68. MOV [DI+6], BL      ;Draw pixel 2
  69.  
  70. .Pixel3:
  71. TEST AL, 4      ;Is there a pixel at bit 3?
  72. JZ .Pixel4      ;No? Jump to pixel 4
  73. MOV [DI+5], BL      ;Draw pixel 3
  74.  
  75. .Pixel4:
  76. TEST AL, 8      ;Is there a pixel at bit 4?
  77. JZ .Pixel5      ;No? Jump to pixel 5
  78. MOV [DI+4], BL      ;Draw pixel 4
  79.  
  80. .Pixel5:
  81. TEST AL, 16     ;Is there a pixel at bit 5?
  82. JZ .Pixel6      ;No? Jump to pixel 6
  83. MOV [DI+3], BL      ;Draw pixel 5
  84.  
  85. .Pixel6:
  86. TEST AL, 32     ;Is there a pixel at bit 6?
  87. JZ .Pixel7      ;No? Jump to pixel 7
  88. MOV [DI+2], BL      ;Draw pixel 6
  89.  
  90. .Pixel7:
  91. TEST AL, 64     ;Is there a pixel at bit 7?
  92. JZ .Pixel8      ;No? Jump to pixel 8
  93. MOV [DI+1], BL      ;Draw pixel 7
  94.  
  95. .Pixel8:
  96. TEST AL, 128        ;Is there a pixel at bit 8?
  97. JZ .EndOfRow        ;No? Skip drawing pixel
  98. MOV [DI], BL        ;Draw pixel 8
  99.  
  100. .EndOfRow:
  101. INC SI          ;Next byte on font table
  102. ADD DI, 320     ;Go to next line on screen
  103.  
  104. DEC BH          ;Done all 8 lines of char?
  105. JNZ .NextLine       ;No? Start over on next line
  106. MOV SI, DX      ;Restore to start of table
  107. SUB DI, 2560-8      ;Done a char, return to top line and move
  108.             ;8 pixels forward for next character
  109.  
  110. INC BP          ;Next char in string pointer
  111. DEC CX          ;Are we done the string?
  112. JNZ ReadChar        ;No? Repeat until done
  113.  
  114.  
  115. End:
  116. POP DS
  117. POP ES
  118. POPA
  119. RETF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement