STMPCACH.ASM 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 : Westwood Library *
  23. ;* *
  24. ;* File Name : STAMP.ASM *
  25. ;* *
  26. ;* Programmer : Joe L. Bostic *
  27. ;* *
  28. ;* Start Date : August 23, 1993 *
  29. ;* *
  30. ;* Last Update : August 23, 1993 [JLB] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  35. IDEAL
  36. P386
  37. MODEL USE32 FLAT
  38. JUMPS
  39. MAX_CACHED_ICONS=300
  40. ICON_WIDTH =24
  41. ICON_HEIGHT =24
  42. MAX_ICON_SETS =100
  43. global C IconPointers:dword
  44. global C Init_Stamps:near
  45. global C IconCacheLookup:word
  46. global LastIconset:dword
  47. global MapPtr:dword
  48. global IconCount:dword
  49. global IconSize:dword
  50. global StampPtr:dword
  51. global IconEntry:dword
  52. global IconData:dword
  53. global Clear_Icon_Pointers_:near
  54. global Cache_Copy_Icon_:near
  55. global Is_Icon_Cached_:near
  56. global Get_Icon_Index_:near
  57. global Get_Free_Index_:near
  58. global Cache_New_Icon_:near
  59. global Is_Stamp_Registered_:near
  60. global Get_Free_Cache_Slot_:near
  61. struc IconSetType
  62. IconSetPtr dd ?
  63. IconListOffset dd ?
  64. ends
  65. global C IconSetList:IconSetType
  66. codeseg
  67. ;************************************************************************************************
  68. ;* Cache_Copy_Icon -- copy an icon to its video memory cache *
  69. ;* *
  70. ;* *
  71. ;* INPUT: eax - ptr to icon_data *
  72. ;* edx - ptr to video surface *
  73. ;* ebx - pitch of video surface *
  74. ;* *
  75. ;* OUTPUT: none *
  76. ;* *
  77. ;* PROTO: extern "C" Cache_Copy_Icon (void const *icon_ptr , *
  78. ;* VideoSurfaceDescription.lpSurface , *
  79. ;* VideoSurfaceDescription.lPitch); *
  80. ;* *
  81. ;* HISTORY: *
  82. ;* 11/8/95 3:16PM ST: Created *
  83. ;*==============================================================================================*
  84. proc Cache_Copy_Icon_ near
  85. pushad
  86. mov esi,eax
  87. mov edi,edx
  88. sub ebx,ICON_WIDTH
  89. mov dl,ICON_HEIGHT ;icon height
  90. ??each_line_lp: mov ecx,ICON_WIDTH/4
  91. rep movsd
  92. lea edi,[edi+ebx]
  93. dec dl
  94. jnz ??each_line_lp
  95. popad
  96. ret
  97. endp Cache_Copy_Icon_
  98. ;************************************************************************************************
  99. ;* Is_Icon_Cached -- has an icon been cached? If not, is it cacheable? *
  100. ;* *
  101. ;* *
  102. ;* INPUT: eax - ptr to icon_data *
  103. ;* edx - icon number *
  104. ;* *
  105. ;* OUTPUT: eax - index of cached icon or -1 if not cached *
  106. ;* *
  107. ;* PROTO: extern "C" int Is_Icon_Cached (void const *icon_data , int icon); *
  108. ;* *
  109. ;* HISTORY: *
  110. ;* 11/8/95 2:16PM ST: Created *
  111. ;*==============================================================================================*
  112. proc Is_Icon_Cached_ near
  113. mov [IconData],eax ;save the icon data ptr for later
  114. push edx
  115. test eax,eax
  116. je ??out
  117. ; Initialize the stamp data if necessary.
  118. cmp [LastIconset],eax
  119. je short ??noreset
  120. call Init_Stamps C,eax
  121. ; Determine if the icon number requested is actually in the set.
  122. ; Perform the logical icon to actual icon number remap if necessary.
  123. ??noreset: cmp [MapPtr],0
  124. je short ??notmap
  125. push edi
  126. mov edi,[MapPtr]
  127. mov dl,[edi+edx]
  128. pop edi
  129. ??notmap: cmp edx,[IconCount]
  130. jl ??in_range
  131. pop edx
  132. mov eax,-1
  133. ret
  134. ; See if the stamp is registered - if not then it cant be cached
  135. ??in_range: mov eax,[IconData]
  136. call Is_Stamp_Registered_
  137. cmp eax,-1
  138. jnz ??got_entry
  139. pop edx
  140. ret
  141. ; Stamp is registered - if its cached already then just return the index
  142. ??got_entry: mov eax,[(IconSetType eax).IconListOffset]
  143. cmp [word eax+edx*2+IconCacheLookup],-1
  144. jz ??not_cached
  145. ; it is cached and [eax+edx] is the index
  146. movzx eax,[word eax+edx*2+IconCacheLookup]
  147. pop edx
  148. ret
  149. ;
  150. ; The stamps set is registered but we havn't seen this stamp before
  151. ; so try caching it
  152. ;
  153. ??not_cached: mov [IconEntry],eax
  154. add [IconEntry],edx
  155. add [IconEntry],edx
  156. call Get_Free_Cache_Slot_
  157. test eax,eax
  158. jge ??got_free_slot
  159. pop edx ;eax is -1 here anyway
  160. ret
  161. ; We found a free caching slot so try caching the stamp into it
  162. ??got_free_slot:imul edx,[IconSize]
  163. add edx,[StampPtr]
  164. push eax
  165. call Cache_New_Icon_ ;takes icon index in eax, ptr to icon in edx
  166. test eax,eax
  167. jz ??cache_failed
  168. ; Success! Add the index into the table
  169. pop eax
  170. mov edx,[IconEntry]
  171. mov [edx+IconCacheLookup],ax
  172. and eax,0ffffh
  173. pop edx
  174. ret
  175. ; Couldnt cache the new Icon - return -1 to say icon isnt cached
  176. ??cache_failed: pop eax
  177. ??out: pop edx
  178. mov eax,-1
  179. ret
  180. endp Is_Icon_Cached_
  181. ;************************************************************************************************
  182. ;* Is_Stamp_Registered -- has an icon's set been previously registered? *
  183. ;* *
  184. ;* *
  185. ;* INPUT: eax - ptr to icon_data *
  186. ;* *
  187. ;* OUTPUT: eax - ptr to registration entry or -1 if not registered *
  188. ;* *
  189. ;* PROTO: extern "C" int Is_Stamp_Registered (void const *icon_data); *
  190. ;* *
  191. ;* HISTORY: *
  192. ;* 11/10/95 10:00AM ST: Created *
  193. ;*==============================================================================================*
  194. proc Is_Stamp_Registered_
  195. push edi
  196. push ecx
  197. mov edi,offset IconSetList
  198. mov ecx,MAX_ICON_SETS
  199. ??each_set_lp: cmp eax,[edi]
  200. jz ??got_icon_set
  201. add edi,size IconSetType
  202. dec ecx
  203. jnz ??each_set_lp
  204. mov eax,-1
  205. pop ecx
  206. pop edi
  207. ret
  208. ??got_icon_set: mov eax,edi
  209. pop ecx
  210. pop edi
  211. ret
  212. endp Is_Stamp_Registered_
  213. dataseg
  214. IconEntry dd 0 ;Temporary pointer to icon index entry in table
  215. IconData dd 0 ;Temporary ptr to icon set data
  216. end