CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

COORDA.ASM (7068B)


      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 
      9 ; TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 ; in the hope that it will be useful, but with permitted additional restrictions 
     11 ; under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 ; distributed with this program. You should have received a copy of the 
     13 ; GNU General Public License along with permitted additional restrictions 
     14 ; with this program. If not, see [https://github.com/electronicarts/CnC_Remastered_Collection]>.
     15 
     16 ;***************************************************************************
     17 ;**   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  **
     18 ;***************************************************************************
     19 ;*                                                                         *
     20 ;*                 Project Name : Command & Conquer                        *
     21 ;*                                                                         *
     22 ;*                    File Name : COORDA.ASM                               *
     23 ;*                                                                         *
     24 ;*                   Programmer : Barry W. Green                           *
     25 ;*                                                                         *
     26 ;*                   Start Date : February 17, 1995                        *
     27 ;*                                                                         *
     28 ;*                  Last Update : February 17, 1995  [BWG]                 *
     29 ;*                                                                         *
     30 ;*-------------------------------------------------------------------------*
     31 ;* Functions:                                                              *
     32 ;*   Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number.                 *
     33 ;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
     34 
     35 
     36 IDEAL
     37 P386
     38 MODEL USE32 FLAT
     39 
     40 global C	Cardinal_To_Fixed	:NEAR
     41 global C	Fixed_To_Cardinal	:NEAR
     42 
     43 	CODESEG
     44 
     45 ;***********************************************************************************************
     46 ;* Cardinal_To_Fixed -- Converts cardinal numbers into a fixed point number.                   *
     47 ;*                                                                                             *
     48 ;*    This utility function will convert cardinal numbers into a fixed point fraction. The     *
     49 ;*    use of fixed point numbers occurs throughout the product -- since it is a convenient     *
     50 ;*    tool. The fixed point number is based on the formula:                                    *
     51 ;*                                                                                             *
     52 ;*       result = cardinal / base                                                              *
     53 ;*                                                                                             *
     54 ;*    The accuracy of the fixed point number is limited to 1/256 as the lowest and up to       *
     55 ;*    256 as the largest.                                                                      *
     56 ;*                                                                                             *
     57 ;* INPUT:   base     -- The key number to base the fraction about.                             *
     58 ;*                                                                                             *
     59 ;*          cardinal -- The other number (hey -- what do you call it?)                         *
     60 ;*                                                                                             *
     61 ;* OUTPUT:  Returns with the fixed point number of the "cardinal" parameter as it relates      *
     62 ;*          to the "base" parameter.                                                           *
     63 ;*                                                                                             *
     64 ;* WARNINGS:   none                                                                            *
     65 ;*                                                                                             *
     66 ;* HISTORY:                                                                                    *
     67 ;*   02/17/1995 BWG : Created.                                                                 *
     68 ;*=============================================================================================*/
     69 ;unsigned int Cardinal_To_Fixed(unsigned base, unsigned cardinal);
     70 
     71 	PROC	Cardinal_To_Fixed C near
     72 	USES	ebx, edx
     73 
     74 	ARG	base:DWORD
     75 	ARG	cardinal:DWORD
     76 
     77 	mov	eax,0FFFFh		; establish default return value
     78 
     79 	mov	ebx,[base]
     80 	or	ebx,ebx
     81 	jz	near ??retneg1		; if base==0, return 65535
     82 
     83 	mov	eax,[cardinal]		; otherwise, return (cardinal*256)/base
     84 	shl	eax,8
     85 	xor	edx,edx
     86 	div	ebx
     87 
     88 ??retneg1:
     89 	ret
     90 
     91 	ENDP	Cardinal_To_Fixed
     92 
     93 
     94 ;***********************************************************************************************
     95 ;* Fixed_To_Cardinal -- Converts a fixed point number into a cardinal number.                  *
     96 ;*                                                                                             *
     97 ;*    Use this routine to convert a fixed point number into a cardinal number.                 *
     98 ;*                                                                                             *
     99 ;* INPUT:   base     -- The base number that the original fixed point number was created from. *
    100 ;*                                                                                             *
    101 ;*          fixed    -- The fixed point number to convert.                                     *
    102 ;*                                                                                             *
    103 ;* OUTPUT:  Returns with the reconverted number.                                               *
    104 ;*                                                                                             *
    105 ;* WARNINGS:   none                                                                            *
    106 ;*                                                                                             *
    107 ;* HISTORY:                                                                                    *
    108 ;*   02/17/1995 BWG : Created.                                                                 *
    109 ;*=============================================================================================*/
    110 ;unsigned int Fixed_To_Cardinal(unsigned base, unsigned fixed);
    111 	PROC	Fixed_To_Cardinal C near
    112 	USES	edx
    113 
    114 	ARG	base:DWORD
    115 	ARG	fixed:DWORD
    116 
    117 	mov	eax,[base]
    118 	mul	[fixed]
    119 	add	eax,080h		; eax = (base * fixed) + 0x80
    120 
    121 	test	eax,0FF000000h		; if high byte set, return FFFF
    122 	jnz	??rneg1
    123 	shr	eax,8			; else, return eax/256
    124 	ret
    125 ??rneg1	:
    126 	mov	eax,0FFFFh		; establish default return value
    127 	ret
    128 
    129 	ENDP	Fixed_To_Cardinal
    130 
    131 	END