DRAWCHAR.ASM 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. ;
  2. ; Command & Conquer Red Alert(tm)
  3. ; Copyright 2025 Electronic Arts Inc.
  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 3 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. ; $Header: U:\vq\projects\vqm32\drawchar.asv 1.1 08 May 1995 10:48:32 DENZIL_LONG $
  19. ;***************************************************************************
  20. ;** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  21. ;***************************************************************************
  22. ;* *
  23. ;* Project Name : Westwood Library *
  24. ;* *
  25. ;* File Name : DRAWCHAR.ASM *
  26. ;* *
  27. ;* Programmer : Joe L. Bostic *
  28. ;* *
  29. ;* Start Date : August 20, 1993 *
  30. ;* *
  31. ;* Last Update : August 20, 1993 [JLB] *
  32. ;* *
  33. ;*-------------------------------------------------------------------------*
  34. ;* Functions: *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. IDEAL
  37. P386
  38. MODEL USE32 FLAT
  39. LOCALS ??
  40. CODESEG
  41. XPIXEL_MAX EQU 320
  42. YPIXEL_MAX EQU 200
  43. FONTINFOBLOCK EQU 4
  44. FONTOFFSETBLOCK EQU 6
  45. FONTWIDTHBLOCK EQU 8
  46. FONTDATABLOCK EQU 10
  47. FONTHEIGHTBLOCK EQU 12
  48. FONTINFOMAXHEIGHT EQU 4
  49. FONTINFOMAXWIDTH EQU 5
  50. EXTRN FontPtr:NEAR PTR
  51. ;***********************************************************
  52. ; DRAW_CHAR
  53. ;
  54. ; VOID Draw_Char(BYTE fontchar, WORD x_pixel, WORD y_pixel);
  55. ;
  56. ; Draws a character to the screen only if given coordinates that will allow
  57. ; the entire character to be drawn on the screen else will exit.
  58. ;
  59. ; NOTE: This is a routine called by Text_Print.
  60. ;
  61. ;*
  62. GLOBAL C Draw_Char:NEAR
  63. PROC Draw_Char C NEAR USES eax ebx ecx edx esi edi
  64. ARG fontchar:DWORD
  65. ARG x_pixel:DWORD
  66. ARG y_pixel:DWORD
  67. LOCAL infoblock:DWORD
  68. LOCAL offsetblock:DWORD
  69. LOCAL widthblock:DWORD
  70. LOCAL heightblock:DWORD
  71. LOCAL fwidth:DWORD
  72. LOCAL nextline:DWORD
  73. LOCAL startv:BYTE
  74. LOCAL dheight:BYTE
  75. LOCAL wheight:BYTE
  76. mov esi,[FontPtr]
  77. ; Set up some working local variables.
  78. xor eax,eax
  79. mov ax,[esi+FONTINFOBLOCK] ; get offset to info block
  80. mov [infoblock],eax ; save offset to info block
  81. mov ax,[esi+FONTOFFSETBLOCK] ; get offset to offset block
  82. mov [offsetblock],eax ; save offset to offset block
  83. mov ax,[esi+FONTWIDTHBLOCK] ; get offset to width block
  84. mov [widthblock],eax ; save offset to width block
  85. mov ax,[esi+FONTHEIGHTBLOCK] ; get offset to height block
  86. mov [heightblock],eax ; save offset to height block
  87. ; Fetch character data offset -- if NULL then undefined character.
  88. mov ebx,[fontchar]
  89. and ebx,0FFh
  90. shl ebx,1 ; make word index
  91. add ebx,[offsetblock] ; add offset to offset block
  92. xor ecx,ecx
  93. mov cx,[esi+ebx] ; load offset to font data
  94. or ecx,ecx
  95. jz ??exit ; is this character a null? if so exit
  96. ; If the character is off the left/right edge of the screen then abort.
  97. mov edx,[x_pixel]
  98. cmp edx,XPIXEL_MAX
  99. jae ??exit
  100. ; If the character is off the top/bottom edge of the screen then abort.
  101. mov ebx,[fontchar] ; get char
  102. and ebx,0FFh
  103. add ebx,[widthblock] ; add offset to width block
  104. xor eax,eax
  105. mov al,[esi+ebx] ; get width for character
  106. mov [fwidth],eax ; save char width
  107. add eax,edx ; ax = char len + x
  108. cmp eax,XPIXEL_MAX
  109. ja ??exit
  110. mov edi,edx ; save xpos in di
  111. mov edx,[y_pixel]
  112. cmp edx,YPIXEL_MAX
  113. jae ??exit
  114. mov ebx,[infoblock] ; get offset to offset block
  115. xor eax,eax
  116. ; get font max height from info block
  117. mov al,[esi+ebx+FONTINFOMAXHEIGHT]
  118. mov [wheight],al ; save max height of character
  119. add eax,edx ; add height to y pos
  120. cmp eax,YPIXEL_MAX ; will it go off the bottom
  121. ja ??exit
  122. ??vdraw:
  123. mov ebx,[fontchar] ; get char
  124. and ebx,0FFh
  125. shl ebx,1 ; make 2 byte index
  126. add ebx,[heightblock] ; add offset to height block
  127. mov ah,[esi+ebx] ; get start vertical for character
  128. mov [startv],ah ; save start vertical for later
  129. mov al,[esi+ebx+1] ; get data height for character
  130. mov [dheight],al ; save data height for later
  131. add ah,al ; add background and data
  132. sub [wheight],ah ; remaining background height
  133. add esi,ecx ; add font offset to font data
  134. push edx
  135. mov eax,XPIXEL_MAX
  136. mul edx
  137. add edi,eax
  138. pop edx
  139. mov eax,XPIXEL_MAX
  140. sub eax,[fwidth]
  141. mov [nextline],eax ; ?? to add to index for the nextline
  142. add edi,0A0000h
  143. mov ebx,OFFSET ColorXlat ; setup up bx for xlat commands
  144. xor ecx,ecx
  145. mov cl,[startv] ; number of scan lines that are
  146. ; background color
  147. or ecx,ecx ; if starting vertical is zero
  148. je short ??skiplead ; skip drawing top background lines
  149. mov al,0
  150. xlat [ebx] ; get background color
  151. or al,al ; check for none zero color
  152. jne short ??lheight ; update background color
  153. push edx
  154. mov eax,XPIXEL_MAX
  155. mul ecx
  156. add edi,eax
  157. pop edx
  158. mov ebx,OFFSET ColorXlat ; restore bx for xlat commands
  159. jmp SHORT ??skiplead
  160. ??lheight:
  161. mov edx,[fwidth] ; width of char
  162. ??lwidth:
  163. stosb ; write out line of pixels for width
  164. dec edx
  165. jne ??lwidth
  166. ??lnext:
  167. add edi,[nextline] ; goto next line at the start of char
  168. loop ??lheight ; any more lines
  169. ??skiplead:
  170. mov cl,[dheight] ; number of scan lines that are data
  171. or ecx,ecx ; is there any data to be drawn
  172. je short ??exit
  173. ??vheight:
  174. mov edx,[fwidth] ; width of char
  175. ??vwidth:
  176. lodsb ; get byte value from font data
  177. mov ah,al ; save hinibble
  178. and al,00FH ; get lonibble
  179. xlat [ebx] ; get new color
  180. or al,al
  181. je short ??chklowidth ; skip color zero
  182. mov [edi],al ; write out pixel of lonibble
  183. ??chklowidth:
  184. inc edi
  185. dec edx
  186. je short ??vnext ; check if done with width of char
  187. mov al,ah ; get byte value
  188. and al,0F0H ; get hinibble
  189. xlat [ebx] ; get new color
  190. or al,al
  191. je short ??chkhiwidth ; skip color zero
  192. mov [edi],al ; write out pixel of hinibble
  193. ??chkhiwidth:
  194. inc edi
  195. dec edx
  196. jne ??vwidth ; check if done with width of char
  197. ??vnext:
  198. add edi,[nextline] ; next line at start of char
  199. loop ??vheight ; any more lines
  200. ??trail:
  201. mov cl,[wheight] ; remaining height of background color
  202. or ecx,ecx ; if trailing height is zero
  203. jle short ??exit ; skip drawing bottom background lines
  204. mov al,0
  205. xlat [ebx] ; get background color
  206. or al,al ; check for color zero
  207. je short ??exit ; skip drawing
  208. ??theight:
  209. mov edx,[fwidth] ; width of char
  210. ??twidth:
  211. stosb ; write out line of pixels for width
  212. dec edx
  213. jne ??twidth
  214. ??tnext:
  215. add edi,[nextline] ; next line at start of char
  216. loop ??theight ; any more lines
  217. ??exit:
  218. ret
  219. ENDP Draw_Char
  220. ;***********************************************************
  221. ;***********************************************************
  222. ; SET_FONT_PALETTE_RANGE
  223. ;
  224. ; VOID Set_Font_Palette_Range(VOID *palette, WORD start, WORD end);
  225. ;
  226. ; This routine changes the local Draw_Char color translation table
  227. ; with the color numbers in palette.
  228. ;
  229. ; Bounds Checking: forces start and end to a range of 0-15
  230. ;*
  231. GLOBAL C Set_Font_Palette_Range:NEAR
  232. PROC Set_Font_Palette_Range C NEAR USES eax ebx ecx edi esi
  233. ARG palette:NEAR PTR
  234. ARG start:DWORD
  235. ARG endval:DWORD
  236. cld
  237. mov esi,[palette]
  238. mov ebx,[start]
  239. and ebx,0FH ; value 0-15
  240. mov ecx,[endval]
  241. and ecx,0FH ; value 0-15
  242. cmp ecx,ebx ; if end < start then exit
  243. jl short ??exit
  244. sub ecx,ebx ; number of colors = end - start + 1
  245. inc ecx
  246. mov edi,OFFSET ColorXlat ; get start of xlat table
  247. add edi,ebx ; add starting offset
  248. shl ebx,4 ; multiply start offset by 16
  249. add ebx,OFFSET ColorXlat ; add start of xlat table
  250. ; updates 0-15 for lonibble xlat
  251. ; updates 0,16,32,...,240 for hinibble xlat
  252. ??setpal:
  253. lodsb ; get color number
  254. stosb ; save color number for lonibble xlat
  255. mov [ebx],al ; save color number for hinibble xlat
  256. add ebx,010H ; add 16 to index for hinibble offset
  257. loop ??setpal
  258. ??exit:
  259. ret
  260. ENDP Set_Font_Palette_Range
  261. ;***********************************************************
  262. ;***********************************************************
  263. ; DRAW_CHAR_SETUP
  264. ;
  265. ; VOID Draw_Char_Setup(VOID);
  266. ;
  267. ; This routine sets up code segment variables for Draw_Char.
  268. ;
  269. ; NOTE: This is a routine called by Set_Font.
  270. ;
  271. ;*
  272. GLOBAL C Draw_Char_Setup:NEAR
  273. PROC Draw_Char_Setup C NEAR
  274. ret
  275. ENDP Draw_Char_Setup
  276. DATASEG
  277. ColorXlat DB 000H,001H,002H,003H,004H,005H,006H,007H
  278. DB 008H,009H,00AH,00BH,00CH,00DH,00EH,00FH
  279. DB 001H,000H,000H,000H,000H,000H,000H,000H
  280. DB 000H,000H,000H,000H,000H,000H,000H,000H
  281. DB 002H,000H,000H,000H,000H,000H,000H,000H
  282. DB 000H,000H,000H,000H,000H,000H,000H,000H
  283. DB 003H,000H,000H,000H,000H,000H,000H,000H
  284. DB 000H,000H,000H,000H,000H,000H,000H,000H
  285. DB 004H,000H,000H,000H,000H,000H,000H,000H
  286. DB 000H,000H,000H,000H,000H,000H,000H,000H
  287. DB 005H,000H,000H,000H,000H,000H,000H,000H
  288. DB 000H,000H,000H,000H,000H,000H,000H,000H
  289. DB 006H,000H,000H,000H,000H,000H,000H,000H
  290. DB 000H,000H,000H,000H,000H,000H,000H,000H
  291. DB 007H,000H,000H,000H,000H,000H,000H,000H
  292. DB 000H,000H,000H,000H,000H,000H,000H,000H
  293. DB 008H,000H,000H,000H,000H,000H,000H,000H
  294. DB 000H,000H,000H,000H,000H,000H,000H,000H
  295. DB 009H,000H,000H,000H,000H,000H,000H,000H
  296. DB 000H,000H,000H,000H,000H,000H,000H,000H
  297. DB 00AH,000H,000H,000H,000H,000H,000H,000H
  298. DB 000H,000H,000H,000H,000H,000H,000H,000H
  299. DB 00BH,000H,000H,000H,000H,000H,000H,000H
  300. DB 000H,000H,000H,000H,000H,000H,000H,000H
  301. DB 00CH,000H,000H,000H,000H,000H,000H,000H
  302. DB 000H,000H,000H,000H,000H,000H,000H,000H
  303. DB 00DH,000H,000H,000H,000H,000H,000H,000H
  304. DB 000H,000H,000H,000H,000H,000H,000H,000H
  305. DB 00EH,000H,000H,000H,000H,000H,000H,000H
  306. DB 000H,000H,000H,000H,000H,000H,000H,000H
  307. DB 00FH
  308. ;***********************************************************
  309. END