COORDA.ASM 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. ;
  2. ; Copyright 2020 Electronic Arts Inc.
  3. ;
  4. ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. ; software: you can redistribute it and/or modify it under the terms of
  6. ; the GNU General Public License as published by the Free Software Foundation,
  7. ; either version 3 of the License, or (at your option) any later version.
  8. ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. ; in the hope that it will be useful, but with permitted additional restrictions
  10. ; under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. ; distributed with this program. You should have received a copy of the
  12. ; GNU General Public License along with permitted additional restrictions
  13. ; with this program. If not, see [https://github.com/electronicarts/CnC_Remastered_Collection]>.
  14. ;***************************************************************************
  15. ;** 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 I N C **
  16. ;***************************************************************************
  17. ;* *
  18. ;* Project Name : Command & Conquer *
  19. ;* *
  20. ;* File Name : COORDA.ASM *
  21. ;* *
  22. ;* Programmer : Barry W. Green *
  23. ;* *
  24. ;* Start Date : February 17, 1995 *
  25. ;* *
  26. ;* Last Update : February 17, 1995 [BWG] *
  27. ;* *
  28. ;*-------------------------------------------------------------------------*
  29. ;* Functions: *
  30. ;* Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number. *
  31. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  32. IDEAL
  33. P386
  34. MODEL USE32 FLAT
  35. global C Cardinal_To_Fixed :NEAR
  36. global C Fixed_To_Cardinal :NEAR
  37. CODESEG
  38. ;***********************************************************************************************
  39. ;* Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number. *
  40. ;* *
  41. ;* This utility function will convert cardinal numbers into a fixed point fraction. The *
  42. ;* use of fixed point numbers occurs throughout the product -- since it is a convenient *
  43. ;* tool. The fixed point number is based on the formula: *
  44. ;* *
  45. ;* result = cardinal / base *
  46. ;* *
  47. ;* The accuracy of the fixed point number is limited to 1/65536 as the lowest and up to *
  48. ;* 65536 as the largest. *
  49. ;* *
  50. ;* INPUT: base -- The key number to base the fraction about. *
  51. ;* *
  52. ;* cardinal -- The other number (hey -- what do you call it?) *
  53. ;* *
  54. ;* OUTPUT: Returns with the fixed point number of the "cardinal" parameter as it relates *
  55. ;* to the "base" parameter. *
  56. ;* *
  57. ;* WARNINGS: none *
  58. ;* *
  59. ;* HISTORY: *
  60. ;* 02/17/1995 BWG : Created. *
  61. ;*=============================================================================================*/
  62. ;unsigned int Cardinal_To_Fixed(unsigned base, unsigned cardinal);
  63. PROC Cardinal_To_Fixed C near
  64. USES ebx, edx
  65. ARG base:DWORD
  66. ARG cardinal:DWORD
  67. mov eax,0FFFFFFFFh ; establish default return value
  68. mov ebx,[base]
  69. or ebx,ebx
  70. jz near ??retneg1 ; if base==0, return 4294967295
  71. mov eax,[cardinal] ; otherwise, return (cardinal*65536)/base
  72. shl eax,16
  73. xor edx,edx
  74. div ebx
  75. ??retneg1:
  76. ret
  77. ENDP Cardinal_To_Fixed
  78. ;***********************************************************************************************
  79. ;* Fixed_To_Cardinal -- Converts a fixed point number into a cardinal number. *
  80. ;* *
  81. ;* Use this routine to convert a fixed point number into a cardinal number. *
  82. ;* *
  83. ;* INPUT: base -- The base number that the original fixed point number was created from. *
  84. ;* *
  85. ;* fixed -- The fixed point number to convert. *
  86. ;* *
  87. ;* OUTPUT: Returns with the reconverted number. *
  88. ;* *
  89. ;* WARNINGS: none *
  90. ;* *
  91. ;* HISTORY: *
  92. ;* 02/17/1995 BWG : Created. *
  93. ;*=============================================================================================*/
  94. ;unsigned int Fixed_To_Cardinal(unsigned base, unsigned fixed);
  95. PROC Fixed_To_Cardinal C near
  96. USES edx
  97. ARG base:DWORD
  98. ARG fixed:DWORD
  99. mov eax,[base]
  100. mul [fixed]
  101. add eax,08000h ; eax = (base * fixed) + 0x8000
  102. shr eax,16 ; return eax/65536
  103. ret
  104. ENDP Fixed_To_Cardinal
  105. END