This repository was archived by the owner on Feb 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathCOORDA.ASM
134 lines (114 loc) · 6.77 KB
/
COORDA.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
;
; Command & Conquer(tm)
; Copyright 2025 Electronic Arts Inc.
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <http://www.gnu.org/licenses/>.
;
;***************************************************************************
;** 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 **
;***************************************************************************
;* *
;* Project Name : Command & Conquer *
;* *
;* File Name : COORDA.ASM *
;* *
;* Programmer : Barry W. Green *
;* *
;* Start Date : February 17, 1995 *
;* *
;* Last Update : February 17, 1995 [BWG] *
;* *
;*-------------------------------------------------------------------------*
;* Functions: *
;* Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number. *
;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
IDEAL
P386
MODEL USE32 FLAT
global C Cardinal_To_Fixed :NEAR
global C Fixed_To_Cardinal :NEAR
CODESEG
;***********************************************************************************************
;* Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number. *
;* *
;* This utility function will convert cardinal numbers into a fixed point fraction. The *
;* use of fixed point numbers occurs throughout the product -- since it is a convenient *
;* tool. The fixed point number is based on the formula: *
;* *
;* result = cardinal / base *
;* *
;* The accuracy of the fixed point number is limited to 1/256 as the lowest and up to *
;* 256 as the largest. *
;* *
;* INPUT: base -- The key number to base the fraction about. *
;* *
;* cardinal -- The other number (hey -- what do you call it?) *
;* *
;* OUTPUT: Returns with the fixed point number of the "cardinal" parameter as it relates *
;* to the "base" parameter. *
;* *
;* WARNINGS: none *
;* *
;* HISTORY: *
;* 02/17/1995 BWG : Created. *
;*=============================================================================================*/
;unsigned int Cardinal_To_Fixed(unsigned base, unsigned cardinal);
PROC Cardinal_To_Fixed C near
USES ebx, edx
ARG base:DWORD
ARG cardinal:DWORD
mov eax,0FFFFh ; establish default return value
mov ebx,[base]
or ebx,ebx
jz near ??retneg1 ; if base==0, return 65535
mov eax,[cardinal] ; otherwise, return (cardinal*256)/base
shl eax,8
xor edx,edx
div ebx
??retneg1:
ret
ENDP Cardinal_To_Fixed
;***********************************************************************************************
;* Fixed_To_Cardinal -- Converts a fixed point number into a cardinal number. *
;* *
;* Use this routine to convert a fixed point number into a cardinal number. *
;* *
;* INPUT: base -- The base number that the original fixed point number was created from. *
;* *
;* fixed -- The fixed point number to convert. *
;* *
;* OUTPUT: Returns with the reconverted number. *
;* *
;* WARNINGS: none *
;* *
;* HISTORY: *
;* 02/17/1995 BWG : Created. *
;*=============================================================================================*/
;unsigned int Fixed_To_Cardinal(unsigned base, unsigned fixed);
PROC Fixed_To_Cardinal C near
USES edx
ARG base:DWORD
ARG fixed:DWORD
mov eax,[base]
mul [fixed]
add eax,080h ; eax = (base * fixed) + 0x80
test eax,0FF000000h ; if high byte set, return FFFF
jnz ??rneg1
shr eax,8 ; else, return eax/256
ret
??rneg1 :
mov eax,0FFFFh ; establish default return value
ret
ENDP Fixed_To_Cardinal
END