COORDA.ASM 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ;
  2. ; Command & Conquer(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 I N C **
  20. ;***************************************************************************
  21. ;* *
  22. ;* Project Name : Command & Conquer *
  23. ;* *
  24. ;* File Name : COORDA.ASM *
  25. ;* *
  26. ;* Programmer : Barry W. Green *
  27. ;* *
  28. ;* Start Date : February 17, 1995 *
  29. ;* *
  30. ;* Last Update : February 17, 1995 [BWG] *
  31. ;* *
  32. ;*-------------------------------------------------------------------------*
  33. ;* Functions: *
  34. ;* Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number. *
  35. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  36. IDEAL
  37. P386
  38. MODEL USE32 FLAT
  39. global C Cardinal_To_Fixed :NEAR
  40. global C Fixed_To_Cardinal :NEAR
  41. CODESEG
  42. ;***********************************************************************************************
  43. ;* Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number. *
  44. ;* *
  45. ;* This utility function will convert cardinal numbers into a fixed point fraction. The *
  46. ;* use of fixed point numbers occurs throughout the product -- since it is a convenient *
  47. ;* tool. The fixed point number is based on the formula: *
  48. ;* *
  49. ;* result = cardinal / base *
  50. ;* *
  51. ;* The accuracy of the fixed point number is limited to 1/256 as the lowest and up to *
  52. ;* 256 as the largest. *
  53. ;* *
  54. ;* INPUT: base -- The key number to base the fraction about. *
  55. ;* *
  56. ;* cardinal -- The other number (hey -- what do you call it?) *
  57. ;* *
  58. ;* OUTPUT: Returns with the fixed point number of the "cardinal" parameter as it relates *
  59. ;* to the "base" parameter. *
  60. ;* *
  61. ;* WARNINGS: none *
  62. ;* *
  63. ;* HISTORY: *
  64. ;* 02/17/1995 BWG : Created. *
  65. ;*=============================================================================================*/
  66. ;unsigned int Cardinal_To_Fixed(unsigned base, unsigned cardinal);
  67. PROC Cardinal_To_Fixed C near
  68. USES ebx, edx
  69. ARG base:DWORD
  70. ARG cardinal:DWORD
  71. mov eax,0FFFFh ; establish default return value
  72. mov ebx,[base]
  73. or ebx,ebx
  74. jz near ??retneg1 ; if base==0, return 65535
  75. mov eax,[cardinal] ; otherwise, return (cardinal*256)/base
  76. shl eax,8
  77. xor edx,edx
  78. div ebx
  79. ??retneg1:
  80. ret
  81. ENDP Cardinal_To_Fixed
  82. ;***********************************************************************************************
  83. ;* Fixed_To_Cardinal -- Converts a fixed point number into a cardinal number. *
  84. ;* *
  85. ;* Use this routine to convert a fixed point number into a cardinal number. *
  86. ;* *
  87. ;* INPUT: base -- The base number that the original fixed point number was created from. *
  88. ;* *
  89. ;* fixed -- The fixed point number to convert. *
  90. ;* *
  91. ;* OUTPUT: Returns with the reconverted number. *
  92. ;* *
  93. ;* WARNINGS: none *
  94. ;* *
  95. ;* HISTORY: *
  96. ;* 02/17/1995 BWG : Created. *
  97. ;*=============================================================================================*/
  98. ;unsigned int Fixed_To_Cardinal(unsigned base, unsigned fixed);
  99. PROC Fixed_To_Cardinal C near
  100. USES edx
  101. ARG base:DWORD
  102. ARG fixed:DWORD
  103. mov eax,[base]
  104. mul [fixed]
  105. add eax,080h ; eax = (base * fixed) + 0x80
  106. test eax,0FF000000h ; if high byte set, return FFFF
  107. jnz ??rneg1
  108. shr eax,8 ; else, return eax/256
  109. ret
  110. ??rneg1 :
  111. mov eax,0FFFFh ; establish default return value
  112. ret
  113. ENDP Fixed_To_Cardinal
  114. END