TEXTPRNT.ASM 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. ;***************************************************************************
  19. ;** 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 **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : 32 bit library Text Print *
  23. ;* *
  24. ;* File Name : TEXTPRNT.ASM *
  25. ;* *
  26. ;* Programmer : Scott K. Bowen *
  27. ;* *
  28. ;* Start Date : July 2, 1994 *
  29. ;* *
  30. ;* Last Update : July 2, 1994 [SKB] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* Text_Print -- Assembly text print routine. *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. IDEAL
  37. P386
  38. MODEL USE32 FLAT
  39. GLOBAL FontPtr:DWORD
  40. GLOBAL Text_Print:NEAR
  41. ; The header of the font file looks like this:
  42. ; UWORD FontLength; 0
  43. ; BYTE FontCompress; 2
  44. ; BYTE FontDataBlocks; 3
  45. ; UWORD InfoBlockOffset; 4
  46. ; UWORD OffsetBlockOffset; 6
  47. ; UWORD WidthBlockOffset; 8
  48. ; UWORD DataBlockOffset; 10
  49. ; UWORD HeightOffset; 12
  50. ; For this reason the following equates have these values:
  51. FONTINFOBLOCK EQU 4
  52. FONTOFFSETBLOCK EQU 6
  53. FONTWIDTHBLOCK EQU 8
  54. FONTDATABLOCK EQU 10
  55. FONTHEIGHTBLOCK EQU 12
  56. FONTINFOMAXHEIGHT EQU 4
  57. FONTINFOMAXWIDTH EQU 5
  58. LOCALS ??
  59. DATASEG
  60. ColorXlat DB 000H,001H,002H,003H,004H,005H,006H,007H
  61. DB 008H,009H,00AH,00BH,00CH,00DH,00EH,00FH
  62. DB 001H,000H,000H,000H,000H,000H,000H,000H
  63. DB 000H,000H,000H,000H,000H,000H,000H,000H
  64. DB 002H,000H,000H,000H,000H,000H,000H,000H
  65. DB 000H,000H,000H,000H,000H,000H,000H,000H
  66. DB 003H,000H,000H,000H,000H,000H,000H,000H
  67. DB 000H,000H,000H,000H,000H,000H,000H,000H
  68. DB 004H,000H,000H,000H,000H,000H,000H,000H
  69. DB 000H,000H,000H,000H,000H,000H,000H,000H
  70. DB 005H,000H,000H,000H,000H,000H,000H,000H
  71. DB 000H,000H,000H,000H,000H,000H,000H,000H
  72. DB 006H,000H,000H,000H,000H,000H,000H,000H
  73. DB 000H,000H,000H,000H,000H,000H,000H,000H
  74. DB 007H,000H,000H,000H,000H,000H,000H,000H
  75. DB 000H,000H,000H,000H,000H,000H,000H,000H
  76. DB 008H,000H,000H,000H,000H,000H,000H,000H
  77. DB 000H,000H,000H,000H,000H,000H,000H,000H
  78. DB 009H,000H,000H,000H,000H,000H,000H,000H
  79. DB 000H,000H,000H,000H,000H,000H,000H,000H
  80. DB 00AH,000H,000H,000H,000H,000H,000H,000H
  81. DB 000H,000H,000H,000H,000H,000H,000H,000H
  82. DB 00BH,000H,000H,000H,000H,000H,000H,000H
  83. DB 000H,000H,000H,000H,000H,000H,000H,000H
  84. DB 00CH,000H,000H,000H,000H,000H,000H,000H
  85. DB 000H,000H,000H,000H,000H,000H,000H,000H
  86. DB 00DH,000H,000H,000H,000H,000H,000H,000H
  87. DB 000H,000H,000H,000H,000H,000H,000H,000H
  88. DB 00EH,000H,000H,000H,000H,000H,000H,000H
  89. DB 000H,000H,000H,000H,000H,000H,000H,000H
  90. DB 00FH
  91. CODESEG
  92. ;***************************************************************************
  93. ;* TEXT_PRINT -- Assembly text print routine. *
  94. ;* *
  95. ;* *
  96. ;* INPUT: *
  97. ;* *
  98. ;* OUTPUT: *
  99. ;* *
  100. ;* WARNINGS: *
  101. ;* *
  102. ;* HISTORY: *
  103. ;* 06/28/1994 SKB : Created. *
  104. ;*=========================================================================*
  105. PROC Text_Print C near
  106. USES ebx,ecx,edx,esi,edi
  107. ARG vpselector:WORD
  108. ARG vpoffset:DWORD
  109. ARG vpwidth:DWORD
  110. ARG vpheight:DWORD
  111. ARG vpxadd:DWORD
  112. ARG string:DWORD
  113. ARG x_pixel:DWORD
  114. ARG y_pixel:DWORD
  115. ARG fcolor:DWORD
  116. ARG bcolor:DWORD
  117. LOCAL infoblock:DWORD ; pointer to info block
  118. LOCAL offsetblock:DWORD ; pointer to offset block (UWORD *)
  119. LOCAL widthblock:DWORD ; pointer to width block (BYTE *)
  120. LOCAL heightblock:DWORD ; pointer to height block (UWORD *)
  121. LOCAL curline:DWORD ; pointer to first column of current row.
  122. LOCAL bufferwidth:DWORD ; width of buffer (vpwidth + Xadd)
  123. LOCAL nextdraw:DWORD ; bufferwidth - width of cur character.
  124. LOCAL startdraw:DWORD ; where next character will start being drawn.
  125. LOCAL char:DWORD ; current character value.
  126. LOCAL maxheight:BYTE ; max height of characters in font.
  127. LOCAL bottomblank:BYTE ; amount of empty space below current character.
  128. LOCAL charheight:BYTE ; true height of current character.
  129. ;-------------------------------- Where to draw -----------------------------------------------
  130. ; Set up memory location to start drawing.
  131. movzx eax,[vpselector]
  132. mov es,ax ; Set up selector to write to.
  133. mov eax,[vpwidth] ; get the width of the viewport
  134. add eax,[vpxadd] ; add amount to add to get to left edge of next line.
  135. mov [bufferwidth],eax ; save it off for later use.
  136. mul [y_pixel] ; multiply rowsize * y_pixel start.
  137. mov edi,[vpoffset] ; get start of the viewport
  138. add edi,eax ; add x,y position to start of vp to get starting row address.
  139. mov [curline],edi ; save 0,y address for line feed stuff.
  140. add edi,[x_pixel] ; add to get starting column in starting row.
  141. mov [startdraw],edi ; save it off.
  142. ;-------------------------------- Create block pointers ----------------------------------------
  143. ; Get the pointer to the font.
  144. ; We could check for NULL but why waste the time.
  145. ; It is up to programmer to make sure it is set.
  146. mov esi,[FontPtr] ; Get the font pointer
  147. ; Set up some pointers to the different memory blocks.
  148. ; esi (FontPtr) is added to each to get the true address of each block.
  149. ; Many registers are used for P5 optimizations.
  150. ; ebx is used for InfoBlock which is then used in the next section.
  151. movzx eax,[WORD PTR esi+FONTOFFSETBLOCK] ; get offset to offset block
  152. movzx ebx,[WORD PTR esi+FONTINFOBLOCK] ; get offset to info block (must be ebx for height test)
  153. movzx ecx,[WORD PTR esi+FONTWIDTHBLOCK] ; get offset to width block
  154. movzx edx,[WORD PTR esi+FONTHEIGHTBLOCK] ; get offset to height block
  155. add eax,esi ; add offset of FontPtr to offset block
  156. add ebx,esi ; add offset of FontPtr to info block
  157. add ecx,esi ; add offset of FontPtr to width block
  158. add edx,esi ; add offset of FontPtr to height block
  159. mov [offsetblock],eax ; save offset to offset block
  160. mov [infoblock],ebx ; save offset to info block
  161. mov [widthblock],ecx ; save offset to width block
  162. mov [heightblock],edx ; save offset to height block
  163. ;------------------------------------------ Test for fit ----------------------------------------------
  164. ; Test to make sure the height of the max character will fit on this line
  165. ; and and not fall out of the viewport.
  166. ; remember we set ebx to FONTINFOBLOCK above.
  167. movzx eax,[BYTE PTR ebx + FONTINFOMAXHEIGHT]; get the max height in font.
  168. mov [maxheight],al ; save it for later use.
  169. add eax,[y_pixel] ; add current y_value.
  170. cmp eax,[vpheight] ; are we over the edge?
  171. jg ??overflow ; if so, we're outa here.
  172. mov [y_pixel],eax ; save for next line feed. y value for next line.
  173. cld ; Make sure we are always forward copying.
  174. ;------------------------ Set palette foreground and background ----------------------------------
  175. mov eax,[fcolor] ; foreground color
  176. mov [ColorXlat+1],al
  177. mov [ColorXlat+16],al
  178. mov eax,[bcolor] ; background color
  179. mov [ColorXlat],al
  180. ;-------------------------------------------------------------------------------------------------
  181. ;----------------------------------------- Main loop ----------------------------------------------
  182. ; Now we go into the main loop of reading each character in the string and doing
  183. ; something with it.
  184. ??next_char:
  185. ; while (*string++)
  186. xor eax,eax ; zero out since we will just load al.
  187. mov esi,[string] ; get address on next character.
  188. lodsb ; load the character into al.
  189. test eax,0FFH ; test to see if character is a NULL
  190. jz ??done ; character is NULL, get outa here.
  191. mov edi,[startdraw] ; Load the starting address.
  192. mov [string],esi ; save index into string. (incremented by lodsb)
  193. cmp eax,13 ; is the character a line feed?
  194. je ??line_feed ; if so, go to special case.
  195. mov [char],eax ; save the character off for later reference.
  196. mov ebx,eax ; save it in ebx for later use also.
  197. add eax,[widthblock] ; figure address of width of character.
  198. mov ecx,[x_pixel] ; get current x_pixel.
  199. movzx edx,[BYTE PTR eax] ; get the width of the character in dl.
  200. add ecx,edx ; add width of char to current x_pixel.
  201. add [startdraw],edx ; save start draw for next character.
  202. cmp ecx,[vpwidth] ; is the pixel greater then the vp width?
  203. jg ??force_line_feed ; if so, force a line feed.
  204. mov [x_pixel],ecx ; save value of start of next character.
  205. mov ecx,[bufferwidth] ; get amount to next y same x (one row down)
  206. sub ecx,edx ; take the current width off.
  207. mov [nextdraw],ecx ; save it to add to edi when done with a row.
  208. ; At this point we got the character. It is now time to find out specifics
  209. ; about drawing the darn thing.
  210. ; ebx = char so they can be used as an indexes.
  211. ; edx = width of character for loop later.
  212. ; get offset of data for character into esi.
  213. shl ebx,1 ; mult by 2 to later use as a WORD index.
  214. mov esi,[offsetblock] ; get pointer to begining of offset block.
  215. add esi,ebx ; index into offset block.
  216. movzx esi,[WORD PTR esi] ; get true offset into data block from FontPtr.
  217. add esi,[FontPtr] ; Now add FontPtr address to get true address.
  218. ; Get top and bottom blank sizes and the true height of the character.
  219. add ebx,[heightblock] ; point ebx to element in height array.
  220. mov al,[ebx+1] ; load the data height into dl.
  221. mov cl,[ebx] ; load the first data row into cl.
  222. mov bl,[maxheight] ; get the max height of characters.
  223. mov [charheight],al ; get number of rows with data.
  224. add al,cl ; add the two heights.
  225. sub bl,al ; subract topblank + char height from maxheight.
  226. mov [bottomblank],bl ; save off the number of blank rows on the bottom.
  227. ; leaving this section:
  228. ; dl is still the width of the character.
  229. ; cl is the height of the top blank area.
  230. mov ebx,OFFSET ColorXlat ; setup ebx for xlat commands.
  231. mov dh,dl ; save the width of the character to restore each loop.
  232. cmp cl,0 ; is there any blank rows on top?
  233. jz ??draw_char ; if not go and draw the real character.
  234. xor eax,eax ; get color 0 for background.
  235. xlat [ebx] ; get translated color into al
  236. test al,al ; is it transparent black
  237. jnz ??loop_top ; if not go and write the color
  238. ;----------------------------------------- skip Top blank area ----------------------------------------
  239. ; this case, the top is transparrent, but we need to increase our dest pointer to correct row.
  240. movzx eax,cl ; get number of rows into eax;
  241. mov ecx,edx ; save width since edx will be destroyed by mul.
  242. mul [bufferwidth] ; multiply that by the width of the buffer.
  243. mov edx,ecx ; restore the width
  244. add edi,eax ; update the pointer.
  245. jmp short ??draw_char ; now go draw the character.
  246. ;----------------------------------------- fill Top blank area ----------------------------------------
  247. ; edi was set a long time ago.
  248. ; al is the translated color
  249. ??loop_top:
  250. stosb ; store the value
  251. dec dh ; decrement our width.
  252. jnz ??loop_top ; if more width, continue on.
  253. add edi,[nextdraw] ; add amount for entire row.
  254. dec cl ; decrement or row count
  255. mov dh,dl ; restore width in dh for loop.
  256. jz ??draw_char ; we are done here, go draw the character.
  257. jmp short ??loop_top ; go back to top of loop.
  258. ;----------------------------------------- Draw character ----------------------------------------------
  259. ??draw_char:
  260. movzx ecx,[charheight] ; get the height of character to count down rows.
  261. test ecx,ecx ; is there any data? (blank would not have any)
  262. jz ??next_char ; if no data, go on to next character.
  263. ??while_data:
  264. lodsb ; get byte value from font data
  265. mov ah,al ; save hinibble
  266. and eax,0F00FH ; mask of low nibble in al hi nibble in ah.
  267. xlat [ebx] ; get new color
  268. test al,al ; is it a transparent?
  269. jz short ??skiplo ; skip over write
  270. mov [es:edi],al ; write it out
  271. ??skiplo:
  272. inc edi
  273. dec dh ; decrement our width.
  274. jz short ??nextrow ; check if done with width of char
  275. mov al,ah ; restore to get
  276. ; test the time difference between looking up in a large table when shr al,4 is not done as
  277. ; compared to using only a 16 byte table when using the shr al,4
  278. ;shr al,4 ; shift the hi nibble down to low nibble
  279. xlat [ebx] ; get new color
  280. test al,al ; is it a transparent?
  281. jz short ??skiphi ; skip over write
  282. mov [es:edi],al ; write it out
  283. ??skiphi:
  284. inc edi
  285. dec dh ; decrement our width.
  286. jnz short ??while_data ; check if done with width of char
  287. ??nextrow:
  288. add edi,[nextdraw] ; go to next line.
  289. dec ecx ; decrement the number of rows to go
  290. mov dh,dl ; restore our column count for row.
  291. jnz ??while_data ; more data for character.
  292. ; Now it is time to setup for clearing out the bottom of the character.
  293. movzx ecx,[bottomblank] ; get amount on bottom that is blank
  294. cmp ecx,0 ; if there is no blank bottom...
  295. jz ??next_char ; then skip to go to next character
  296. xor eax,eax ; get color 0 for background.
  297. xlat [ebx] ; get translated color into al
  298. test al,al ; is it transparent black
  299. jz ??next_char ; skip the top black section to let the background through
  300. mov dh,dl ; restore width in dh for loop.
  301. ;----------------------------------------- Blank below character -----------------------------------
  302. ??loop_bottom:
  303. stosb ; store the value
  304. dec dh ; decrement our width.
  305. jnz ??loop_bottom ; if more width, continue on.
  306. add edi,[nextdraw] ; add amount for entire row.
  307. mov dh,dl ; restore width in dh for loop.
  308. dec cl ; decrement or row count
  309. jz ??next_char ; we are done here, go to the next character.
  310. jmp short ??loop_bottom ; go back to top of loop.
  311. ;----------------------------------- end of next_char (main) loop ------------------------------------
  312. ;-------------------------------------------------------------------------------------------------
  313. ;----------------------------------- special case line feeds ----------------------------------------
  314. ??force_line_feed:
  315. ; decrement pointer *string so that it will be back at same character
  316. ; when it goes through the loop.
  317. mov eax,[string] ; get string pointer.
  318. dec eax ; decrement it to point to previos char
  319. mov [string],eax ; save it back off.
  320. ; Now go into the line feed code.....
  321. ??line_feed:
  322. mov edx,[y_pixel] ; get the current y pixel value.
  323. movzx ecx,[maxheight] ; get max height for later use.
  324. add edx,ecx ; add max height to y_pixel
  325. cmp edx,[vpheight] ; are we over the edge?
  326. jg ??overflow ; if so, we are outa here.
  327. mov eax,[bufferwidth] ; get bytes to next line.
  328. mov edi,[curline] ; get start of current line.
  329. mul ecx ; mult max height * next line.
  330. add edi,eax ; add adjustment to current line.
  331. add [y_pixel],ecx ; increment to our next y position.
  332. mov [curline],edi ; save it off for next line_feed.
  333. mov [startdraw],edi ; save it off so we know where to draw next char.w
  334. mov [x_pixel],0 ; zero out x_pixel
  335. jmp ??next_char
  336. ??overflow:
  337. mov [startdraw],0 ; Indicate that there is no valid next pos.
  338. ??done:
  339. mov eax,[startdraw] ; return this so calling routine
  340. ret ; can figure out where to draw next.
  341. ENDP Text_Print
  342. ;***********************************************************
  343. END