COORDA.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. ;***************************************************************************
  16. ;** 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 **
  17. ;***************************************************************************
  18. ;* *
  19. ;* Project Name : Command & Conquer *
  20. ;* *
  21. ;* File Name : COORDA.ASM *
  22. ;* *
  23. ;* Programmer : Barry W. Green *
  24. ;* *
  25. ;* Start Date : February 17, 1995 *
  26. ;* *
  27. ;* Last Update : February 17, 1995 [BWG] *
  28. ;* *
  29. ;*-------------------------------------------------------------------------*
  30. ;* Functions: *
  31. ;* Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number. *
  32. ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  33. */
  34. #ifndef COORD_A_H
  35. //IDEAL
  36. //P386
  37. //MODEL USE32 FLAT
  38. //global C Cardinal_To_Fixed :NEAR
  39. //global C Fixed_To_Cardinal :NEAR
  40. // CODESEG
  41. /*
  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 __cdecl Cardinal_To_Fixed(unsigned base, unsigned cardinal);
  67. #if (0)
  68. PROC Cardinal_To_Fixed C near
  69. USES ebx, edx
  70. ARG base:DWORD
  71. ARG cardinal:DWORD
  72. mov eax,0FFFFh ; establish default return value
  73. mov ebx,[base]
  74. or ebx,ebx
  75. jz near ??retneg1 ; if base==0, return 65535
  76. mov eax,[cardinal] ; otherwise, return (cardinal*256)/base
  77. shl eax,8
  78. xor edx,edx
  79. div ebx
  80. ??retneg1:
  81. ret
  82. ENDP Cardinal_To_Fixed
  83. #endif
  84. /*
  85. ;***********************************************************************************************
  86. ;* Fixed_To_Cardinal -- Converts a fixed point number into a cardinal number. *
  87. ;* *
  88. ;* Use this routine to convert a fixed point number into a cardinal number. *
  89. ;* *
  90. ;* INPUT: base -- The base number that the original fixed point number was created from. *
  91. ;* *
  92. ;* fixed -- The fixed point number to convert. *
  93. ;* *
  94. ;* OUTPUT: Returns with the reconverted number. *
  95. ;* *
  96. ;* WARNINGS: none *
  97. ;* *
  98. ;* HISTORY: *
  99. ;* 02/17/1995 BWG : Created. *
  100. ;*=============================================================================================*/
  101. unsigned int __cdecl Fixed_To_Cardinal(unsigned base, unsigned fixed);
  102. #if (0)
  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
  115. #endif
  116. #endif COORD_A_H