I_FONT.asm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ; Seven Kingdoms: Ancient Adversaries
  2. ;
  3. ; Copyright 1997,1998 Enlight Software Ltd.
  4. ;
  5. ; This program is free software: you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation, either version 2 of the License, or
  8. ; (at your option) any later version.
  9. ;
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ; GNU General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ;
  18. ;Filename : I_FONT.ASM
  19. ;Description : Image buffer font displaying function
  20. INCLUDE IMGFUN.inc
  21. .CODE
  22. ;-------- BEGIN OF FUNCTION IMGputBitFont ------
  23. ;
  24. ; Put font on IMG screen, bit to byte copying
  25. ;
  26. ; Syntax : IMGputBitFont( x,y,width,fontOffset,fontWidth,fontHeight,bitmapBuf,color)
  27. ;
  28. ; char *imageBuf - the pointer to the display surface buffer
  29. ; int pitch - the pitch of the display surface buffer
  30. ; int x,y - the start location of the font
  31. ; int bitmapWidth - bitmap buffer line width (in byte)
  32. ; int fontOffset - font offset from the bitmap buffer
  33. ; int fontWidth - font width
  34. ; int fontHeight - font height (in bit)
  35. ; char *bitmapBuf - bitmap buffer
  36. ;
  37. ; int foreColor - foreground color of the font
  38. ; [int] backColor - background color of the font
  39. ; (default : -1 (transparent background color)
  40. ;
  41. ; The bitmapBuf is origanized in a bitmap of all fonts packed together.
  42. ; To get the font of one character, you get the several from one line,
  43. ; and then next line, the distance between two line is represented by width
  44. ;
  45. ; AX - bitmap byte register
  46. ; BX - current bit position in the byte
  47. ; CX - counter
  48. ; DX - temporary register for color
  49. ;
  50. ; DS:SI - Source address
  51. ; ES:DI - Destination address
  52. ;
  53. ; widthDiff - width difference (640 - width)
  54. ;
  55. PUBLIC IMGputBitFont
  56. IMGputBitFont PROC imageBuf, pitch, x, y, bitmapWidth, fontOffset, fontWidth, fontHeight, bitmapPtr, foreColor, backColor
  57. LOCAL widthDiff, lastSI, bitMask
  58. STARTPROC
  59. MOV EAX, imageBuf ; store the address of the image buffer to a variable
  60. MOV image_buf, EAX
  61. ;---- Initialize destination variables ----
  62. MOV AX, DS
  63. MOV ES, AX
  64. MOV EAX, pitch
  65. SUB EAX, fontWidth
  66. MOV widthDiff, EAX
  67. CLD ; clear direction flag for MOVSB
  68. ;------- initialize source variables --------
  69. MOV ESI, bitmapPtr
  70. MOV EAX, fontOffset
  71. SHR EAX, 3 ; Divide by 16, bit --> byte
  72. ADD ESI, EAX
  73. MOV lastSI, ESI
  74. MOV ECX, fontOffset
  75. AND ECX, 07h ; the bit of the current byte
  76. MOV EBX, 8000h
  77. SHR EBX, CL
  78. MOV bitMask, EBX
  79. LODSW ; Load DS:SI --> AX
  80. XCHG AL, AH ; Restore the lo-hi to hi-lo
  81. ;------- Draw one line for this loop ------
  82. @@putLine:
  83. CALC_ADDR EDI, x, y, pitch ; Get the offset to the video address
  84. MOV ECX, fontWidth ; Get the offset to the video address
  85. @@putPixel: TEST AX, BX ; test one bit only
  86. JZ @@putBack ; if 1->paint, 0->ingore
  87. @@putFore: MOV EDX, foreColor ; foreColor->dest. byte
  88. MOV ES:[EDI], DL
  89. JMP @@nextPixel
  90. @@putBack: MOV EDX, backColor
  91. CMP EDX, 0FFFFFFFFH
  92. JE @@nextPixel
  93. MOV ES:[EDI], DL
  94. ;-------- Next Pixel ---------------------
  95. @@nextPixel: SHR EBX, 1
  96. JNZ @@nextDest ; Next destination byte
  97. LODSW
  98. XCHG AL, AH ; Restore the lo-hi to hi-lo
  99. MOV EBX, 8000h ; New byte
  100. ;-------- Next destination pixel -----------
  101. @@nextDest: INC EDI
  102. LOOP @@putPixel
  103. @@nextLine: INC y ; decrease height of the bar
  104. DEC fontHeight
  105. JZ @@end
  106. ;------ check if y is in another bank -----
  107. MOV ESI, lastSI
  108. ADD ESI, bitmapWidth ; next line
  109. MOV lastSI, ESI
  110. MOV EBX, bitMask
  111. LODSW
  112. XCHG AL, AH ; Restore the lo-hi to hi-lo
  113. ADD EDI, widthDiff
  114. JMP @@putLine ; if no. exceed next bank, then loop
  115. @@end: ENDPROC
  116. IMGputBitFont ENDP
  117. ;----------- END OF FUNCTION IMGputBitFont ----------
  118. END