Initial commit of Command & Conquer Red Alert source code.
This commit is contained in:
165
WWFLAT32/FILE/DEVICES.ASM
Normal file
165
WWFLAT32/FILE/DEVICES.ASM
Normal file
@@ -0,0 +1,165 @@
|
||||
;
|
||||
; Command & Conquer Red Alert(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/>.
|
||||
;
|
||||
|
||||
; $Header: g:/library/wwlib32/system/rcs/devices.asm 1.2 1994/04/28 12:41:41 jeff_wilson Exp $
|
||||
;***************************************************************************
|
||||
;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
|
||||
;***************************************************************************
|
||||
;* *
|
||||
;* Project Name : LIBRARY *
|
||||
;* *
|
||||
;* File Name : DEVICES.ASM *
|
||||
;* *
|
||||
;* Programmer : Christopher Yates *
|
||||
;* *
|
||||
;* Last Update : 12 December, 1990 [CY] *
|
||||
;* *
|
||||
;*-------------------------------------------------------------------------*
|
||||
;* Functions: *
|
||||
;* *
|
||||
; VOID Get_Devices(VOID); *
|
||||
; WORD Is_Device_Real(WORD drive); *
|
||||
;* *
|
||||
;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
|
||||
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
|
||||
IDEAL
|
||||
P386
|
||||
MODEL USE32 FLAT
|
||||
|
||||
GLOBAL Get_Devices :NEAR
|
||||
GLOBAL Is_Device_Real :NEAR
|
||||
|
||||
GLOBAL MaxDevice :BYTE
|
||||
GLOBAL DefaultDrive :BYTE
|
||||
|
||||
; ----------------------------------------------------------------
|
||||
;
|
||||
; Here are prototypes for the routines defined within this module:
|
||||
;
|
||||
; VOID Get_Devices(VOID);
|
||||
; WORD Is_Device_Real(WORD drive);
|
||||
;
|
||||
; ----------------------------------------------------------------
|
||||
|
||||
CODESEG
|
||||
|
||||
;***********************************************************
|
||||
;
|
||||
; GET_DEVICES
|
||||
;
|
||||
; VOID Get_Devices(VOID);
|
||||
;
|
||||
; This routine establishes the default disk drive and the maximum drive
|
||||
; available in the current system.
|
||||
;
|
||||
;*
|
||||
DOS equ 21h
|
||||
|
||||
PROC Get_Devices C near
|
||||
USES eax,ebx,edx
|
||||
|
||||
sub eax,eax
|
||||
mov ah,25 ; get current drive service
|
||||
int DOS ; drive returned in al
|
||||
mov [DefaultDrive],al ; save it
|
||||
mov dl,al
|
||||
mov ah,14 ; set current as current drive
|
||||
int DOS
|
||||
dec al ; al = max drives, make it n - 1
|
||||
xor ah,ah ; clear high byte
|
||||
mov edx,eax ; use dx to go backward to find out
|
||||
sub ebx,ebx
|
||||
|
||||
??back_loop:
|
||||
mov bl,dl ; find out about the drive in dl
|
||||
inc bl
|
||||
mov eax,0440Eh ; get the physical drive associated
|
||||
int DOS ; with this letter
|
||||
jnc short ??later ; if c clear, no error
|
||||
cmp al,0Fh ; was it invalid? (0Fh = invalid)
|
||||
jne short ??later ; yes, so LATER
|
||||
dec edx
|
||||
jmp ??back_loop ; try, try again
|
||||
|
||||
??later:
|
||||
mov eax,edx ; restore ax
|
||||
mov [MaxDevice],al ; save the max drive #
|
||||
|
||||
ret
|
||||
|
||||
ENDP Get_Devices
|
||||
|
||||
;***************************************************************
|
||||
|
||||
|
||||
;***************************************************************
|
||||
;
|
||||
; IS_DEVICE_REAL
|
||||
;
|
||||
; WORD Is_Device_Real(WORD drive);
|
||||
;
|
||||
; This routine will tell whether or not a device is a true
|
||||
; phisical one. Send it the drive # to check.
|
||||
;
|
||||
;*
|
||||
PROC Is_Device_Real C near
|
||||
USES ebx,edx
|
||||
ARG drive:WORD
|
||||
|
||||
sub edx,edx
|
||||
mov dx,[drive]
|
||||
|
||||
??next_drive:
|
||||
push ebx
|
||||
mov bl,dl ; find out about the drive in dl
|
||||
inc bl
|
||||
mov eax,0440Eh ; get the physical drive associated
|
||||
int DOS ; with this letter
|
||||
pop ebx
|
||||
|
||||
jnc short ??it_is_real ; jump if no error
|
||||
cmp al,01 ; 1 = invalid command,
|
||||
; 0F = invalid device
|
||||
je short ??real ; 1? it is ok (RAM device)
|
||||
jmp short ??invalid ; 0Fh, it was not a device
|
||||
|
||||
??it_is_real:
|
||||
cmp al,0 ; was it a fixed device?
|
||||
je short ??real ; yes, it's ok
|
||||
dec al ; make it a drive #
|
||||
cmp al,dl ; is it a valid drive?
|
||||
je short ??real
|
||||
|
||||
??invalid: ; The device is invalid.
|
||||
mov eax,0
|
||||
jmp short ??out
|
||||
|
||||
??real: ; Return true, for valid device.
|
||||
mov eax,1
|
||||
|
||||
??out:
|
||||
ret
|
||||
ENDP Is_Device_Real
|
||||
|
||||
;***************************************************************
|
||||
|
||||
END
|
||||
|
204
WWFLAT32/FILE/DEVTABLE.ASM
Normal file
204
WWFLAT32/FILE/DEVTABLE.ASM
Normal file
@@ -0,0 +1,204 @@
|
||||
;
|
||||
; Command & Conquer Red Alert(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/>.
|
||||
;
|
||||
|
||||
; $Header: g:/library/wwlib32/system/rcs/devtable.asm 1.2 1994/04/28 12:41:29 jeff_wilson Exp $
|
||||
;***************************************************************************
|
||||
;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
|
||||
;***************************************************************************
|
||||
;* *
|
||||
;* Project Name : LIBRARY *
|
||||
;* *
|
||||
;* File Name : DEVTABLE.ASM *
|
||||
;* *
|
||||
;* Programmer : Christopher Yates *
|
||||
;* *
|
||||
;* Last Update : 12 December, 1990 [CY] *
|
||||
;* *
|
||||
;* Updated to 32bit protected mode JAW *
|
||||
;* *
|
||||
;*-------------------------------------------------------------------------*
|
||||
;* Functions: *
|
||||
;* *
|
||||
; VOID Init_Device_Table(BYTE *table); *
|
||||
; WORD Max_Device(VOID); *
|
||||
;* *
|
||||
;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
|
||||
|
||||
IDEAL
|
||||
P386
|
||||
MODEL USE32 FLAT
|
||||
|
||||
LOCALS ??
|
||||
|
||||
DOS equ 21h
|
||||
|
||||
GLOBAL Max_Device :NEAR
|
||||
GLOBAL get_max_device :NEAR
|
||||
GLOBAL Init_Device_Table :NEAR
|
||||
|
||||
|
||||
CODESEG
|
||||
|
||||
; ----------------------------------------------------------------
|
||||
;
|
||||
; Here are prototypes for the routines defined within this module:
|
||||
;
|
||||
; VOID Init_Device_Table(BYTE *table);
|
||||
; WORD Max_Device(VOID);
|
||||
;
|
||||
; ----------------------------------------------------------------
|
||||
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
;
|
||||
; WORD Max_Device(VOID);
|
||||
;
|
||||
|
||||
PROC Max_Device C NEAR
|
||||
|
||||
call get_max_device ; get max devices in ax
|
||||
ret
|
||||
|
||||
ENDP Max_Device
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
;
|
||||
;
|
||||
; returns max devices in AX
|
||||
|
||||
PROC get_max_device C NEAR
|
||||
USES ebx,edx
|
||||
|
||||
mov ah,25 ; get current drive service
|
||||
int DOS ; drive returned in al
|
||||
mov dl,al
|
||||
mov ah,14 ; set current as current drive
|
||||
int DOS
|
||||
dec al ; al = max drives, make it n - 1
|
||||
xor ah,ah ; clear high byte
|
||||
sub edx,edx
|
||||
mov edx,eax ; use dx to go backward to find out
|
||||
; if DOS is lying (down)
|
||||
|
||||
??back_loop:
|
||||
push ds
|
||||
push ebx
|
||||
mov bl,dl ; find out about the drive in dl
|
||||
inc bl
|
||||
mov eax,0440Eh ; get the physical drive associated
|
||||
int DOS ; with this letter
|
||||
pop ebx
|
||||
pop ds
|
||||
jnc short ??later ; if c clear, no error
|
||||
|
||||
cmp al,0Fh ; was it invalid? (0Fh = invalid)
|
||||
jne short ??later ; yes, so LATER
|
||||
|
||||
dec edx
|
||||
jmp ??back_loop ; try, try again
|
||||
|
||||
??later:
|
||||
mov eax,edx ; restore ax
|
||||
ret
|
||||
|
||||
ENDP get_max_device
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
;
|
||||
; VOID Init_Device_Table(BYTE *table);
|
||||
;
|
||||
|
||||
PROC Init_Device_Table C NEAR
|
||||
|
||||
USES eax,ebx,edi,edx
|
||||
ARG table:DWORD ; Pointer to device table.
|
||||
LOCAL curr_drive:BYTE ; Copy of current drive number.
|
||||
|
||||
mov edi,[table]
|
||||
|
||||
call get_max_device ; get max devices in ax
|
||||
add edi,eax
|
||||
std
|
||||
mov [curr_drive],al ; save it
|
||||
|
||||
??next_drive:
|
||||
mov dl,[curr_drive] ; copy current drive #
|
||||
cmp dl,0FFh ; are we done?
|
||||
je short ??later ; if so, later
|
||||
|
||||
dec [curr_drive] ; dec our local drive #
|
||||
|
||||
push ds
|
||||
push ebx
|
||||
mov bl,dl ; find out about the drive in dl
|
||||
inc bl
|
||||
mov eax,0440Eh ; get the physical drive associated
|
||||
int DOS ; with this letter
|
||||
pop ebx
|
||||
pop ds
|
||||
|
||||
jnc short ??it_is_real ; jump if no error
|
||||
cmp al,01 ; 1 = invalid command,
|
||||
; 0F = invalid device
|
||||
je short ??set_as_current ; 1? it is ok (RAM device)
|
||||
jmp short ??invalid ; 0Fh, it was not a device
|
||||
|
||||
|
||||
??it_is_real:
|
||||
cmp al,0 ; was it a fixed device?
|
||||
je short ??set_as_current ; yes, it's ok
|
||||
|
||||
dec al ; make it a drive #
|
||||
cmp al,dl ; is it a valid drive?
|
||||
je short ??set_as_current
|
||||
|
||||
;
|
||||
; Device was logical and not active, so clear the entry
|
||||
;
|
||||
??invalid:
|
||||
xor al,al
|
||||
stosb
|
||||
cmp [curr_drive],0 ; are we done checking?
|
||||
jge ??next_drive ; no, go to next
|
||||
|
||||
jmp short ??later
|
||||
|
||||
??set_as_current:
|
||||
mov al,1
|
||||
stosb
|
||||
cmp dl,0 ; are we before the A drive (invalid)
|
||||
jl short ??later ; yes, we are done checking
|
||||
|
||||
jmp ??next_drive ; keep processing
|
||||
|
||||
??later:
|
||||
cld
|
||||
ret
|
||||
|
||||
ENDP Init_Device_Table
|
||||
|
||||
;----------------------------------------------------------------------------
|
||||
|
||||
END
|
||||
|
238
WWFLAT32/FILE/FFIRST.ASM
Normal file
238
WWFLAT32/FILE/FFIRST.ASM
Normal file
@@ -0,0 +1,238 @@
|
||||
;
|
||||
; Command & Conquer Red Alert(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 **
|
||||
;***************************************************************************
|
||||
;* *
|
||||
;* Project Name : First First *
|
||||
;* *
|
||||
;* File Name : FFIRST.ASM *
|
||||
;* *
|
||||
;* Programmer : Jeff Wilson *
|
||||
;* *
|
||||
;* Start Date : March 28, 1994 *
|
||||
;* *
|
||||
;* Last Update : April 15, 1994 [] *
|
||||
;* *
|
||||
;*-------------------------------------------------------------------------*
|
||||
;* Functions: *
|
||||
;* Find_First -- Find a file spec *
|
||||
;* Find_Next -- Find next file in sreach params *
|
||||
;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
|
||||
|
||||
|
||||
|
||||
IDEAL
|
||||
P386
|
||||
MODEL USE32 FLAT
|
||||
|
||||
LOCALS ??
|
||||
|
||||
GLOBAL Find_First :NEAR
|
||||
GLOBAL Find_Next :NEAR
|
||||
|
||||
;============================================================================
|
||||
CODESEG
|
||||
|
||||
|
||||
;***************************************************************************
|
||||
;* FIND_FIRST -- Find a file spec *
|
||||
;* *
|
||||
;* *
|
||||
;* *
|
||||
;* INPUT: *
|
||||
;* file_name File spec to find. Maybe a wildcard name *
|
||||
;* mode File type *
|
||||
;* ffblk file data block ptr to write info into *
|
||||
;* *
|
||||
;* *
|
||||
;* OUTPUT: *
|
||||
;* *
|
||||
;* WARNINGS: *
|
||||
;* *
|
||||
;* HISTORY: *
|
||||
;* 04/15/1994 jaw: Created. *
|
||||
;*=========================================================================*
|
||||
|
||||
PROC Find_First C near
|
||||
USES ebx,ecx,edx,esi,edi,es,ds
|
||||
ARG file_name:DWORD,mode:WORD,ffblk:DWORD
|
||||
|
||||
mov edx,[file_name]
|
||||
mov cx,[mode]
|
||||
|
||||
mov eax,4e00h ;first firstg function
|
||||
|
||||
int 21h
|
||||
;Find it?
|
||||
jnc ??found_it ;=>yes
|
||||
|
||||
; ax holds the error code
|
||||
;insure high word of eax is clear
|
||||
or eax,0ffffffffh
|
||||
jmp ??exit
|
||||
|
||||
??found_it:
|
||||
; found something
|
||||
;copy the DTA into the user block
|
||||
mov eax,2f00h ;get DTA address
|
||||
int 21h
|
||||
|
||||
mov ax,es ;switch selectors
|
||||
mov dx,ds
|
||||
mov ds,ax
|
||||
mov es,dx
|
||||
|
||||
mov esi,ebx
|
||||
mov edi,[ffblk]
|
||||
|
||||
add esi,21 ;SKIP RESERVED
|
||||
add edi,4 ;SKIP RESERVED
|
||||
|
||||
sub eax,eax
|
||||
mov al,[esi] ;get attrib byte
|
||||
mov [es:edi+4],eax
|
||||
inc esi
|
||||
|
||||
;get time
|
||||
mov ax,[esi]
|
||||
add esi,2
|
||||
mov [es:edi+8],ax
|
||||
|
||||
;get date
|
||||
mov ax,[esi]
|
||||
add esi,2
|
||||
mov [es:edi+10],ax
|
||||
|
||||
;get file size
|
||||
mov eax,[esi]
|
||||
add esi,4
|
||||
mov [es:edi],eax
|
||||
|
||||
add edi,12
|
||||
|
||||
mov ecx,13
|
||||
|
||||
rep movsb ;copy the DTA name
|
||||
|
||||
mov ax,es
|
||||
mov ds,ax
|
||||
|
||||
xor eax,eax
|
||||
??exit:
|
||||
ret
|
||||
;====================
|
||||
ENDP Find_First
|
||||
|
||||
|
||||
|
||||
;***************************************************************************
|
||||
;* FIND_NEXT -- Find next file in sreach params *
|
||||
;* *
|
||||
;* *
|
||||
;* *
|
||||
;* INPUT: *
|
||||
;* NONE *
|
||||
;* OUTPUT: *
|
||||
;* *
|
||||
;* WARNINGS: *
|
||||
;* *
|
||||
;* HISTORY: *
|
||||
;* 04/15/1994 jaw: Created. *
|
||||
;*=========================================================================*
|
||||
|
||||
PROC Find_Next C near
|
||||
USES ebx,ecx,edx,esi,edi,ds,es
|
||||
|
||||
ARG ffblk:DWORD
|
||||
|
||||
mov eax,04f00h ;Find Next function
|
||||
|
||||
int 21h
|
||||
;Find anything?
|
||||
jnc ??found_it ;=>no
|
||||
|
||||
; ax holds the error code
|
||||
;insure high word of eax is clear
|
||||
or eax,0ffffffffh
|
||||
jmp ??exit
|
||||
|
||||
??found_it:
|
||||
; found something
|
||||
;copy the DTA into the user block
|
||||
mov eax,2f00h ;get DTA address
|
||||
int 21h
|
||||
|
||||
mov ax,es ;switch selectors
|
||||
mov dx,ds
|
||||
mov ds,ax
|
||||
mov es,dx
|
||||
|
||||
mov esi,ebx
|
||||
mov edi,[ffblk]
|
||||
|
||||
add esi,21 ;SKIP RESERVED
|
||||
add edi,4 ;SKIP RESERVED
|
||||
|
||||
sub eax,eax
|
||||
mov al,[esi] ;get attrib byte
|
||||
mov [es:edi+4],eax
|
||||
inc esi
|
||||
|
||||
;get time
|
||||
mov ax,[esi]
|
||||
add esi,2
|
||||
mov [es:edi+8],ax
|
||||
|
||||
;get date
|
||||
mov ax,[esi]
|
||||
add esi,2
|
||||
mov [es:edi+10],ax
|
||||
|
||||
;get file size
|
||||
mov eax,[esi]
|
||||
add esi,4
|
||||
mov [es:edi],eax
|
||||
|
||||
add edi,12
|
||||
|
||||
mov ecx,13
|
||||
|
||||
rep movsb ;copy the DTA name
|
||||
|
||||
mov ax,es
|
||||
mov ds,ax
|
||||
|
||||
xor eax,eax
|
||||
??exit:
|
||||
ret
|
||||
|
||||
ENDP Find_Next
|
||||
|
||||
|
||||
END
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
41
WWFLAT32/FILE/FGLOB2.CPP
Normal file
41
WWFLAT32/FILE/FGLOB2.CPP
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : FILEIO Library *
|
||||
* *
|
||||
* File Name : FILEGLOB.C *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : April 11, 1994 *
|
||||
* *
|
||||
* Last Update : April 11, 1994 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#include <wwstd.h>
|
||||
#include "_file.h"
|
||||
|
||||
/* Global varaiables */
|
||||
WORD Hard_Error_Occured=0;
|
261
WWFLAT32/FILE/FILE.BAK
Normal file
261
WWFLAT32/FILE/FILE.BAK
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Library - Filio header stuff. *
|
||||
* *
|
||||
* File Name : FILE.H *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : September 13, 1993 *
|
||||
* *
|
||||
* Last Update : April 11, 1994 *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef FILE_H
|
||||
#define FILE_H
|
||||
|
||||
|
||||
#ifndef ERROR
|
||||
#define ERROR -1
|
||||
#endif
|
||||
|
||||
#ifndef FILETEMP_H
|
||||
// This should be removed once the library is all intacked.
|
||||
#include "filetemp.h"
|
||||
#endif
|
||||
|
||||
/*=========================================================================*/
|
||||
/* File IO system defines and enumerations */
|
||||
/*=========================================================================*/
|
||||
|
||||
#define XMAXPATH 80
|
||||
|
||||
/*
|
||||
** These are the Open_File, Read_File, and Seek_File constants.
|
||||
*/
|
||||
#define READ 1 // Read access.
|
||||
#define WRITE 2 // Write access.
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0 // Seek from start of file.
|
||||
#define SEEK_CUR 1 // Seek relative from current location.
|
||||
#define SEEK_END 2 // Seek from end of file.
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum {
|
||||
FILEB_PROCESSED=8,// Was the packed file header of this file processed?
|
||||
FILEB_PRELOAD, // Scan for and make file resident at WWDOS_Init time?
|
||||
FILEB_RESIDENT, // Make resident at Open_File time?
|
||||
FILEB_FLUSH, // Un-resident at Close_File time?
|
||||
FILEB_PACKED, // Is this file packed?
|
||||
FILEB_KEEP, // Don't ever flush this resident file?
|
||||
FILEB_PRIORITY, // Flush this file last?
|
||||
|
||||
FILEB_LAST
|
||||
} FileFlags_Type;
|
||||
|
||||
#define FILEF_NONE 0
|
||||
#define FILEF_PROCESSED (1<<FILEB_PROCESSED)
|
||||
#define FILEF_PRELOAD (1<<FILEB_PRELOAD)
|
||||
#define FILEF_RESIDENT (1<<FILEB_RESIDENT)
|
||||
#define FILEF_FLUSH (1<<FILEB_FLUSH)
|
||||
#define FILEF_PACKED (1<<FILEB_PACKED)
|
||||
#define FILEF_KEEP (1<<FILEB_KEEP)
|
||||
#define FILEF_PRIORITY (1<<FILEB_PRIORITY)
|
||||
|
||||
/*
|
||||
** These errors are returned by WWDOS_Init(). All errors encountered are
|
||||
** or'd together so there may be more then one error returned. Not all
|
||||
** errors are fatal, such as the cache errors.
|
||||
*/
|
||||
typedef enum {
|
||||
FI_SUCCESS = 0x00,
|
||||
FI_CACHE_TOO_BIG = 0x01,
|
||||
FI_CACHE_ALREADY_INIT = 0x02,
|
||||
FI_FILEDATA_FILE_NOT_FOUND = 0x04,
|
||||
FI_FILEDATA_TOO_BIG = 0x08,
|
||||
FI_SEARCH_PATH_NOT_FOUND = 0x10,
|
||||
FI_STARTUP_PATH_NOT_FOUND = 0x20,
|
||||
FI_NO_CACHE_FOR_PRELOAD = 0x40,
|
||||
FI_FILETABLE_NOT_INIT = 0x80,
|
||||
} FileInitErrorType;
|
||||
|
||||
|
||||
/*
|
||||
** These are the errors that are detected by the File I/O system and
|
||||
** passed to the io error routine.
|
||||
*/
|
||||
//lint -strong(AJX,FileErrorType)
|
||||
typedef enum {
|
||||
CANT_CREATE_FILE,
|
||||
BAD_OPEN_MODE,
|
||||
COULD_NOT_OPEN,
|
||||
TOO_MANY_FILES,
|
||||
CLOSING_NON_HANDLE,
|
||||
READING_NON_HANDLE,
|
||||
WRITING_NON_HANDLE,
|
||||
SEEKING_NON_HANDLE,
|
||||
SEEKING_BAD_OFFSET,
|
||||
WRITING_RESIDENT,
|
||||
UNKNOWN_INDEX,
|
||||
DID_NOT_CLOSE,
|
||||
FATAL_ERROR,
|
||||
FILE_NOT_LISTED,
|
||||
FILE_LENGTH_MISMATCH,
|
||||
INTERNAL_ERROR,
|
||||
MAKE_RESIDENT_ZERO_SIZE,
|
||||
RESIDENT_SORT_FAILURE,
|
||||
|
||||
NUMBER_OF_ERRORS /* MAKE SURE THIS IS THE LAST ENTRY */
|
||||
} FileErrorType;
|
||||
|
||||
// This is here tempararaly until library is put together.
|
||||
//extern WORD cdecl (*cdecl IO_Error)(FileErrorType error, BYTE const *filename);
|
||||
extern short (*Open_Error)(FileErrorType, BYTE const *);
|
||||
|
||||
/*=========================================================================*/
|
||||
/* File IO system structures */
|
||||
/*=========================================================================*/
|
||||
|
||||
//lint -strong(AJX,FileDataType)
|
||||
typedef struct {
|
||||
char *Name; // File name (include sub-directory but not volume).
|
||||
long Size; // File size (0=indeterminate).
|
||||
void *Ptr; // Resident file pointer.
|
||||
long Start; // Starting offset in DOS handle file.
|
||||
unsigned char Disk; // Disk number location.
|
||||
unsigned char OpenCount; // Count of open locks on resident file.
|
||||
unsigned short Flag; // File control flags.
|
||||
} FileDataType;
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* FIle IO system globals. */
|
||||
/*=========================================================================*/
|
||||
|
||||
// These are cpp errors in funtions declarations JULIO JEREZ
|
||||
|
||||
// extern FileDataType cdecl FileData[];
|
||||
// extern BYTE cdecl ExecPath[XMAXPATH + 1];
|
||||
// extern BYTE cdecl DataPath[XMAXPATH + 1];
|
||||
// extern BYTE cdecl StartPath[XMAXPATH + 1];
|
||||
// extern BOOL cdecl UseCD;
|
||||
|
||||
// The correct syntax is NO TYPE MODIFIER APPLY TO DATA DECLARATIONS
|
||||
extern FileDataType FileData[];
|
||||
extern char ExecPath[XMAXPATH + 1];
|
||||
extern char DataPath[XMAXPATH + 1];
|
||||
extern char StartPath[XMAXPATH + 1];
|
||||
extern BOOL UseCD;
|
||||
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILEINIT.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
void cdecl WWDOS_Shutdown(void);
|
||||
FileInitErrorType cdecl WWDOS_Init(unsigned long cachesize, char *filedata, char *cdpath);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILE.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
int cdecl Open_File(char const *file_name, short mode);
|
||||
void cdecl Close_File(short handle);
|
||||
long cdecl Read_File(short handle, void *buf, unsigned long bytes);
|
||||
long cdecl Write_File(short handle, void const *buf, unsigned long bytes);
|
||||
unsigned long cdecl Seek_File(short handle, long offset, short starting);
|
||||
int cdecl File_Exists(char const *file_name);
|
||||
unsigned long cdecl File_Size(short handle);
|
||||
BOOL cdecl Is_Handle_Valid(short handle, FileErrorType error, char const *name);
|
||||
short cdecl Open_File_With_Recovery( char const *file_name, unsigned short mode );
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILECACH.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
void Unfragment_File_Cache(void);
|
||||
BOOL cdecl Make_File_Resident(char const *filename);
|
||||
short cdecl Flush_Unused_File_Cache(short flush_keeps);
|
||||
BOOL cdecl Free_Resident_File(char const *file);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILECHNG.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
short cdecl Create_File(char const *file_name);
|
||||
short cdecl Delete_File(char const *file_name);
|
||||
BOOL cdecl Change_File_Size(short handle, unsigned long new_size);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILEINFO.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
short cdecl Get_DOS_Handle(short fh);
|
||||
short cdecl Free_Handles(void);
|
||||
short cdecl Find_Disk_Number(char const *file_name);
|
||||
short cdecl Set_File_Flags(char const *filename, short flags);
|
||||
short cdecl Clear_File_Flags(char const *filename, short flags);
|
||||
short cdecl Get_File_Flags(char const *filename);
|
||||
BOOL cdecl Multi_Drive_Search(BOOL on);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FINDFILE.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
short cdecl Find_File(char const *file_name);
|
||||
short cdecl Find_File_Index(char const *filename);
|
||||
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FFIRST.ASM */
|
||||
/*=========================================================================*/
|
||||
|
||||
#include <dos.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern short Find_First(unsigned char *fname, unsigned short mode, struct find_t *ffblk);
|
||||
extern short Find_Next(struct find_t *ffblk);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // FILE_H
|
||||
|
1070
WWFLAT32/FILE/FILE.CPP
Normal file
1070
WWFLAT32/FILE/FILE.CPP
Normal file
File diff suppressed because it is too large
Load Diff
261
WWFLAT32/FILE/FILE.H
Normal file
261
WWFLAT32/FILE/FILE.H
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Library - Filio header stuff. *
|
||||
* *
|
||||
* File Name : FILE.H *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : September 13, 1993 *
|
||||
* *
|
||||
* Last Update : April 11, 1994 *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef FILE_H
|
||||
#define FILE_H
|
||||
|
||||
|
||||
#ifndef ERROR
|
||||
#define ERROR -1
|
||||
#endif
|
||||
|
||||
#ifndef FILETEMP_H
|
||||
// This should be removed once the library is all intacked.
|
||||
#include "filetemp.h"
|
||||
#endif
|
||||
|
||||
/*=========================================================================*/
|
||||
/* File IO system defines and enumerations */
|
||||
/*=========================================================================*/
|
||||
|
||||
#define XMAXPATH 80
|
||||
|
||||
/*
|
||||
** These are the Open_File, Read_File, and Seek_File constants.
|
||||
*/
|
||||
#define READ 1 // Read access.
|
||||
#define WRITE 2 // Write access.
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0 // Seek from start of file.
|
||||
#define SEEK_CUR 1 // Seek relative from current location.
|
||||
#define SEEK_END 2 // Seek from end of file.
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum {
|
||||
FILEB_PROCESSED=8,// Was the packed file header of this file processed?
|
||||
FILEB_PRELOAD, // Scan for and make file resident at WWDOS_Init time?
|
||||
FILEB_RESIDENT, // Make resident at Open_File time?
|
||||
FILEB_FLUSH, // Un-resident at Close_File time?
|
||||
FILEB_PACKED, // Is this file packed?
|
||||
FILEB_KEEP, // Don't ever flush this resident file?
|
||||
FILEB_PRIORITY, // Flush this file last?
|
||||
|
||||
FILEB_LAST
|
||||
} FileFlags_Type;
|
||||
|
||||
#define FILEF_NONE 0
|
||||
#define FILEF_PROCESSED (1<<FILEB_PROCESSED)
|
||||
#define FILEF_PRELOAD (1<<FILEB_PRELOAD)
|
||||
#define FILEF_RESIDENT (1<<FILEB_RESIDENT)
|
||||
#define FILEF_FLUSH (1<<FILEB_FLUSH)
|
||||
#define FILEF_PACKED (1<<FILEB_PACKED)
|
||||
#define FILEF_KEEP (1<<FILEB_KEEP)
|
||||
#define FILEF_PRIORITY (1<<FILEB_PRIORITY)
|
||||
|
||||
/*
|
||||
** These errors are returned by WWDOS_Init(). All errors encountered are
|
||||
** or'd together so there may be more then one error returned. Not all
|
||||
** errors are fatal, such as the cache errors.
|
||||
*/
|
||||
typedef enum {
|
||||
FI_SUCCESS = 0x00,
|
||||
FI_CACHE_TOO_BIG = 0x01,
|
||||
FI_CACHE_ALREADY_INIT = 0x02,
|
||||
FI_FILEDATA_FILE_NOT_FOUND = 0x04,
|
||||
FI_FILEDATA_TOO_BIG = 0x08,
|
||||
FI_SEARCH_PATH_NOT_FOUND = 0x10,
|
||||
FI_STARTUP_PATH_NOT_FOUND = 0x20,
|
||||
FI_NO_CACHE_FOR_PRELOAD = 0x40,
|
||||
FI_FILETABLE_NOT_INIT = 0x80,
|
||||
} FileInitErrorType;
|
||||
|
||||
|
||||
/*
|
||||
** These are the errors that are detected by the File I/O system and
|
||||
** passed to the io error routine.
|
||||
*/
|
||||
//lint -strong(AJX,FileErrorType)
|
||||
typedef enum {
|
||||
CANT_CREATE_FILE,
|
||||
BAD_OPEN_MODE,
|
||||
COULD_NOT_OPEN,
|
||||
TOO_MANY_FILES,
|
||||
CLOSING_NON_HANDLE,
|
||||
READING_NON_HANDLE,
|
||||
WRITING_NON_HANDLE,
|
||||
SEEKING_NON_HANDLE,
|
||||
SEEKING_BAD_OFFSET,
|
||||
WRITING_RESIDENT,
|
||||
UNKNOWN_INDEX,
|
||||
DID_NOT_CLOSE,
|
||||
FATAL_ERROR,
|
||||
FILE_NOT_LISTED,
|
||||
FILE_LENGTH_MISMATCH,
|
||||
INTERNAL_ERROR,
|
||||
MAKE_RESIDENT_ZERO_SIZE,
|
||||
RESIDENT_SORT_FAILURE,
|
||||
|
||||
NUMBER_OF_ERRORS /* MAKE SURE THIS IS THE LAST ENTRY */
|
||||
} FileErrorType;
|
||||
|
||||
// This is here tempararaly until library is put together.
|
||||
//extern WORD cdecl (*cdecl IO_Error)(FileErrorType error, BYTE const *filename);
|
||||
extern short (*Open_Error)(FileErrorType, BYTE const *);
|
||||
|
||||
/*=========================================================================*/
|
||||
/* File IO system structures */
|
||||
/*=========================================================================*/
|
||||
|
||||
//lint -strong(AJX,FileDataType)
|
||||
typedef struct {
|
||||
char *Name; // File name (include sub-directory but not volume).
|
||||
long Size; // File size (0=indeterminate).
|
||||
void *Ptr; // Resident file pointer.
|
||||
long Start; // Starting offset in DOS handle file.
|
||||
unsigned char Disk; // Disk number location.
|
||||
unsigned char OpenCount; // Count of open locks on resident file.
|
||||
unsigned short Flag; // File control flags.
|
||||
} FileDataType;
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* FIle IO system globals. */
|
||||
/*=========================================================================*/
|
||||
|
||||
// These are cpp errors in funtions declarations JULIO JEREZ
|
||||
|
||||
// extern FileDataType cdecl FileData[];
|
||||
// extern BYTE cdecl ExecPath[XMAXPATH + 1];
|
||||
// extern BYTE cdecl DataPath[XMAXPATH + 1];
|
||||
// extern BYTE cdecl StartPath[XMAXPATH + 1];
|
||||
// extern BOOL cdecl UseCD;
|
||||
|
||||
// The correct syntax is NO TYPE MODIFIER APPLY TO DATA DECLARATIONS
|
||||
extern FileDataType FileData[];
|
||||
extern char ExecPath[XMAXPATH + 1];
|
||||
extern char DataPath[XMAXPATH + 1];
|
||||
extern char StartPath[XMAXPATH + 1];
|
||||
extern BOOL UseCD;
|
||||
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILEINIT.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
void cdecl WWDOS_Shutdown(void);
|
||||
FileInitErrorType cdecl WWDOS_Init(unsigned long cachesize, char *filedata, char *cdpath);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILE.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
int cdecl Open_File(char const *file_name, int mode);
|
||||
void cdecl Close_File(int handle);
|
||||
long cdecl Read_File(int handle, void *buf, unsigned long bytes);
|
||||
long cdecl Write_File(int handle, void const *buf, unsigned long bytes);
|
||||
unsigned long cdecl Seek_File(int handle, long offset, int starting);
|
||||
int cdecl File_Exists(char const *file_name);
|
||||
unsigned long cdecl File_Size(int handle);
|
||||
BOOL cdecl Is_Handle_Valid(int handle, FileErrorType error, char const *name);
|
||||
int cdecl Open_File_With_Recovery( char const *file_name, unsigned int mode );
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILECACH.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
void Unfragment_File_Cache(void);
|
||||
BOOL cdecl Make_File_Resident(char const *filename);
|
||||
short cdecl Flush_Unused_File_Cache(short flush_keeps);
|
||||
BOOL cdecl Free_Resident_File(char const *file);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILECHNG.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
short cdecl Create_File(char const *file_name);
|
||||
short cdecl Delete_File(char const *file_name);
|
||||
BOOL cdecl Change_File_Size(short handle, unsigned long new_size);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILEINFO.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
short cdecl Get_DOS_Handle(short fh);
|
||||
short cdecl Free_Handles(void);
|
||||
short cdecl Find_Disk_Number(char const *file_name);
|
||||
short cdecl Set_File_Flags(char const *filename, short flags);
|
||||
short cdecl Clear_File_Flags(char const *filename, short flags);
|
||||
short cdecl Get_File_Flags(char const *filename);
|
||||
BOOL cdecl Multi_Drive_Search(BOOL on);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FINDFILE.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
int cdecl Find_File(char const *file_name);
|
||||
int cdecl Find_File_Index(char const *filename);
|
||||
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FFIRST.ASM */
|
||||
/*=========================================================================*/
|
||||
|
||||
#include <dos.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern short Find_First(unsigned char *fname, unsigned short mode, struct find_t *ffblk);
|
||||
extern short Find_Next(struct find_t *ffblk);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // FILE_H
|
||||
|
250
WWFLAT32/FILE/FILECACH.CPP
Normal file
250
WWFLAT32/FILE/FILECACH.CPP
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Library - File Caching routines *
|
||||
* *
|
||||
* File Name : FILECACH.CPP *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : September 13, 1993 *
|
||||
* *
|
||||
* Last Update : April 18, 1994 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* Make_File_Resident -- Makes a file resident even if not flaged so. *
|
||||
* Flush_Unused_File_Cache -- Flushes the file cache of any non opened fi*
|
||||
* Free_Resident_File -- Free the given file if it is resident. *
|
||||
* Unfragment_File_Cache -- Does a garbage collection on the file heap. *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#ifndef WWSTD_H
|
||||
#include <wwstd.h>
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
#ifndef WWMEM_H
|
||||
#include <wwmem.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* UNFRAGMENT_FILE_CACHE -- Does a garbage collection on the file heap. *
|
||||
* *
|
||||
* INPUT: NONE. *
|
||||
* *
|
||||
* OUTPUT: NONE. *
|
||||
* *
|
||||
* WARNINGS: Can be a lengthy process. *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 04/18/1994 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
VOID Unfragment_File_Cache(VOID)
|
||||
{
|
||||
FileDataType *filedata;
|
||||
FileDataType *parent;
|
||||
UWORD idx;
|
||||
|
||||
|
||||
// Let the memory system clean up the file heap.
|
||||
Mem_Cleanup(FileCacheHeap);
|
||||
|
||||
// Now get our pointers back.
|
||||
// Start after the parent PAK files since we will need to check our pointers
|
||||
// with them.
|
||||
filedata = &FileDataPtr[NumPAKFiles];
|
||||
for (idx = NumPAKFiles; idx < NumPAKFiles; idx++, filedata++) {
|
||||
while (filedata->Name) {
|
||||
|
||||
// Only process files that are in the file cache.
|
||||
if (filedata->Ptr) {
|
||||
|
||||
// Is a inner PAK file?
|
||||
if (filedata->Flag & FILEF_PACKED) {
|
||||
|
||||
parent = &FileDataPtr[filedata->Disk];
|
||||
|
||||
// Is it just a copied pointer of the parent?
|
||||
if (parent->Ptr == filedata->Ptr) {
|
||||
filedata->Ptr = Mem_Find(FileCacheHeap, filedata->Disk);
|
||||
}
|
||||
else
|
||||
filedata->Ptr = Mem_Find(FileCacheHeap, idx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
filedata->Ptr = Mem_Find(FileCacheHeap, idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now that the children have been taken care of, let us do the parents.
|
||||
for (filedata = FileDataPtr, idx = 0; idx < NumPAKFiles; idx++, filedata++) {
|
||||
|
||||
// Only process files that are in the file cache.
|
||||
if (filedata->Ptr) {
|
||||
filedata->Ptr = Mem_Find(FileCacheHeap, idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* MAKE_FILE_RESIDENT -- Makes a file resident even if not flaged so. *
|
||||
* *
|
||||
* INPUT: BYTE *filename - name of file to be made resident. *
|
||||
* *
|
||||
* OUTPUT: BOOL if successful. could fail in not enouph RAM or not found. *
|
||||
* *
|
||||
* WARNINGS: File must be in FileData table. *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 09/13/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
BOOL Make_File_Resident(BYTE const *filename)
|
||||
{
|
||||
FileDataType *filedata; // Pointer to the current FileData.
|
||||
FileDataType hold; // Hold buffer for record (DO NOT ACCESS DIRECTLY)
|
||||
WORD fileindex;
|
||||
WORD oldflag;
|
||||
WORD handle;
|
||||
|
||||
fileindex = Find_File_Index(filename);
|
||||
|
||||
// if the file is not in the table, we can't make it resident
|
||||
if (fileindex == ERROR) return(FALSE);
|
||||
|
||||
// Get a pointer for quicker pointer action.
|
||||
filedata = &FileDataPtr[fileindex];
|
||||
|
||||
// Change the flags for a moment.
|
||||
oldflag = filedata->Flag;
|
||||
filedata->Flag |= FILEF_RESIDENT;
|
||||
filedata->Flag &= ~FILEF_FLUSH;
|
||||
|
||||
// Make the file resident.
|
||||
handle = Open_File(filename, READ);
|
||||
Close_File(handle);
|
||||
|
||||
// Set flags back to normal.
|
||||
filedata->Flag = oldflag;
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* Flush_Unused_File_Cache -- Flushes the file cache of any non opened files. *
|
||||
* *
|
||||
* INPUT: WORD flush_keep - TRUE to flush even files marked FILEF_KEEP.*
|
||||
* *
|
||||
* OUTPUT: WORD Number of file flushed. *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 02/23/1993 SB : Created. *
|
||||
*=========================================================================*/
|
||||
WORD Flush_Unused_File_Cache(WORD flush_keeps)
|
||||
{
|
||||
WORD index;
|
||||
WORD freed = 0;
|
||||
FileDataType *filedata = NULL;
|
||||
FileDataType hold; // Hold buffer for record (DO NOT ACCESS DIRECTLY)
|
||||
|
||||
// Loop throuph the file table looking for files that could be freed.
|
||||
index = 0;
|
||||
filedata = &FileDataPtr[index];;
|
||||
while (filedata->Name && strlen(filedata->Name)) {
|
||||
|
||||
if (filedata->Ptr && !filedata->OpenCount &&
|
||||
(flush_keeps || !(filedata->Flag & FILEF_KEEP)) ) {
|
||||
|
||||
Mem_Free(FileCacheHeap, filedata->Ptr);
|
||||
filedata->Ptr = NULL;
|
||||
freed++;
|
||||
}
|
||||
index++;
|
||||
filedata = &FileDataPtr[index];;
|
||||
}
|
||||
return (freed);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* FREE_RESIDENT_FILE -- Free the given file if it is resident. *
|
||||
* *
|
||||
* INPUT: BYTE *file to free *
|
||||
* *
|
||||
* OUTPUT: TRUE if file was free'd, FALSE otherwise *
|
||||
* *
|
||||
* WARNINGS: none *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 07/22/1992 CY : Created. *
|
||||
*=========================================================================*/
|
||||
BOOL cdecl Free_Resident_File(BYTE const *file)
|
||||
{
|
||||
WORD fileindex;
|
||||
BOOL oldflag; // Previous file flag.
|
||||
FileDataType *filedata; // Pointer to the current FileData.
|
||||
FileDataType hold; // Hold buffer for record (DO NOT ACCESS DIRECTLY)
|
||||
|
||||
|
||||
// if the file is not in the table, we can't free it
|
||||
if ((fileindex = Find_File_Index(file)) == ERROR) {
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
// get a pointer for quicker calculations.
|
||||
filedata = &FileDataPtr[fileindex];
|
||||
|
||||
// If it isn't resident, don't try to Free it
|
||||
if (filedata->Ptr == NULL) {
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
// Change the flags for a moment.
|
||||
oldflag = filedata->Flag;
|
||||
filedata->Flag &= ~(FILEF_RESIDENT|FILEF_KEEP);
|
||||
filedata->Flag |= FILEF_FLUSH;
|
||||
|
||||
// Get the file out of Memory if it was there.
|
||||
Close_File(Open_File(file, READ));
|
||||
|
||||
// Set flags back to original.
|
||||
filedata->Flag = oldflag;
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
154
WWFLAT32/FILE/FILECHNG.CPP
Normal file
154
WWFLAT32/FILE/FILECHNG.CPP
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Library - File functions. *
|
||||
* *
|
||||
* File Name : FILECHNG.CPP *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : September 13, 1993 *
|
||||
* *
|
||||
* Last Update : September 13, 1993 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* Delete_File -- Deletes the file from the disk. *
|
||||
* Create_File -- Creates an empty file on disk. *
|
||||
* Change_File_Size -- Change the size of a writting file. *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#ifndef WWSTD_H
|
||||
#include "wwstd.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
#ifndef WWMEM_H
|
||||
#include <wwmem.h>
|
||||
#endif
|
||||
|
||||
#include <io.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
/***************************************************************************
|
||||
* CREATE_FILE -- Creates an empty file on disk. *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* INPUT: *
|
||||
* *
|
||||
* OUTPUT: *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 05/24/1992 JLB : Created. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Create_File(BYTE const *file_name)
|
||||
{
|
||||
WORD fd;
|
||||
|
||||
if (!file_name) return(FALSE);
|
||||
|
||||
fd = Open_File(file_name, WRITE);
|
||||
if (fd != ERROR) {
|
||||
Close_File(fd);
|
||||
return(TRUE);
|
||||
}
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* DELETE_FILE -- Deletes the file from the disk. *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* INPUT: *
|
||||
* *
|
||||
* OUTPUT: *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 05/24/1992 JLB : Created. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Delete_File(BYTE const *file_name)
|
||||
{
|
||||
WORD index;
|
||||
FileDataType *filedata; // Pointer to the current FileData.
|
||||
FileDataType hold; // Hold buffer for record (DO NOT ACCESS DIRECTLY)
|
||||
|
||||
if (!file_name) return(FALSE);
|
||||
|
||||
CallingDOSInt++;
|
||||
|
||||
ibm_setdisk(*StartPath - 'A');
|
||||
|
||||
index = Find_File_Index(file_name);
|
||||
filedata = &FileDataPtr[index];
|
||||
|
||||
if (index != ERROR && filedata->Ptr) {
|
||||
Mem_Free(FileCacheHeap, filedata->Ptr);
|
||||
filedata->Ptr = NULL;
|
||||
}
|
||||
|
||||
index = !FILEDELETE(file_name);
|
||||
CallingDOSInt--;
|
||||
return(index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* CHANGE_FILE_SIZE -- Change the size of a writting file. *
|
||||
* *
|
||||
* INPUT: WORD handle - handle of file. *
|
||||
* ULONG new_size - size of new handle. *
|
||||
* *
|
||||
* OUTPUT: *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 09/13/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
BOOL cdecl Change_File_Size(WORD handle, ULONG new_size)
|
||||
{
|
||||
WORD entry;
|
||||
|
||||
if (Is_Handle_Valid(handle, WRITING_NON_HANDLE, NULL)) {
|
||||
entry = Get_DOS_Handle(handle);
|
||||
if (entry != ERROR) {
|
||||
return(chsize(entry, new_size) != ERROR);
|
||||
}
|
||||
}
|
||||
return(FALSE);
|
||||
}
|
72
WWFLAT32/FILE/FILEDATA.CPP
Normal file
72
WWFLAT32/FILE/FILEDATA.CPP
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : File IO System LIbrary *
|
||||
* *
|
||||
* File Name : FILEDATA.CPP *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : April 11, 1994 *
|
||||
* *
|
||||
* Last Update : April 11, 1994 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef WWSTD_H
|
||||
#include "wwstd.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
|
||||
/*
|
||||
structure for FileDataType is:
|
||||
|
||||
BYTE *filename: initialize to actual file name on disk.
|
||||
LONG size: initialize to actual file size on disk.
|
||||
BYTE *ptr: initialize to a 0L below.
|
||||
WORD disk: which floppy disk number (1+) file resides on.
|
||||
LONG pos: initialize to a 0L below.
|
||||
UBYTE priority: file priorities can be from 0 to 127. (127 = highest)
|
||||
if you want the file to be attempted to be made
|
||||
resident at runtime, add 128 to the file priority
|
||||
to set the high bit. even though the files
|
||||
priority will appear to be 128 to 255, it will
|
||||
still remain 0 to 127.
|
||||
*/
|
||||
|
||||
FileDataType FileData[] = {
|
||||
{ "", 0L, 0L, 0, 0L, 0 }
|
||||
/* Must have an empty entry!!! */
|
||||
};
|
74
WWFLAT32/FILE/FILEGLOB.CPP
Normal file
74
WWFLAT32/FILE/FILEGLOB.CPP
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : FILEIO Library *
|
||||
* *
|
||||
* File Name : FILEGLOB.C *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : April 11, 1994 *
|
||||
* *
|
||||
* Last Update : April 11, 1994 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef WWSTD_H
|
||||
#include <wwstd.h>
|
||||
#endif
|
||||
|
||||
#ifndef FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
#include <process.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
|
||||
/* Global varaiables */
|
||||
BYTE ExecPath[XMAXPATH + 1];
|
||||
BYTE DataPath[XMAXPATH + 1];
|
||||
BYTE StartPath[XMAXPATH + 1];
|
||||
BOOL UseCD;
|
||||
|
||||
/* File System only Global varaiables */
|
||||
BYTE CallingDOSInt; // Indicate we are performing a DOS function
|
||||
BYTE MaxDevice,DefaultDrive;
|
||||
BYTE MultiDriveSearch = TRUE; // Multiple drive search flag
|
||||
FileDataType *FileDataPtr = NULL;
|
||||
FileHandleType FileHandleTable[TABLE_MAX];
|
||||
UWORD NumFiles; // Number of files, except PAK, in file table.
|
||||
UWORD NumPAKFiles; // Number of PAK files in filetable.
|
||||
VOID *FileCacheHeap = NULL; // Pointer to the cache in memory.
|
||||
WORD DiskNumber; // Where file was found (-1 == current directory).
|
||||
WORD MaxDirNum = 0;
|
||||
|
||||
|
||||
WORD (*Open_Error)(FileErrorType, BYTE const *) = NULL;
|
276
WWFLAT32/FILE/FILEINFO.CPP
Normal file
276
WWFLAT32/FILE/FILEINFO.CPP
Normal file
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Library - Fileio information functions. *
|
||||
* *
|
||||
* File Name : FILE.CPP *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : September 13, 1993 *
|
||||
* *
|
||||
* Last Update : April 19, 1994 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* Get_DOS_Handle -- Fetches system specific DOS file handle. *
|
||||
* Find_Disk_Number -- Determine disk a file resides upon. *
|
||||
* Set_File_Flags -- Sets flags for file if FileData table. *
|
||||
* Get_File_Flags -- Gets the flags on a file in the FileData table. *
|
||||
* Free_Handles -- Returns number of free file handles in WW system. *
|
||||
* Multi_Drive_Search -- Turns Multi search drive on and off. *
|
||||
* Clear_File_Flags -- Clears flags specified for file. *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#ifndef WWSTD_H
|
||||
#include "wwstd.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* GET_DOS_HANDLE -- Fetches system specific DOS file handle. *
|
||||
* *
|
||||
* This routine will return with the system specific DOS file handle. *
|
||||
* On the IBM, this is a WORD, on the Amiga, it is a LONG (BPTR). Use *
|
||||
* this routine with caution, because the value returned is NOT *
|
||||
* portable. *
|
||||
* *
|
||||
* INPUT: fh -- Westwood file system handle. *
|
||||
* *
|
||||
* OUTPUT: Returns with the system DOS file handle (WORD or LONG). *
|
||||
* *
|
||||
* WARNINGS: If you pass in an invalid file handle, or a file handle *
|
||||
* that references a resident file, then the ERROR code is *
|
||||
* returned. Be SURE to check for this. *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 08/21/1991 JLB : Created. *
|
||||
* 11/09/1991 JLB : Checks for illegal file handle passed in. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Get_DOS_Handle(WORD fh)
|
||||
{
|
||||
/*
|
||||
** If an illegal file handle is passed in then always abort.
|
||||
*/
|
||||
if (fh >= 0 && fh < TABLE_MAX) {
|
||||
if (!FileHandleTable[fh].Empty || FileHandleTable[fh].Handle) {
|
||||
return(FileHandleTable[fh].Handle);
|
||||
}
|
||||
|
||||
/*
|
||||
** If it falls through here, then the file must be resident. It is
|
||||
** illegal to get a DOS handle to a resident file.
|
||||
*/
|
||||
}
|
||||
return(FILEOPENERROR);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* FREE_HANDLES -- Returns number of free file handles in WW system. *
|
||||
* *
|
||||
* INPUT: NONE. *
|
||||
* *
|
||||
* OUTPUT: NONE. *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 09/13/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Free_Handles(VOID)
|
||||
{
|
||||
WORD count; // Count of the number of free file handles.
|
||||
WORD index; // Working file handle index var.
|
||||
|
||||
count = 0;
|
||||
for (index = 0; index < TABLE_MAX; index++) {
|
||||
if (FileHandleTable[index].Empty) count++;
|
||||
}
|
||||
return(count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* FIND_DISK_NUMBER -- Determine disk a file resides upon. *
|
||||
* *
|
||||
* This routine will determine the disk number that the specified *
|
||||
* file resides upon. It determines this by scanning through the *
|
||||
* FileData table. If the specified file is a packed file, then it *
|
||||
* will reference the parent packed file to determine the disk number. *
|
||||
* *
|
||||
* INPUT: file_name -- Pointer to the file name to check. *
|
||||
* *
|
||||
* OUTPUT: Returns with the disk number that the file resides upon. If *
|
||||
* ERROR is returned, then the file does not exist in the *
|
||||
* FileTable. The number returned is 0=A, 1=B, etc. *
|
||||
* *
|
||||
* WARNINGS: none *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 11/22/1991 JLB : Created. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Find_Disk_Number(BYTE const *file_name)
|
||||
{
|
||||
FileDataType *filedata; // Pointer to the current FileData.
|
||||
WORD index; // FileTable index.
|
||||
|
||||
index = Find_File_Index(file_name);
|
||||
|
||||
if (index != ERROR) {
|
||||
|
||||
filedata = &FileDataPtr[index];
|
||||
|
||||
if (filedata->Flag & FILEF_PACKED) {
|
||||
return (Find_Disk_Number(FileDataPtr[filedata->Disk].Name));
|
||||
}
|
||||
return(filedata->Disk);
|
||||
}
|
||||
return (index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* SET_FILE_FLAGS -- Sets flags for file if FileData table. *
|
||||
* *
|
||||
* INPUT: BYTE *filename - file to modify. *
|
||||
* WORD flags - flags to set in file. *
|
||||
* *
|
||||
* OUTPUT: WORD - if file found in FileData table. *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 10/04/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Set_File_Flags(BYTE const *filename, WORD flags)
|
||||
{
|
||||
FileDataType *filedata; // Pointer to the current FileData.
|
||||
WORD index; // FileTable index.
|
||||
|
||||
index = Find_File_Index(filename);
|
||||
|
||||
if (index != ERROR) {
|
||||
filedata = &FileDataPtr[index];
|
||||
filedata->Flag |= flags;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* CLEAR_FILE_FLAGS -- Clears flags specified for file. *
|
||||
* *
|
||||
* INPUT: BYTE *filename - file to modify. *
|
||||
* WORD flags - flags to set in file. *
|
||||
* *
|
||||
* OUTPUT: WORD - if file found in FileData table. *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 04/19/1994 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Clear_File_Flags(BYTE const *filename, WORD flags)
|
||||
{
|
||||
FileDataType *filedata; // Pointer to the current FileData.
|
||||
WORD index; // FileTable index.
|
||||
|
||||
index = Find_File_Index(filename);
|
||||
|
||||
if (index != ERROR) {
|
||||
filedata = &FileDataPtr[index];
|
||||
filedata->Flag &= ~flags;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* GET_FILE_FLAGS -- Gets the flags on a file in the FileData table. *
|
||||
* *
|
||||
* *
|
||||
* INPUT: BYTE *filename - file to modify. *
|
||||
* *
|
||||
* OUTPUT: *
|
||||
* *
|
||||
* OUTPUT: WORD - if file found in FileData table. *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 10/04/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Get_File_Flags(BYTE const *filename)
|
||||
{
|
||||
FileDataType *filedata; // Pointer to the current FileData.
|
||||
WORD index; // FileTable index.
|
||||
|
||||
index = Find_File_Index(filename);
|
||||
|
||||
if (index != ERROR) {
|
||||
filedata = &FileDataPtr[index];
|
||||
return (filedata->Flag);
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* MULTI_DRIVE_SEARCH -- Turns Multi search drive on and off. *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* INPUT: *
|
||||
* *
|
||||
* OUTPUT: *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 09/13/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
BOOL cdecl Multi_Drive_Search(BOOL on)
|
||||
{
|
||||
BOOL old;
|
||||
|
||||
Hard_Error_Occured = 0;
|
||||
old = MultiDriveSearch;
|
||||
MultiDriveSearch = on;
|
||||
return(old);
|
||||
}
|
511
WWFLAT32/FILE/FILEINIT.CPP
Normal file
511
WWFLAT32/FILE/FILEINIT.CPP
Normal file
@@ -0,0 +1,511 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Library - Fileio init routines. *
|
||||
* *
|
||||
* File Name : FILEINIT.C *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : September 13, 1993 *
|
||||
* *
|
||||
* Last Update : April 19, 1994 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* WWDOS_Init -- Initialize the fileio WWS fileio system. *
|
||||
* WWDOS_Shutdown -- Clean up any things that needs to be to exit game. *
|
||||
* Init_FileData_Table -- Initializes or reads in FileData Table. *
|
||||
* Sort_FileData_Table -- Sorts the FileData table that is in memory. *
|
||||
* Preload_Files -- Loads files marked with FILEF_PRELOAD into cache. *
|
||||
* Init_File_Cache -- Initializes and allocs the file cache heap. *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#ifndef WWSTD_H
|
||||
#include "wwstd.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
#ifndef WWMEM_H
|
||||
#include <wwmem.h>
|
||||
#endif
|
||||
|
||||
#ifndef MISC_H
|
||||
#include <misc.h>
|
||||
#endif
|
||||
|
||||
#include <direct.h>
|
||||
#include <search.h>
|
||||
#include <string.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
PRIVATE FileInitErrorType cdecl Init_File_Cache(ULONG cachesize);
|
||||
PRIVATE FileInitErrorType cdecl Init_FileData_Table(BYTE const *filename);
|
||||
PRIVATE FileInitErrorType cdecl Set_Search_Drives( BYTE *cdpath );
|
||||
PRIVATE FileInitErrorType cdecl Preload_Files(VOID);
|
||||
PRIVATE int QSort_Comp_Func(const void *p1, const void *p2);
|
||||
PRIVATE VOID Sort_FileData_Table(VOID);
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* WWDOS_INIT -- Initialize the fileio WWS fileio system. *
|
||||
* *
|
||||
* *
|
||||
* INPUT: ULONG cachesize - size wanted for the cache. *
|
||||
* BYTE *filedat - NULL or name of filedata table file. *
|
||||
* BYTE *cdpath - NULL or secondary search path on a CD. *
|
||||
* *
|
||||
* OUTPUT: Returns all errors encountered or'd together. *
|
||||
* *
|
||||
* WARNINGS: User should call the WWDOS_Init function for all file *
|
||||
* initialization. *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 04/19/1994 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
FileInitErrorType cdecl WWDOS_Init(ULONG cachesize, BYTE *filedata, BYTE *cdpath)
|
||||
{
|
||||
// FileInitErrorType errors;
|
||||
unsigned errors ;
|
||||
|
||||
// This has not been completed yet, when it is, uncomment it and add errors.
|
||||
Install_Hard_Error_Handler () ;
|
||||
Get_Devices();
|
||||
|
||||
if (cachesize) {
|
||||
errors = Init_File_Cache(cachesize);
|
||||
} else {
|
||||
errors = FI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
errors = errors | Init_FileData_Table(filedata);
|
||||
|
||||
errors = errors | Set_Search_Drives(cdpath);
|
||||
|
||||
errors = errors | Preload_Files();
|
||||
|
||||
|
||||
return ( FileInitErrorType ) errors ;
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* WWDOS_SHUTDOWN -- Clean up any things that needs to be in file syste to *
|
||||
* exit game. *
|
||||
* One could shut down the file system and open it back *
|
||||
* up with a different size cache or filetable. *
|
||||
* *
|
||||
* INPUT: NONE. *
|
||||
* *
|
||||
* OUTPUT: NONE. *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 04/19/1994 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
VOID cdecl WWDOS_Shutdown(VOID)
|
||||
{
|
||||
FileDataType *filedata; // Pointer to the current FileData.
|
||||
WORD file_handle;
|
||||
FileHandleType *filehandletable; // Pointer to the current file handle.
|
||||
|
||||
// Close all open files.
|
||||
filehandletable = FileHandleTable;
|
||||
for (file_handle = 0; file_handle < TABLE_MAX; file_handle++, filehandletable++) {
|
||||
if (!filehandletable->Empty) {
|
||||
Close_File(file_handle);
|
||||
}
|
||||
}
|
||||
|
||||
// Free the file cache heap.
|
||||
if (FileCacheHeap) {
|
||||
|
||||
// Get a pointer to the current filedata.
|
||||
if (FileDataPtr) {
|
||||
filedata = FileDataPtr;
|
||||
} else {
|
||||
filedata = FileData;
|
||||
}
|
||||
|
||||
while(filedata->Name && filedata->Name[0]) {
|
||||
filedata->Ptr = NULL;
|
||||
filedata++;
|
||||
}
|
||||
|
||||
Free(FileCacheHeap);
|
||||
FileCacheHeap = NULL;
|
||||
}
|
||||
|
||||
// Free up the file data.
|
||||
if (FileDataPtr != FileData) {
|
||||
Free(FileDataPtr);
|
||||
}
|
||||
FileDataPtr = NULL;
|
||||
|
||||
chdir(StartPath);
|
||||
ibm_setdisk(*StartPath - 'A');
|
||||
|
||||
// This has not been completed yet, when it is, uncomment it and add errors.
|
||||
Remove_Hard_Error_Handler();
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* INIT_FILE_CACHE -- Initializes and allocs the file cache heap. *
|
||||
* *
|
||||
* INPUT: ULONG cachesize - size of heap cache.. *
|
||||
* *
|
||||
* OUTPUT: FileInitErrorType error code. *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 04/19/1994 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
PRIVATE FileInitErrorType cdecl Init_File_Cache(ULONG cachesize)
|
||||
{
|
||||
// Allocate and initialize the file cache heap.
|
||||
if (FileCacheHeap) {
|
||||
return (FI_CACHE_ALREADY_INIT);
|
||||
}
|
||||
|
||||
if ((Ram_Free(MEM_NORMAL) >= cachesize)) {
|
||||
FileCacheHeap = Alloc(cachesize, MEM_NORMAL);
|
||||
Mem_Init(FileCacheHeap, cachesize);
|
||||
}
|
||||
|
||||
if (!FileCacheHeap) {
|
||||
return (FI_CACHE_TOO_BIG);
|
||||
}
|
||||
|
||||
return (FI_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* INIT_FILEDATA_TABLE -- Initializes or reads in FileData Table. *
|
||||
* *
|
||||
* INPUT: *
|
||||
* *
|
||||
* OUTPUT: FileInitErrorType error code. *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 09/13/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
PRIVATE FileInitErrorType cdecl Init_FileData_Table(BYTE const *filename)
|
||||
{
|
||||
WORD fd;
|
||||
ULONG fsize;
|
||||
FileDataType *ptr;
|
||||
WORD index;
|
||||
BYTE fname[13];
|
||||
|
||||
/*
|
||||
** Inialize the file handle table to reflect no files open.
|
||||
*/
|
||||
for (index = 0; index < TABLE_MAX; index++) {
|
||||
FileHandleTable[index].Empty = TRUE;
|
||||
}
|
||||
|
||||
// Set up our FileData ptr to be the initial FileData table.
|
||||
FileDataPtr = FileData;
|
||||
|
||||
// Sort the filedata table.
|
||||
// This needs to be done even if we load it off disk since the initial file data
|
||||
// table might contain a filename.
|
||||
Sort_FileData_Table();
|
||||
|
||||
// If there is a file name, then the filedata table will be loaded from disk.
|
||||
if (filename) {
|
||||
if (!Find_File(filename)) {
|
||||
return (FI_FILEDATA_FILE_NOT_FOUND);
|
||||
}
|
||||
fd = Open_File(filename, READ);
|
||||
|
||||
fsize = File_Size(fd);
|
||||
|
||||
if ((Ram_Free(MEM_NORMAL) < fsize)) {
|
||||
Close_File(fd);
|
||||
return (FI_FILEDATA_TOO_BIG);
|
||||
}
|
||||
|
||||
// Allocate some system memory.
|
||||
// Setup the new FileDataPtr and this time.
|
||||
FileDataPtr = ptr = (FileDataType *) Alloc(fsize, MEM_NORMAL);
|
||||
|
||||
// Load the file up into memory.
|
||||
Read_File(fd, FileDataPtr, fsize);
|
||||
Close_File(fd);
|
||||
|
||||
// Process the filetable. The filenames need their pointers adjusted.
|
||||
// At this time we will also count the number of files and number of PAK files.
|
||||
NumPAKFiles = NumFiles = 0;
|
||||
|
||||
// Make sure that the file name will have a NUL at the end.
|
||||
fname[12] = 0;
|
||||
while(TRUE) {
|
||||
// Have we reached the end of the list?
|
||||
if (!ptr->Name) break;
|
||||
|
||||
// Adjust the name pointer to point the the correct area.
|
||||
ptr->Name = (BYTE *)FileDataPtr + (LONG) ptr->Name;
|
||||
|
||||
// Count up weather it is a PAK file or a normal file.
|
||||
if (!NumFiles && strstr((char *) ptr->Name, (char *) ".PAK")) {
|
||||
NumPAKFiles++;
|
||||
|
||||
// Mark that it has been processed so that Open_File() will not do it.
|
||||
ptr->Flag |= FILEF_PROCESSED;
|
||||
|
||||
} else {
|
||||
NumFiles++;
|
||||
}
|
||||
|
||||
// Next record.
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
return (FI_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* Set_Search_Drives -- Sets up the CDRom and HardDrive paths. *
|
||||
* *
|
||||
* INPUT: BYTE *cdpath - path of data files on a CD. *
|
||||
* Should pass in NULL for non CD products. *
|
||||
* *
|
||||
* OUTPUT: FileInitErrorType error code. *
|
||||
* Varibable defined: *
|
||||
* ExecPath = Full path of EXE file. *
|
||||
* StartPath = Directory user started in. *
|
||||
* DataPath = secondary search path (typically CD-ROM). *
|
||||
* Note: format of paths is "C:\PATH" *
|
||||
* *
|
||||
* WARNINGS: The cdpath may be overiden by a "-CD<path>" command line *
|
||||
* arguement that specifies another drive (HARD or CD) and path *
|
||||
* where the data resides. Whenever a file is opened, it checks *
|
||||
* the startup drive first, then the CD search path if the first *
|
||||
* search was unsuccessful. *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 01/14/1993 SB : Created. *
|
||||
* 04/19/1994 SKB : Mods for 32 bit library. *
|
||||
*=========================================================================*/
|
||||
PRIVATE FileInitErrorType cdecl Set_Search_Drives( BYTE *cdpath )
|
||||
{
|
||||
BYTE *ptr;
|
||||
|
||||
|
||||
#if LIB_EXTERNS_RESOLVED
|
||||
// NOTE: THIS IS WRONG, THIS IS NOT THE WAY TO GET THE EXE's PATH.
|
||||
// Locate the executable.
|
||||
strcpy(ExecPath, _argv[0]);
|
||||
|
||||
// Find the very last '\' on the path.
|
||||
ptr = strrchr((char *) ExecPath, (int) '\\');
|
||||
#else
|
||||
ptr = NULL;
|
||||
#endif
|
||||
|
||||
// Remove the exe name to just have the path.
|
||||
if (ptr == NULL) {
|
||||
*ExecPath = 0;
|
||||
}
|
||||
else {
|
||||
*ptr = 0;
|
||||
}
|
||||
|
||||
// Did the user specify a second path?
|
||||
ptr = Find_Argv("-CD");
|
||||
|
||||
// If so, set the data path to that.
|
||||
if (ptr) {
|
||||
strcpy(DataPath, ptr + 3);
|
||||
}
|
||||
// Otherwise check to see if there is a CD-Rom drive.
|
||||
else {
|
||||
if (cdpath && *cdpath) {
|
||||
|
||||
#if LIB_EXTERNS_RESOLVED
|
||||
UseCD = GetCDDrive();
|
||||
#else
|
||||
UseCD = FALSE;
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
UseCD = FALSE;
|
||||
}
|
||||
|
||||
// If so, set the Drive to it and find out if any directories.
|
||||
if ( UseCD ) {
|
||||
strcpy( DataPath, "A:" );
|
||||
strcat( DataPath, cdpath);
|
||||
*DataPath = 'A'+UseCD;
|
||||
}
|
||||
// If not, set the Data path to the execacutable path.
|
||||
else {
|
||||
strcpy(DataPath, ExecPath);
|
||||
}
|
||||
}
|
||||
|
||||
// Finnally, set the starting path.
|
||||
getcwd(StartPath, XMAXPATH);
|
||||
|
||||
// Make sure they are all uppercase.
|
||||
strupr(StartPath);
|
||||
strupr(DataPath);
|
||||
strupr(ExecPath);
|
||||
|
||||
// Change directories to the secondary search path (DataPath).
|
||||
if (*DataPath && chdir(DataPath)) {
|
||||
return (FI_SEARCH_PATH_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Lastley, Make sure we are in the startup directory. This will overide
|
||||
// the secondary data path if they are on the same drive.
|
||||
if (chdir(StartPath)) {
|
||||
return (FI_STARTUP_PATH_NOT_FOUND);
|
||||
}
|
||||
|
||||
return (FI_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* PRELOAD_FILES -- Loads files marked with FILEF_PRELOAD into cache. *
|
||||
* *
|
||||
* *
|
||||
* INPUT: none. *
|
||||
* *
|
||||
* OUTPUT: FileInitErrorType error code. *
|
||||
* *
|
||||
* WARNINGS: The FileData must be initialized and the file heap initialized*
|
||||
* in order for this to work. *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 04/19/1994 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
PRIVATE FileInitErrorType cdecl Preload_Files(VOID)
|
||||
{
|
||||
FileDataType *filedata; // Working file data table pointer.
|
||||
BOOL oldflag; // Previous file flag.
|
||||
|
||||
if (!FileDataPtr) {
|
||||
return (FI_FILETABLE_NOT_INIT);
|
||||
}
|
||||
|
||||
if (!FileCacheHeap) {
|
||||
return (FI_NO_CACHE_FOR_PRELOAD);
|
||||
}
|
||||
|
||||
/*
|
||||
** Make all files flagged to be made resident at startup, resident.
|
||||
*/
|
||||
filedata = FileDataPtr;
|
||||
|
||||
while (filedata->Name && strlen(filedata->Name)) {
|
||||
if (filedata->Flag & FILEF_PRELOAD) {
|
||||
|
||||
oldflag = filedata->Flag;
|
||||
filedata->Flag |= FILEF_RESIDENT; // Make it resident.
|
||||
filedata->Flag &= ~FILEF_FLUSH; // Don't purge on Close_File.
|
||||
|
||||
Close_File(Open_File(filedata->Name, READ));
|
||||
|
||||
filedata->Flag &= ~(FILEF_RESIDENT|FILEF_FLUSH); // Clear bits.
|
||||
filedata->Flag |= oldflag & (FILEF_RESIDENT|FILEF_FLUSH); // Restore bits.
|
||||
|
||||
}
|
||||
filedata++;
|
||||
}
|
||||
return (FI_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* SORT_FILEDATA_TABLE -- Sorts the FileData table that is in memory. *
|
||||
* *
|
||||
* INPUT: NONE *
|
||||
* *
|
||||
* OUTPUT: NONE. *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 09/13/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
|
||||
PRIVATE int QSort_Comp_Func(const void *p1, const void *p2)
|
||||
{
|
||||
return(strcmp(((FileDataType*)p1)->Name, ((FileDataType*)p2)->Name));
|
||||
}
|
||||
PRIVATE VOID Sort_FileData_Table(VOID)
|
||||
{
|
||||
/*
|
||||
** Sort the filetable it but keep the pack file indexes correct.
|
||||
*/
|
||||
|
||||
/*
|
||||
** The number of pak files in the file table.
|
||||
*/
|
||||
NumPAKFiles = 0;
|
||||
strupr(FileData[NumPAKFiles].Name);
|
||||
while (strstr((char *) FileData[NumPAKFiles].Name, (char *) ".PAK")) {
|
||||
strupr(FileData[NumPAKFiles].Name);
|
||||
NumPAKFiles++;
|
||||
}
|
||||
|
||||
/*
|
||||
** Count the remaining files within the file table.
|
||||
*/
|
||||
NumFiles = 0;
|
||||
while(FileData[NumFiles+NumPAKFiles].Name && FileData[NumFiles+NumPAKFiles].Name[0]) {
|
||||
strupr(FileData[NumFiles+NumPAKFiles].Name);
|
||||
NumFiles++;
|
||||
}
|
||||
|
||||
/*
|
||||
** Sort the file entries (past the pak files).
|
||||
*/
|
||||
if (NumFiles) {
|
||||
qsort(&FileData[NumPAKFiles], NumFiles, sizeof(FileDataType), QSort_Comp_Func);
|
||||
}
|
||||
}
|
||||
|
151
WWFLAT32/FILE/FILEIO.CPP
Normal file
151
WWFLAT32/FILE/FILEIO.CPP
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Westwood Library *
|
||||
* *
|
||||
* File Name : FILEIO.C *
|
||||
* *
|
||||
* Programmer : Joe L. Bostic *
|
||||
* *
|
||||
* Start Date : August 21, 1991 *
|
||||
* *
|
||||
* Last Update : September 13, 1993 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef WWSTD_H
|
||||
#include "wwstd.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
#include <dos.h>
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
|
||||
WORD ibm_getdisk(VOID)
|
||||
{
|
||||
unsigned disk;
|
||||
|
||||
CallingDOSInt++;
|
||||
// disk = getdisk();
|
||||
_dos_getdrive ( & disk ) ;
|
||||
CallingDOSInt--;
|
||||
return(disk-1);
|
||||
}
|
||||
|
||||
WORD ibm_setdisk(WORD drive)
|
||||
{
|
||||
// WORD disk;
|
||||
unsigned disk ;
|
||||
|
||||
CallingDOSInt++;
|
||||
// disk = setdisk(drive);
|
||||
_dos_setdrive ( drive+1 , & disk ) ;
|
||||
CallingDOSInt--;
|
||||
return(disk);
|
||||
}
|
||||
|
||||
WORD ibm_close(WORD handle)
|
||||
{
|
||||
WORD success;
|
||||
|
||||
CallingDOSInt++;
|
||||
success = close(handle);
|
||||
CallingDOSInt--;
|
||||
return(success);
|
||||
}
|
||||
|
||||
WORD ibm_unlink(BYTE const *name)
|
||||
{
|
||||
WORD success;
|
||||
|
||||
CallingDOSInt++;
|
||||
success = unlink(name);
|
||||
CallingDOSInt--;
|
||||
return(success);
|
||||
}
|
||||
|
||||
LONG ibm_lseek(WORD handle, LONG offset, WORD where)
|
||||
{
|
||||
LONG new_offset;
|
||||
|
||||
CallingDOSInt++;
|
||||
new_offset = lseek(handle, offset, where);
|
||||
CallingDOSInt--;
|
||||
return(new_offset);
|
||||
}
|
||||
|
||||
UWORD ibm_read(WORD handle, VOID *ptr, UWORD bytes)
|
||||
{
|
||||
UWORD bytes_read;
|
||||
|
||||
CallingDOSInt++;
|
||||
bytes_read = read(handle, ptr, bytes);
|
||||
CallingDOSInt--;
|
||||
return(bytes_read);
|
||||
}
|
||||
|
||||
UWORD ibm_write(WORD handle, VOID *ptr, UWORD bytes)
|
||||
{
|
||||
UWORD bytes_written;
|
||||
|
||||
CallingDOSInt++;
|
||||
bytes_written = write(handle, ptr, bytes);
|
||||
CallingDOSInt--;
|
||||
return(bytes_written);
|
||||
}
|
||||
|
||||
WORD ibm_open(BYTE const *name, UWORD mode, WORD attrib)
|
||||
{
|
||||
WORD handle;
|
||||
|
||||
CallingDOSInt++;
|
||||
handle = open(name, mode, attrib);
|
||||
CallingDOSInt--;
|
||||
return(handle);
|
||||
}
|
||||
|
||||
WORD ibm_chdir(BYTE const *path)
|
||||
{
|
||||
WORD retval;
|
||||
|
||||
CallingDOSInt++;
|
||||
retval = chdir(path);
|
||||
CallingDOSInt--;
|
||||
return(retval);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
388
WWFLAT32/FILE/FILELIB.CPP
Normal file
388
WWFLAT32/FILE/FILELIB.CPP
Normal file
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : FILEIO Library support routines. *
|
||||
* *
|
||||
* File Name : FILELIB.C *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : April 11, 1994 *
|
||||
* *
|
||||
* Last Update : April 11, 1994 [SKB] *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Notes: This file contains private functions to the fileio system. *
|
||||
* While these functions may be used by any module in the fileio *
|
||||
* system, they cannot be used by a user program. For this reason *
|
||||
* they are put into this module. *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* Cache_File -- Attempts to cache file in XMS if flags set. *
|
||||
* Do_IO_Error -- Performs a non-recoverable error message display. *
|
||||
* Do_Open_Error -- Does an error message that could return. *
|
||||
* Is_Handle_Valid -- Determines validity of the specified file handle. *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef WWSTD_H
|
||||
#include "wwstd.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
#ifndef WWMEM_H
|
||||
#include <wwmem.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <process.h>
|
||||
#include <sys\stat.h>
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* DO_ERROR -- Does an error message that could return. *
|
||||
* *
|
||||
* This routine displays a file error message and unless the player *
|
||||
* presses <ESC>, it will return. If the player presses <ESC>, then *
|
||||
* it will terminate the program. *
|
||||
* *
|
||||
* INPUT: error -- Error message number. *
|
||||
* *
|
||||
* filename -- File name that the error occured on. *
|
||||
* *
|
||||
* OUTPUT: TRUE/FALSE; Should the process be repeated? *
|
||||
* *
|
||||
* WARNINGS: none *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 11/09/1991 JLB : Created. *
|
||||
*=========================================================================*/
|
||||
#pragma argsused
|
||||
WORD cdecl Do_Open_Error(FileErrorType errormsgnum, BYTE const *file_name)
|
||||
{
|
||||
BYTE *ptr=NULL; // Working file name pointer (just name and extension).
|
||||
|
||||
/*
|
||||
** Since the file name may include a path, we must extract the true
|
||||
** file name from the given string.
|
||||
*/
|
||||
if (file_name) {
|
||||
#if LIB_EXTERNS_RESOLVED
|
||||
ptr = strrchr((char *) file_name, (int) '\\');
|
||||
#else
|
||||
ptr = NULL;
|
||||
#endif
|
||||
if (ptr) {
|
||||
ptr++;
|
||||
} else {
|
||||
ptr = (BYTE *) file_name;
|
||||
}
|
||||
}
|
||||
|
||||
#if LIB_EXTERNS_RESOLVED
|
||||
strupr(ptr);
|
||||
return (IO_Error(errormsgnum, ptr));
|
||||
#else
|
||||
return(0);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* DO_IO_ERROR -- Performs a non-recoverable error message display. *
|
||||
* *
|
||||
* This routine will perform a non-recoverable file error message *
|
||||
* display. It is called when an error is detected that has no *
|
||||
* recovery or retry process defined. *
|
||||
* *
|
||||
* INPUT: errornum -- Error number detected. *
|
||||
* *
|
||||
* filename -- Name of the file that caused the error. *
|
||||
* *
|
||||
* OUTPUT: none *
|
||||
* *
|
||||
* WARNINGS: none *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 11/09/1991 JLB : Created. *
|
||||
*=========================================================================*/
|
||||
#pragma argsused
|
||||
VOID cdecl Do_IO_Error(FileErrorType errormsgnum, BYTE const *filename)
|
||||
{
|
||||
#if LIB_EXTERNS_RESOLVED
|
||||
(VOID)IO_Error(errormsgnum, filename);
|
||||
#endif
|
||||
#if(TRUE)
|
||||
Prog_End();
|
||||
exit((int)errormsgnum);
|
||||
#else
|
||||
Program_End();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* Read_File_With_Recovery -- read the same file on another directory if an error *
|
||||
* occurs. *
|
||||
* *
|
||||
* *
|
||||
* INPUT: *
|
||||
* *
|
||||
* OUTPUT: *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 02/16/1993 QY : Created. *
|
||||
*=========================================================================*/
|
||||
LONG cdecl Read_File_With_Recovery( WORD handle, VOID *buf, UWORD bytes )
|
||||
{
|
||||
WORD newhandle;
|
||||
LONG bytes_read;
|
||||
|
||||
do {
|
||||
Hard_Error_Occured = 0;
|
||||
|
||||
// Make sure we are in the right path.
|
||||
CHANGEDIR( DataPath );
|
||||
|
||||
// open the same file
|
||||
newhandle = Open_File( FileHandleTable[ handle ].Name, FileHandleTable[ handle ].Mode );
|
||||
Seek_File( newhandle, FileHandleTable[ handle ].Pos, SEEK_SET );
|
||||
|
||||
// dos close the old file
|
||||
FILECLOSE( FileHandleTable[ handle ].Handle );
|
||||
|
||||
// copy FileHandleTable[ newhandle ] to FileHandleTable[ handle ]
|
||||
Mem_Copy( &FileHandleTable[ newhandle ], &FileHandleTable[ handle ],
|
||||
( ULONG ) sizeof( FileHandleTable[ newhandle ] ) );
|
||||
|
||||
// delete FileHandleTable[newhandle]
|
||||
|
||||
FileHandleTable[ newhandle ].Empty = TRUE;
|
||||
|
||||
// continue reading file
|
||||
bytes_read = ( LONG ) FILEREAD( FileHandleTable[ handle ].Handle, buf, bytes );
|
||||
|
||||
// if still error, do it again; else return the number of bytes read
|
||||
if ( !Hard_Error_Occured ) {
|
||||
return( bytes_read );
|
||||
}
|
||||
if (!Do_Open_Error(COULD_NOT_OPEN, FileHandleTable[ handle ].Name)) {
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
} while (CHANGEDIR( DataPath ));
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
* Open_File_With_Recovery -- open the same file on another directory *
|
||||
* *
|
||||
* *
|
||||
* *
|
||||
* INPUT: *
|
||||
* *
|
||||
* OUTPUT: *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 02/16/1993 QY : Created. *
|
||||
*=========================================================================*/
|
||||
WORD cdecl Open_File_With_Recovery( BYTE const *file_name, UWORD mode )
|
||||
{
|
||||
WORD handle;
|
||||
|
||||
Hard_Error_Occured = FALSE;
|
||||
handle = FILEOPEN(file_name, mode);
|
||||
|
||||
// Do not return if there was a HardError and Using a CD and we are looking at
|
||||
// the CD.
|
||||
if (!Hard_Error_Occured || !UseCD || (ibm_getdisk() != (*DataPath - 'A'))) {
|
||||
return (handle);
|
||||
}
|
||||
|
||||
#if DEBUGPRINT
|
||||
Mono_Print(file_name); Mono_Print(":OPENERROR ");
|
||||
#endif
|
||||
|
||||
Hard_Error_Occured = 0;
|
||||
|
||||
// It is possible that the CD has been poped out and put back in, let us
|
||||
// change there and then try again.
|
||||
ibm_setdisk(*DataPath - 'A');
|
||||
CHANGEDIR( DataPath );
|
||||
|
||||
// open the same file
|
||||
handle = FILEOPEN( file_name, mode );
|
||||
|
||||
// if still error, do it again; else return the dos handle
|
||||
if ( !Hard_Error_Occured ) {
|
||||
return( handle );
|
||||
}
|
||||
|
||||
Hard_Error_Occured = 0;
|
||||
return (FILEOPENERROR);
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* CACHE_FILE -- Attempts to cache file in XMS if flags set. *
|
||||
* *
|
||||
* *
|
||||
* INPUT: WORD index - the index of the file in the FileData table. *
|
||||
* WORD file_handle - WWS file handle of file. *
|
||||
* *
|
||||
* OUTPUT: BOOL : was it cached? *
|
||||
* *
|
||||
* WARNINGS: *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 06/21/1993 SKB : Created. *
|
||||
*=========================================================================*/
|
||||
BOOL cdecl Cache_File(WORD index, WORD file_handle)
|
||||
{
|
||||
LONG filesize; // Size of the memory block needed.
|
||||
LONG freecache; // Amount of free XMS.
|
||||
FileDataType *filedata = NULL;
|
||||
FileDataType hold;
|
||||
FileHandleType *filehandletable;
|
||||
WORD flag; // Type of system memory to cache file.
|
||||
WORD file;
|
||||
|
||||
// Only files in the file table can be cached.
|
||||
if (index == ERROR) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Setup our pointer to the file we may want to cache.
|
||||
filedata = &FileDataPtr[index];
|
||||
|
||||
// Should this be cached, and is it not yet cached?
|
||||
if ((filedata->Flag & (FILEF_RESIDENT|FILEF_PRELOAD)) && !filedata->Ptr) {
|
||||
|
||||
filesize = filedata->Size;
|
||||
|
||||
/*
|
||||
** If there is o room to cache the file, then turn off its cache file.
|
||||
*/
|
||||
if (filesize > Mem_Pool_Size(FileCacheHeap)) {
|
||||
|
||||
// Remove resident flags so that it will not keep trying to cache itself
|
||||
// since there will never be enough room for it.
|
||||
filedata->Flag &= ~(FILEF_PRELOAD|FILEF_KEEP|FILEF_RESIDENT|FILEF_FLUSH);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// Go through freeing files until there is enouph space in the
|
||||
// memory pool.
|
||||
while (filesize > Mem_Avail(FileCacheHeap)) {
|
||||
VOID *node;
|
||||
|
||||
// Get the oldest non used file pointer.
|
||||
node = Mem_Find_Oldest(FileCacheHeap);
|
||||
|
||||
// If non was found, sorry no room for the new file.
|
||||
if (!node) {
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
// Get a pointer to the structure for convenience.
|
||||
filedata = &FileDataPtr[Mem_Get_ID(node)];
|
||||
|
||||
// Free it from the heap and update the file system so it knows that
|
||||
// the file is no longer in memory.
|
||||
Mem_Free(FileCacheHeap, filedata->Ptr);
|
||||
filedata->Ptr = NULL;
|
||||
}
|
||||
|
||||
|
||||
// If there is not a big enough space we will have to take garbage
|
||||
// collection hit. (OUCH!!!!!!)
|
||||
if (filesize > Mem_Largest_Avail(FileCacheHeap)) {
|
||||
Unfragment_File_Cache();
|
||||
}
|
||||
|
||||
// Make sure we have a big enough space and if so, put the file into memory.
|
||||
if (filesize < Mem_Largest_Avail(FileCacheHeap)) {
|
||||
|
||||
// Get some pointers to save code space and time.
|
||||
filehandletable = &FileHandleTable[file_handle];
|
||||
filedata = &FileDataPtr[index];
|
||||
|
||||
// Alloc the buffer in our file cache, then read the file in.
|
||||
filedata->Ptr = Mem_Alloc(FileCacheHeap, filesize, index);
|
||||
|
||||
// Extra check - it should not fail.
|
||||
if (!filedata->Ptr) return(FALSE);
|
||||
|
||||
// Mark it so that it never comes back as Oldest used.
|
||||
Mem_In_Use(filedata->Ptr);
|
||||
|
||||
// Get the file into memory.
|
||||
Read_File(file_handle, filedata->Ptr, filesize);
|
||||
|
||||
// reset the read index from the above read.
|
||||
filehandletable->Pos = 0L;
|
||||
|
||||
// This makes caching inner pak file possible. No longer is the
|
||||
// PAK'd file based off the parent file.
|
||||
filehandletable->Start = 0;
|
||||
|
||||
// Close the parent file. Remove it's open count.
|
||||
if (filedata->Flag & FILEF_PACKED) {
|
||||
FileDataType p_hold;
|
||||
FileDataType *parent;
|
||||
|
||||
parent = &FileDataPtr[filedata->Disk];
|
||||
parent->OpenCount--;
|
||||
}
|
||||
FILECLOSE(filehandletable->Handle);
|
||||
filehandletable->Handle = 0;
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
// The file was not cached, let the caller know.
|
||||
return (FALSE);
|
||||
}
|
41
WWFLAT32/FILE/FILESTUB.CPP
Normal file
41
WWFLAT32/FILE/FILESTUB.CPP
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : wwlib32 *
|
||||
* *
|
||||
* File Name : FILESTUB.CPP *
|
||||
* *
|
||||
* Programmer : Bill Randolph *
|
||||
* *
|
||||
* Start Date : May 3, 1994 *
|
||||
* *
|
||||
* Last Update : May 3, 1994 [BR] *
|
||||
* *
|
||||
* This module is a temorary stub that contains IO_Error. *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
#include "wwstd.h"
|
||||
#include "file.h"
|
||||
|
||||
WORD Text_IO_Error(FileErrorType, BYTE const *){return FALSE;}
|
||||
WORD (*IO_Error)(FileErrorType, BYTE const *) = Text_IO_Error;
|
||||
|
||||
/************************* End of filestub.cpp *****************************/
|
60
WWFLAT32/FILE/FILETEMP.H
Normal file
60
WWFLAT32/FILE/FILETEMP.H
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Temp header for file routines. *
|
||||
* *
|
||||
* File Name : FILETEMP.H *
|
||||
* *
|
||||
* Programmer : Scott K. Bowen *
|
||||
* *
|
||||
* Start Date : April 20, 1994 *
|
||||
* *
|
||||
* Last Update : April 20, 1994 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef FILETEMP_H
|
||||
#define FILETEMP_H
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// THIS DOES NOT BELONG HERE. IT WAS PUT HERE JUST TO GET THE THING
|
||||
// TO COMPILE. ONCE THE BUFFER AND PAGE SYSTEMS ARE PUT IN, THESE
|
||||
// WILL NEED TO BE TAKEN OUT AND MODS MADE TO ANY FUNCTION USING BuffType.
|
||||
// SKB 4/20/94.
|
||||
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* Defines and such that must go into wwstd.h */
|
||||
/*=========================================================================*/
|
||||
// Look at FileErrorType below for the IO_Error function.
|
||||
//extern WORD cdecl (*cdecl IO_Error)(FileErrorType error, BYTE const *filename);
|
||||
VOID cdecl Prog_End(VOID);
|
||||
extern WORD Hard_Error_Occured;
|
||||
|
||||
|
||||
|
||||
//////////////////////// END OF DON'T BELONG //////////////////////////////////
|
||||
|
||||
#endif //FILETEMP_H
|
312
WWFLAT32/FILE/FINDFILE.BAK
Normal file
312
WWFLAT32/FILE/FINDFILE.BAK
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Westwood Library *
|
||||
* *
|
||||
* File Name : FINDFILE.C *
|
||||
* *
|
||||
* Programmer : Joe L. Bostic *
|
||||
* *
|
||||
* Start Date : August 21, 1991 *
|
||||
* *
|
||||
* Last Update : September 29, 1993 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* Find_File_Index -- Finds the FileTable index number for a given file. *
|
||||
* Find_File -- Checks if a file is immediatly available. *
|
||||
* Get_FileData -- Gets a pointer back to the correct file. *
|
||||
* Find_File -- Checks if a file is immediatly available. *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
#ifndef WWSTD_H
|
||||
#include "wwstd.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
#include <direct.h>
|
||||
#include <dos.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <search.h>
|
||||
#include <sys\stat.h>
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* FIND_FILE -- Checks if a file is immediatly available. *
|
||||
* *
|
||||
* Use this function to determine if a file is immediatly available. *
|
||||
* This routine will NOT request for the proper disk to be inserted *
|
||||
* if the file could not be found. Use File_Exists for that feature. *
|
||||
* The Westwood file I/O system does NOT have to be initialized as *
|
||||
* a prerequisit to using this function. *
|
||||
* *
|
||||
* INPUT: file_name -- Name of the file to check. *
|
||||
* *
|
||||
* OUTPUT: Returns the disk number that the file exits on (A=1, B=2, etc) *
|
||||
* *
|
||||
* WARNINGS: This sets the current drive to the drive that contains the *
|
||||
* specified file (if it is found). *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 11/14/1991 JLB : Created. *
|
||||
* 03/14/1992 JLB : Modified for Amiga compatability. *
|
||||
* 01/11/1993 SKB : Modified for CD-ROM searches. *
|
||||
*=========================================================================*/
|
||||
int cdecl Find_File(char const *file_name)
|
||||
{
|
||||
FileDataType *filedata = NULL;
|
||||
WORD index; // File index (if any).
|
||||
WORD disk; // Disk number of file (if in filetable).
|
||||
|
||||
/*
|
||||
** If the filename is invalid then it errors out as if the file wasn't
|
||||
** found (naturally).
|
||||
*/
|
||||
if (!file_name) return(FALSE);
|
||||
|
||||
/*
|
||||
** Determine if the file has a file table entry. If it does, then
|
||||
** special checks and processing must occur.
|
||||
** Also, if it is in memory, return with it.
|
||||
*/
|
||||
index = Find_File_Index(file_name);
|
||||
filedata = &FileDataPtr[index];
|
||||
|
||||
if (index != ERROR) {
|
||||
|
||||
// If the file is currently cached, return TRUE that it was found.
|
||||
if (filedata->Ptr) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Always check the current directory for the file. Only if it can't
|
||||
** be found are furthur measures required.
|
||||
*/
|
||||
DiskNumber = ERROR; // This indicates file exists in current directory.
|
||||
|
||||
|
||||
#if (LIB_CDROM)
|
||||
ibm_setdisk(*StartPath - 'A');
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Check the current directory by attempting to open with READ access.
|
||||
*/
|
||||
{
|
||||
WORD handle;
|
||||
|
||||
CallingDOSInt++;
|
||||
handle = open(file_name, O_RDONLY | O_BINARY, S_IREAD);
|
||||
CallingDOSInt--;
|
||||
if (handle != ERROR)
|
||||
{
|
||||
// WORD d;
|
||||
unsigned d ;
|
||||
|
||||
CallingDOSInt++;
|
||||
close(handle);
|
||||
// d = getdisk();
|
||||
_dos_getdrive ( & d) ;
|
||||
CallingDOSInt--;
|
||||
return(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (index != ERROR) {
|
||||
|
||||
disk = filedata->Disk;
|
||||
/*
|
||||
** If the file is in a packed file, then search for the packed file
|
||||
** instead of the specified one.
|
||||
*/
|
||||
if (index != ERROR && (filedata->Flag & FILEF_PACKED)) {
|
||||
filedata = &FileDataPtr[disk];
|
||||
return (Find_File(filedata->Name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
** It could not be found on the current drive, so search the other
|
||||
** drives if allowed to do so.
|
||||
*/
|
||||
if (!MultiDriveSearch) {
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
#if (LIB_CDROM)
|
||||
// If we were unable to find the file on the hard drive, change
|
||||
// drives to the CD rom drive and see if it is there.
|
||||
ibm_setdisk(*DataPath - 'A');
|
||||
|
||||
{
|
||||
WORD handle;
|
||||
|
||||
Hard_Error_Occured = 0;
|
||||
|
||||
handle = Open_File_With_Recovery( file_name, MODE_OLDFILE );
|
||||
|
||||
if (handle != FILEOPENERROR) {
|
||||
FILECLOSE(handle);
|
||||
return(ibm_getdisk() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
ibm_setdisk(*StartPath - 'A');
|
||||
return (FALSE);
|
||||
#else
|
||||
|
||||
{
|
||||
WORD start_drive; // Original current drive number.
|
||||
|
||||
/*
|
||||
** Record the current drive for restoring later in case of failure.
|
||||
*/
|
||||
CallingDOSInt++;
|
||||
start_drive = getdisk();
|
||||
CallingDOSInt--;
|
||||
|
||||
/*
|
||||
** Sweep backward from the last real drive to the first, looking for the
|
||||
** file on each in turn.
|
||||
*/
|
||||
for (index = MaxDevice; index != -1; index--) {
|
||||
if (Is_Device_Real(index)) {
|
||||
CallingDOSInt++;
|
||||
setdisk(index);
|
||||
CallingDOSInt--;
|
||||
|
||||
{
|
||||
WORD handle;
|
||||
|
||||
CallingDOSInt++;
|
||||
handle = open(file_name, O_RDONLY | O_BINARY, S_IREAD);
|
||||
CallingDOSInt--;
|
||||
if (handle != ERROR) {
|
||||
CallingDOSInt++;
|
||||
close(handle);
|
||||
CallingDOSInt--;
|
||||
DiskNumber = index+1;
|
||||
return (DiskNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CallingDOSInt++;
|
||||
setdisk(start_drive);
|
||||
CallingDOSInt--;
|
||||
}
|
||||
|
||||
return(FALSE);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* FIND_FILE_INDEX -- Finds the FileTable index number for a given file. *
|
||||
* *
|
||||
* This function searches the FileTable and returns with the index of *
|
||||
* the matching file. If the file doesn't exist in the table, then *
|
||||
* ERROR is returned. It does not care about case. *
|
||||
* *
|
||||
* INPUT: filename -- Pointer to the filename to check. *
|
||||
* *
|
||||
* OUTPUT: Returns with the index into the FileTable. If the file does *
|
||||
* not exist in the file table, then ERROR is returned. *
|
||||
* *
|
||||
* WARNINGS: none *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 11/09/1991 JLB : Created. *
|
||||
* 06/11/1993 JLB : Sorts and binary searches the file table. *
|
||||
*=========================================================================*/
|
||||
PRIVATE int Comp_Func(const void *p1, const void *p2)
|
||||
{
|
||||
return(strcmp((char *) ((FileDataType*)p1)->Name, (char *) ((FileDataType*)p2)->Name));
|
||||
}
|
||||
WORD cdecl Find_File_Index(BYTE const *filename)
|
||||
{
|
||||
FileDataType *filedata; // File entry pointer.
|
||||
FileDataType key; // Working file data type var.
|
||||
|
||||
/*
|
||||
** Perform a binary search on the presorted filetable.
|
||||
*/
|
||||
if (filename) {
|
||||
|
||||
filedata = NULL;
|
||||
key.Name = (BYTE *) strupr((char *)filename);
|
||||
if (strstr((char *)key.Name, (char *)".PAK")) {
|
||||
|
||||
/*
|
||||
** If the FileData table was not loaded from the disk then the PAK files are
|
||||
** not sorted so Perform a linear search for the pak files.
|
||||
** Otherwise the files are sorted so speed things up by doing a bsearch.
|
||||
*/
|
||||
if (FileData == FileDataPtr) {
|
||||
filedata = (FileDataType *) lfind(&key, FileDataPtr, (size_t *) &NumPAKFiles, sizeof(FileDataType), Comp_Func);
|
||||
}
|
||||
else {
|
||||
filedata = (FileDataType *)bsearch(&key, FileDataPtr, NumPAKFiles, sizeof(FileDataType), Comp_Func);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/*
|
||||
** Perform a binary search for the regular files.
|
||||
*/
|
||||
filedata = (FileDataType *)bsearch(&key, &FileDataPtr[NumPAKFiles], NumFiles, sizeof(FileDataType), Comp_Func);
|
||||
}
|
||||
|
||||
// Return the element in the array if file was found in table.
|
||||
if (filedata) {
|
||||
return (filedata - FileDataPtr);
|
||||
//return ((WORD)((((LONG)filedata) - ((LONG)FileDataPtr)) / sizeof(FileDataType)));
|
||||
}
|
||||
}
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
312
WWFLAT32/FILE/FINDFILE.CPP
Normal file
312
WWFLAT32/FILE/FINDFILE.CPP
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
***************************************************************************
|
||||
* *
|
||||
* Project Name : Westwood Library *
|
||||
* *
|
||||
* File Name : FINDFILE.C *
|
||||
* *
|
||||
* Programmer : Joe L. Bostic *
|
||||
* *
|
||||
* Start Date : August 21, 1991 *
|
||||
* *
|
||||
* Last Update : September 29, 1993 [SKB] *
|
||||
* *
|
||||
*-------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* Find_File_Index -- Finds the FileTable index number for a given file. *
|
||||
* Find_File -- Checks if a file is immediatly available. *
|
||||
* Get_FileData -- Gets a pointer back to the correct file. *
|
||||
* Find_File -- Checks if a file is immediatly available. *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following PRIVATE functions are in this file: */
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
|
||||
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
|
||||
|
||||
#ifndef WWSTD_H
|
||||
#include "wwstd.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#include "_file.h"
|
||||
#endif
|
||||
|
||||
#include <direct.h>
|
||||
#include <dos.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <search.h>
|
||||
#include <sys\stat.h>
|
||||
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* FIND_FILE -- Checks if a file is immediatly available. *
|
||||
* *
|
||||
* Use this function to determine if a file is immediatly available. *
|
||||
* This routine will NOT request for the proper disk to be inserted *
|
||||
* if the file could not be found. Use File_Exists for that feature. *
|
||||
* The Westwood file I/O system does NOT have to be initialized as *
|
||||
* a prerequisit to using this function. *
|
||||
* *
|
||||
* INPUT: file_name -- Name of the file to check. *
|
||||
* *
|
||||
* OUTPUT: Returns the disk number that the file exits on (A=1, B=2, etc) *
|
||||
* *
|
||||
* WARNINGS: This sets the current drive to the drive that contains the *
|
||||
* specified file (if it is found). *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 11/14/1991 JLB : Created. *
|
||||
* 03/14/1992 JLB : Modified for Amiga compatability. *
|
||||
* 01/11/1993 SKB : Modified for CD-ROM searches. *
|
||||
*=========================================================================*/
|
||||
int cdecl Find_File(char const *file_name)
|
||||
{
|
||||
FileDataType *filedata = NULL;
|
||||
WORD index; // File index (if any).
|
||||
WORD disk; // Disk number of file (if in filetable).
|
||||
|
||||
/*
|
||||
** If the filename is invalid then it errors out as if the file wasn't
|
||||
** found (naturally).
|
||||
*/
|
||||
if (!file_name) return(FALSE);
|
||||
|
||||
/*
|
||||
** Determine if the file has a file table entry. If it does, then
|
||||
** special checks and processing must occur.
|
||||
** Also, if it is in memory, return with it.
|
||||
*/
|
||||
index = Find_File_Index(file_name);
|
||||
filedata = &FileDataPtr[index];
|
||||
|
||||
if (index != ERROR) {
|
||||
|
||||
// If the file is currently cached, return TRUE that it was found.
|
||||
if (filedata->Ptr) {
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Always check the current directory for the file. Only if it can't
|
||||
** be found are furthur measures required.
|
||||
*/
|
||||
DiskNumber = ERROR; // This indicates file exists in current directory.
|
||||
|
||||
|
||||
#if (LIB_CDROM)
|
||||
ibm_setdisk(*StartPath - 'A');
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Check the current directory by attempting to open with READ access.
|
||||
*/
|
||||
{
|
||||
WORD handle;
|
||||
|
||||
CallingDOSInt++;
|
||||
handle = open(file_name, O_RDONLY | O_BINARY, S_IREAD);
|
||||
CallingDOSInt--;
|
||||
if (handle != ERROR)
|
||||
{
|
||||
// WORD d;
|
||||
unsigned d ;
|
||||
|
||||
CallingDOSInt++;
|
||||
close(handle);
|
||||
// d = getdisk();
|
||||
_dos_getdrive ( & d) ;
|
||||
CallingDOSInt--;
|
||||
return(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (index != ERROR) {
|
||||
|
||||
disk = filedata->Disk;
|
||||
/*
|
||||
** If the file is in a packed file, then search for the packed file
|
||||
** instead of the specified one.
|
||||
*/
|
||||
if (index != ERROR && (filedata->Flag & FILEF_PACKED)) {
|
||||
filedata = &FileDataPtr[disk];
|
||||
return (Find_File(filedata->Name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
** It could not be found on the current drive, so search the other
|
||||
** drives if allowed to do so.
|
||||
*/
|
||||
if (!MultiDriveSearch) {
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
#if (LIB_CDROM)
|
||||
// If we were unable to find the file on the hard drive, change
|
||||
// drives to the CD rom drive and see if it is there.
|
||||
ibm_setdisk(*DataPath - 'A');
|
||||
|
||||
{
|
||||
WORD handle;
|
||||
|
||||
Hard_Error_Occured = 0;
|
||||
|
||||
handle = Open_File_With_Recovery( file_name, MODE_OLDFILE );
|
||||
|
||||
if (handle != FILEOPENERROR) {
|
||||
FILECLOSE(handle);
|
||||
return(ibm_getdisk() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
ibm_setdisk(*StartPath - 'A');
|
||||
return (FALSE);
|
||||
#else
|
||||
|
||||
{
|
||||
WORD start_drive; // Original current drive number.
|
||||
|
||||
/*
|
||||
** Record the current drive for restoring later in case of failure.
|
||||
*/
|
||||
CallingDOSInt++;
|
||||
start_drive = getdisk();
|
||||
CallingDOSInt--;
|
||||
|
||||
/*
|
||||
** Sweep backward from the last real drive to the first, looking for the
|
||||
** file on each in turn.
|
||||
*/
|
||||
for (index = MaxDevice; index != -1; index--) {
|
||||
if (Is_Device_Real(index)) {
|
||||
CallingDOSInt++;
|
||||
setdisk(index);
|
||||
CallingDOSInt--;
|
||||
|
||||
{
|
||||
WORD handle;
|
||||
|
||||
CallingDOSInt++;
|
||||
handle = open(file_name, O_RDONLY | O_BINARY, S_IREAD);
|
||||
CallingDOSInt--;
|
||||
if (handle != ERROR) {
|
||||
CallingDOSInt++;
|
||||
close(handle);
|
||||
CallingDOSInt--;
|
||||
DiskNumber = index+1;
|
||||
return (DiskNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CallingDOSInt++;
|
||||
setdisk(start_drive);
|
||||
CallingDOSInt--;
|
||||
}
|
||||
|
||||
return(FALSE);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* FIND_FILE_INDEX -- Finds the FileTable index number for a given file. *
|
||||
* *
|
||||
* This function searches the FileTable and returns with the index of *
|
||||
* the matching file. If the file doesn't exist in the table, then *
|
||||
* ERROR is returned. It does not care about case. *
|
||||
* *
|
||||
* INPUT: filename -- Pointer to the filename to check. *
|
||||
* *
|
||||
* OUTPUT: Returns with the index into the FileTable. If the file does *
|
||||
* not exist in the file table, then ERROR is returned. *
|
||||
* *
|
||||
* WARNINGS: none *
|
||||
* *
|
||||
* HISTORY: *
|
||||
* 11/09/1991 JLB : Created. *
|
||||
* 06/11/1993 JLB : Sorts and binary searches the file table. *
|
||||
*=========================================================================*/
|
||||
PRIVATE int Comp_Func(const void *p1, const void *p2)
|
||||
{
|
||||
return(strcmp((char *) ((FileDataType*)p1)->Name, (char *) ((FileDataType*)p2)->Name));
|
||||
}
|
||||
int cdecl Find_File_Index(char const *filename)
|
||||
{
|
||||
FileDataType *filedata; // File entry pointer.
|
||||
FileDataType key; // Working file data type var.
|
||||
|
||||
/*
|
||||
** Perform a binary search on the presorted filetable.
|
||||
*/
|
||||
if (filename) {
|
||||
|
||||
filedata = NULL;
|
||||
key.Name = (BYTE *) strupr((char *)filename);
|
||||
if (strstr((char *)key.Name, (char *)".PAK")) {
|
||||
|
||||
/*
|
||||
** If the FileData table was not loaded from the disk then the PAK files are
|
||||
** not sorted so Perform a linear search for the pak files.
|
||||
** Otherwise the files are sorted so speed things up by doing a bsearch.
|
||||
*/
|
||||
if (FileData == FileDataPtr) {
|
||||
filedata = (FileDataType *) lfind(&key, FileDataPtr, (size_t *) &NumPAKFiles, sizeof(FileDataType), Comp_Func);
|
||||
}
|
||||
else {
|
||||
filedata = (FileDataType *)bsearch(&key, FileDataPtr, NumPAKFiles, sizeof(FileDataType), Comp_Func);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/*
|
||||
** Perform a binary search for the regular files.
|
||||
*/
|
||||
filedata = (FileDataType *)bsearch(&key, &FileDataPtr[NumPAKFiles], NumFiles, sizeof(FileDataType), Comp_Func);
|
||||
}
|
||||
|
||||
// Return the element in the array if file was found in table.
|
||||
if (filedata) {
|
||||
return (filedata - FileDataPtr);
|
||||
//return ((WORD)((((LONG)filedata) - ((LONG)FileDataPtr)) / sizeof(FileDataType)));
|
||||
}
|
||||
}
|
||||
return(ERROR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
216
WWFLAT32/FILE/HARDERR.ASM
Normal file
216
WWFLAT32/FILE/HARDERR.ASM
Normal file
@@ -0,0 +1,216 @@
|
||||
;
|
||||
; Command & Conquer Red Alert(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 **
|
||||
;***************************************************************************
|
||||
;* *
|
||||
;* Project Name : Hard/Critical Error Handler *
|
||||
;* *
|
||||
;* File Name : harderr.asm *
|
||||
;* *
|
||||
;* Programmer : Scott K. Bowen. *
|
||||
;* *
|
||||
;* Start Date : July 18, 1994 *
|
||||
;* *
|
||||
;* Last Update : July 26, 1994 [SKB] *
|
||||
;* *
|
||||
;*-------------------------------------------------------------------------*
|
||||
;* Functions: *
|
||||
;* Install_Hard_Error_Handler -- Setup for handling critical errors *
|
||||
;* Remove_Hard_Erroror_Handler -- Remove the critical error handler stuff*
|
||||
;* Critical_Error_Handler -- Catch critical error interrupt. *
|
||||
;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
|
||||
|
||||
|
||||
IDEAL
|
||||
P386
|
||||
MODEL USE32 FLAT
|
||||
|
||||
LOCALS ??
|
||||
|
||||
;INCLUDE "tntdos.inc"
|
||||
|
||||
|
||||
;//////////////////////////////////////////////////////////////////////////////////////
|
||||
;///////////////////////////////////// Equates ////////////////////////////////////////
|
||||
DOS_SYS_CALL EQU 21h ; to do TNT DOS-XNDR system calls.
|
||||
LOCK_PAGES EQU 5 ; Lock pages subfunction using DX_MEM_MGT
|
||||
UNLOCK_PAGES EQU 6 ; Unlock pages subfunction using DX_MEM_MGT
|
||||
CRITERR_INT_NUM EQU 24h
|
||||
|
||||
DISK_ERROR_BIT EQU 01000000000000000b ; bit 7 of dh.
|
||||
DISK_ERROR EQU 1 ; Value of Hard_Error_Occured if disk/floppy error.
|
||||
OTHER_ERROR EQU 2 ; Value of Hard_Error_Occured if other type of error.
|
||||
|
||||
;
|
||||
; Interrupt handler stack frame
|
||||
;
|
||||
_FLGS equ [DWORD PTR ebp+52] ; 386|DOS-Extender flags
|
||||
_GS equ [WORD PTR ebp+48] ; original GS
|
||||
_FS equ [WORD PTR ebp+44] ; original FS
|
||||
_DS equ [WORD PTR ebp+40] ; original DS
|
||||
_ES equ [WORD PTR ebp+36] ; original ES
|
||||
_SS equ [WORD PTR ebp+32] ; original SS
|
||||
_ESP equ [DWORD PTR ebp+28] ; original ESP
|
||||
_EFLAGS equ [DWORD PTR ebp+24] ; original EFLAGS
|
||||
_CS equ [DWORD PTR ebp+20] ; original CS
|
||||
_EIP equ [DWORD PTR ebp+16] ; original EIP
|
||||
_EBP equ [DWORD PTR ebp] ; original EBP
|
||||
|
||||
;
|
||||
; DOS critical error stack frame
|
||||
;
|
||||
_DOS_FLAGS equ [WORD PTR es:ebx+22] ; interrupt stack frame from real
|
||||
_DOS_CS equ [WORD PTR es:ebx+20] ; mode INT 21h
|
||||
_DOS_IP equ [WORD PTR es:ebx+18] ;
|
||||
_DOS_ES equ [WORD PTR es:ebx+16] ; regs at time INT 21h was issued
|
||||
_DOS_DS equ [WORD PTR es:ebx+14] ; in real mode
|
||||
_DOS_BP equ [WORD PTR es:ebx+12] ;
|
||||
_DOS_DI equ [WORD PTR es:ebx+10] ;
|
||||
_DOS_SI equ [WORD PTR es:ebx+8] ;
|
||||
_DOS_DX equ [WORD PTR es:ebx+6] ;
|
||||
_DOS_CX equ [WORD PTR es:ebx+4] ;
|
||||
_DOS_BX equ [WORD PTR es:ebx+2] ;
|
||||
_DOS_AX equ [WORD PTR es:ebx] ;
|
||||
|
||||
|
||||
;
|
||||
; Error codes put into Hard_Error_Code
|
||||
;
|
||||
DISK_WRITE_PROTECTED equ 00h
|
||||
UNKOWN_DEVICE equ 01h
|
||||
DRIVE_NOT_READY equ 02h
|
||||
UNKOWN_COMMAND equ 03h
|
||||
CRC_ERROR equ 04h
|
||||
WRONG_DATA_LENGTH equ 05h
|
||||
SEEK_ERROR equ 06h
|
||||
UNKOWN_DEVICE_TYPE equ 07h
|
||||
SECTOR_NOT_FOUND equ 08h
|
||||
OUT_OF_PAPER equ 09h
|
||||
WRITE_ERROR equ 0Ah
|
||||
READ_ERROR equ 0Bh
|
||||
GENERAL_ERROR equ 0Ch
|
||||
|
||||
;//////////////////////////////////////////////////////////////////////////////////////
|
||||
;/////////////////////////////////// Prototypes ///////////////////////////////////////
|
||||
|
||||
GLOBAL Install_Hard_Error_Handler :NEAR
|
||||
GLOBAL Remove_Hard_Error_Handler :NEAR
|
||||
|
||||
;//////////////////////////////////////////////////////////////////////////////////////
|
||||
;///////////////////////////////// Global/Local Data //////////////////////////////////
|
||||
|
||||
DATASEG
|
||||
|
||||
LABEL LockedDataStart BYTE
|
||||
Hard_Error_Occured DB 0 ; Hard disk error or other error.
|
||||
Hard_Error_Code DB 0 ; Error Code.
|
||||
LABEL LockedDataEnd BYTE
|
||||
|
||||
|
||||
OldRMI DD ? ; original real mode critical err vector
|
||||
OldPMIOffset DD ? ; original protected mode critical err vector
|
||||
OldPMISelector DD ? ; original PM crit error selector.
|
||||
|
||||
InitFlags DD 0 ; Flags to indicate what has been initialized.
|
||||
|
||||
; InitFlags that are set to have a fully functional interrupt.
|
||||
IF_SET_VECTORS equ 1 ; Vectors have been set.
|
||||
IF_LOCKED_PM_CODE equ 2 ; Locked PM code for DPMI.
|
||||
IF_LOCKED_PM_DATA equ 4 ; Locked PM data for DPMI.
|
||||
IF_FUNCTIONAL equ 8 ; crit error is in and functional.
|
||||
|
||||
|
||||
;//////////////////////////////////////////////////////////////////////////////////////
|
||||
;///////////////////////////////////// Code //////////////////////////////////////////
|
||||
|
||||
CODESEG
|
||||
|
||||
;***************************************************************************
|
||||
;* INSTALL_HARD_ERROR_HANDLER -- Setup for handling critical errors. *
|
||||
;* *
|
||||
;* *
|
||||
;* *
|
||||
;* INPUT: *
|
||||
;* *
|
||||
;* OUTPUT: *
|
||||
;* *
|
||||
;* WARNINGS: *
|
||||
;* *
|
||||
;* HISTORY: *
|
||||
;* 07/26/1994 SKB : Created. *
|
||||
;*=========================================================================*
|
||||
PROC Install_Hard_Error_Handler C near
|
||||
USES eax,ebx,ecx,ds,es
|
||||
ret
|
||||
|
||||
ENDP Install_Hard_Error_Handler
|
||||
|
||||
|
||||
;***************************************************************************
|
||||
;* REMOVE_HARD_ERROROR_HANDLER -- Remove the critical error handler stuff *
|
||||
;* *
|
||||
;* *
|
||||
;* *
|
||||
;* INPUT: *
|
||||
;* *
|
||||
;* OUTPUT: *
|
||||
;* *
|
||||
;* WARNINGS: *
|
||||
;* *
|
||||
;* HISTORY: *
|
||||
;* 07/26/1994 SKB : Created. *
|
||||
;*=========================================================================*
|
||||
|
||||
PROC Remove_Hard_Error_Handler C near
|
||||
USES ebx,ecx,edx,ds,es
|
||||
;
|
||||
; Restore the original interrupt vectors and exit
|
||||
;
|
||||
|
||||
ret
|
||||
|
||||
ENDP Remove_Hard_Error_Handler
|
||||
|
||||
|
||||
;***************************************************************************
|
||||
;* Critical_Error_Handler -- Catch critical error interrupt. *
|
||||
;* *
|
||||
;* *
|
||||
;* *
|
||||
;* INPUT: *
|
||||
;* *
|
||||
;* OUTPUT: *
|
||||
;* *
|
||||
;* WARNINGS: *
|
||||
;* *
|
||||
;* HISTORY: *
|
||||
;* 07/26/1994 SKB : Created. *
|
||||
;*=========================================================================*
|
||||
|
||||
LABEL LockedCodeStart BYTE
|
||||
|
||||
PROC Critical_Error_Handler NEAR
|
||||
|
||||
ENDP Critical_Error_Handler
|
||||
|
||||
LABEL LockedCodeEnd BYTE
|
||||
|
||||
END
|
||||
|
194
WWFLAT32/FILE/MAKEFILE
Normal file
194
WWFLAT32/FILE/MAKEFILE
Normal file
@@ -0,0 +1,194 @@
|
||||
#
|
||||
# Command & Conquer Red Alert(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 **
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Project Name : Westwood Library .LIB makefile *
|
||||
#* *
|
||||
#* File Name : MAKEFILE *
|
||||
#* *
|
||||
#* Programmer : Julio R. Jerez *
|
||||
#* *
|
||||
#* Start Date : Jan 26, 1995 *
|
||||
#* *
|
||||
#* *
|
||||
#*-------------------------------------------------------------------------*
|
||||
#* *
|
||||
#* Required environment variables: *
|
||||
#* WWFLAT = your root WWFLAT path *
|
||||
#* WWVCS = root directory for wwlib version control archive *
|
||||
#* WATCOM = your Watcom installation path *
|
||||
#* *
|
||||
#* Required changes to makefile: *
|
||||
#* PROJ_NAME = name of the library you're building *
|
||||
#* OBJECTS = list of objects in your library *
|
||||
#* *
|
||||
#* Optional changes to makefile: *
|
||||
#* PROJ_DIR = full pathname of your working directory *
|
||||
#* .path.xxx = full pathname where various file types live *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Verify user's environment
|
||||
#---------------------------------------------------------------------------
|
||||
!ifndef %WWFLAT
|
||||
!error WWFLAT Environment var not configured.
|
||||
!endif
|
||||
|
||||
|
||||
!ifndef %WWVCS
|
||||
!error WWVCS Environment var not configured.
|
||||
!endif
|
||||
|
||||
!ifndef %WATCOM
|
||||
!error WATCOM Environment var not configured.
|
||||
!endif
|
||||
|
||||
#===========================================================================
|
||||
# User-defined section: the user should tailor this section for each project
|
||||
#===========================================================================
|
||||
|
||||
PROJ_NAME = file
|
||||
PROJ_DIR = $(%WWFLAT)\$(PROJ_NAME)
|
||||
LIB_DIR = $(%WWFLAT)\lib
|
||||
|
||||
!include $(%WWFLAT)\project.cfg
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Project-dependent variables
|
||||
#---------------------------------------------------------------------------
|
||||
OBJECTS = &
|
||||
file.obj &
|
||||
filecach.obj &
|
||||
filechng.obj &
|
||||
filedata.obj &
|
||||
fileglob.obj &
|
||||
fglob2.obj &
|
||||
fileinfo.obj &
|
||||
fileinit.obj &
|
||||
fileio.obj &
|
||||
filelib.obj &
|
||||
filestub.obj &
|
||||
findfile.obj &
|
||||
devices.obj &
|
||||
devtable.obj &
|
||||
ffirst.obj &
|
||||
harderr.obj
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Path macros: one path for each file type.
|
||||
# These paths are used to tell make where to find/put each file type.
|
||||
#---------------------------------------------------------------------------
|
||||
.asm: $(PROJ_DIR)
|
||||
.c: $(PROJ_DIR)
|
||||
.cpp: $(PROJ_DIR)
|
||||
.h: $(PROJ_DIR)
|
||||
.obj: $(PROJ_DIR)
|
||||
.lib: $(WWLIB)\lib
|
||||
.exe: $(PROJ_DIR)
|
||||
|
||||
#===========================================================================
|
||||
# Pre-defined section: there should be little need to modify this section.
|
||||
#===========================================================================
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Tools/commands
|
||||
#---------------------------------------------------------------------------
|
||||
C_CMD = wcc386
|
||||
CPP_CMD = wpp386
|
||||
LIB_CMD = wlib
|
||||
LINK_CMD = wlink
|
||||
ASM_CMD = tasm32
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Include & library paths
|
||||
# If LIB & INCLUDE are already defined, they are used in addition to the
|
||||
# WWLIB32 lib & include; otherwise, they're constructed from
|
||||
# BCDIR & TNTDIR
|
||||
#---------------------------------------------------------------------------
|
||||
LIBPATH = $(%WWFLAT)\LIB;$(%WATCOM)\LIB
|
||||
INCLUDEPATH = $(%WWFLAT)\INCLUDE;$(%WATCOM)\H
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Implicit rules
|
||||
# Compiler:
|
||||
# ($< = full dependent with path)
|
||||
# Assembler:
|
||||
# output obj's are constructed from .obj: & the $& macro
|
||||
# ($< = full dependent with path)
|
||||
# tasm's cfg file is not invoked as a response file.
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
.c.obj: $(%WWFLAT)\project.cfg .AUTODEPEND
|
||||
$(C_CMD) $(CC_CFG) $<
|
||||
|
||||
.cpp.obj: $(%WWFLAT)\project.cfg .AUTODEPEND
|
||||
$(CPP_CMD) $(CC_CFG) $<
|
||||
|
||||
.asm.obj: $(%WWFLAT)\project.cfg
|
||||
$(ASM_CMD) $(ASM_CFG) $<
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Default target: configuration files & library (in that order)
|
||||
#---------------------------------------------------------------------------
|
||||
all: $(LIB_DIR)\$(PROJ_NAME).lib .SYMBOLIC
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Build the library
|
||||
# The original library is deleted by the librarian
|
||||
# Lib objects & -+ commands are constructed by substituting within the
|
||||
# $^@ macro (which expands to all target dependents, separated with
|
||||
# spaces)
|
||||
# Tlib's cfg file is not invoked as a response file.
|
||||
# All headers & source files are copied into WWFLAT\SRCDEBUG, for debugging
|
||||
#---------------------------------------------------------------------------
|
||||
$(LIB_DIR)\$(PROJ_NAME).lib: $(OBJECTS) objects.lbc
|
||||
copy *.h $(%WWFLAT)\include
|
||||
copy *.inc $(%WWFLAT)\include
|
||||
copy *.cpp $(%WWFLAT)\srcdebug
|
||||
copy *.asm $(%WWFLAT)\srcdebug
|
||||
$(LIB_CMD) $(LIB_CFG) $^@ @objects.lbc
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Objects now have a link file which is NOT generated everytime. Instead
|
||||
# it just has its own dependacy rule.
|
||||
#---------------------------------------------------------------------------
|
||||
objects.lbc : $(OBJECTS)
|
||||
%create $^@
|
||||
for %index in ($(OBJECTS)) do %append $^@ +%index
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Create the test directory and make it.
|
||||
#---------------------------------------------------------------------------
|
||||
test:
|
||||
mkdir test
|
||||
cd test
|
||||
copy $(%WWVCS)\$(PROJ_NAME)\test\vcs.cfg
|
||||
update
|
||||
wmake
|
||||
cd ..
|
||||
|
||||
#**************************** End of makefile ******************************
|
||||
|
183
WWFLAT32/FILE/_FILE.BAK
Normal file
183
WWFLAT32/FILE/_FILE.BAK
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
;***************************************************************************
|
||||
;* *
|
||||
;* Project Name : Library - Filio header stuff. *
|
||||
;* *
|
||||
;* File Name : FILE.H *
|
||||
;* *
|
||||
;* Programmer : Scott K. Bowen *
|
||||
;* *
|
||||
;* Start Date : September 13, 1993 *
|
||||
;* *
|
||||
;* Last Update : April 11, 1994 *
|
||||
;* *
|
||||
;*-------------------------------------------------------------------------*
|
||||
;* Functions: *
|
||||
;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef FILE_H
|
||||
#include "file.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#define _FILE_H
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* Fileio defines */
|
||||
/*=========================================================================*/
|
||||
|
||||
#define LIB_CDROM TRUE
|
||||
|
||||
#define MODE_OLDFILE (O_RDONLY | O_BINARY)
|
||||
#define MODE_NEWFILE (O_WRONLY | O_BINARY | O_CREAT | O_TRUNC)
|
||||
#define MODE_READWRITE (O_RDWR | O_BINARY)
|
||||
|
||||
#define FILEOPENERROR -1
|
||||
#define FILEOPEN(f,m) ibm_open(f, m, (((UWORD) m) == MODE_OLDFILE) ? S_IREAD : (S_IREAD | S_IWRITE))
|
||||
|
||||
#define FILECLOSE(fd) ibm_close(fd)
|
||||
#define FILEREAD(f,b,n) ibm_read(f,b,(WORD)(n))
|
||||
#define FILEWRITE(f,b,n) ibm_write(f,b,(WORD)(n))
|
||||
#define FILESEEK(f,b,n) ibm_lseek(f, b, n)
|
||||
#define FILEDELETE(f) ibm_unlink(f)
|
||||
#define CHANGEDIR(p) ibm_chdir(p)
|
||||
|
||||
#define FILENAMESIZE 13
|
||||
#define IO_CHUNK_SIZE 0xfff0UL
|
||||
|
||||
/*
|
||||
** Maximum number of file handles
|
||||
*/
|
||||
#define TABLE_MAX 20
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The file handle table */
|
||||
/*=========================================================================*/
|
||||
typedef struct {
|
||||
BOOL Empty; // Is this handle empty?
|
||||
WORD Handle; // DOS file handle (0 = resident).
|
||||
LONG Pos; // Current file position.
|
||||
LONG Start; // Offset of file from pointer.
|
||||
WORD Index; // FileData[] index.
|
||||
WORD Mode; // Access mode (WW).
|
||||
BYTE *Name; // File name pointer.
|
||||
} FileHandleType;
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILEIO.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
WORD ibm_getdisk(VOID);
|
||||
WORD ibm_setdisk(WORD drive);
|
||||
WORD ibm_close(WORD handle);
|
||||
WORD ibm_unlink(BYTE const *name);
|
||||
LONG ibm_lseek(WORD handle, LONG offset, WORD where);
|
||||
UWORD ibm_read(WORD handle, VOID *ptr, UWORD bytes);
|
||||
UWORD ibm_write(WORD handle, VOID *ptr, UWORD bytes);
|
||||
WORD ibm_open(BYTE const *name, UWORD mode, WORD attrib);
|
||||
WORD ibm_chdir(BYTE const *path);
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILELIB.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
WORD cdecl Do_Open_Error(FileErrorType errormsgnum, BYTE const *file_name);
|
||||
VOID cdecl Do_IO_Error(FileErrorType errormsgnum, BYTE const *filename);
|
||||
LONG cdecl Read_File_With_Recovery( WORD handle, VOID *buf, UWORD bytes );
|
||||
WORD cdecl Open_File_With_Recovery( BYTE const *file_name, UWORD mode );
|
||||
BOOL cdecl Cache_File(WORD index, WORD file_handle);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: DEVICES.ASM */
|
||||
/*=========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern VOID Get_Devices(VOID);
|
||||
extern WORD Is_Device_Real(WORD device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: DEVTABLE.ASM */
|
||||
/*=========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern VOID Init_Device_Table(BYTE *table);
|
||||
extern WORD Max_Device(VOID);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: HARDERR.ASM */
|
||||
/*=========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern VOID Install_Hard_Error_Handler(VOID);
|
||||
extern VOID Remove_Hard_Error_Handler(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* Globale variables in the fileio system. */
|
||||
/*=========================================================================*/
|
||||
|
||||
extern BYTE CallingDOSInt;
|
||||
extern "C" extern BYTE MaxDevice,DefaultDrive;
|
||||
extern BYTE MultiDriveSearch;
|
||||
extern FileDataType *FileDataPtr;
|
||||
extern FileHandleType FileHandleTable[TABLE_MAX];
|
||||
extern UWORD NumFiles; // Number of files, except PAK, in file table.
|
||||
extern UWORD NumPAKFiles; // Number of PAK files in filetable.
|
||||
extern VOID *FileCacheHeap; // Pointer to the cache in memory.
|
||||
extern WORD DiskNumber;
|
||||
extern WORD MaxDirNum;
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
|
||||
#endif // _FILE_H
|
||||
|
||||
|
183
WWFLAT32/FILE/_FILE.H
Normal file
183
WWFLAT32/FILE/_FILE.H
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
** Command & Conquer Red Alert(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 A S S O C I A T E S **
|
||||
;***************************************************************************
|
||||
;* *
|
||||
;* Project Name : Library - Filio header stuff. *
|
||||
;* *
|
||||
;* File Name : FILE.H *
|
||||
;* *
|
||||
;* Programmer : Scott K. Bowen *
|
||||
;* *
|
||||
;* Start Date : September 13, 1993 *
|
||||
;* *
|
||||
;* Last Update : April 11, 1994 *
|
||||
;* *
|
||||
;*-------------------------------------------------------------------------*
|
||||
;* Functions: *
|
||||
;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#ifndef FILE_H
|
||||
#include "file.h"
|
||||
#endif
|
||||
|
||||
#ifndef _FILE_H
|
||||
#define _FILE_H
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* Fileio defines */
|
||||
/*=========================================================================*/
|
||||
|
||||
#define LIB_CDROM TRUE
|
||||
|
||||
#define MODE_OLDFILE (O_RDONLY | O_BINARY)
|
||||
#define MODE_NEWFILE (O_WRONLY | O_BINARY | O_CREAT | O_TRUNC)
|
||||
#define MODE_READWRITE (O_RDWR | O_BINARY)
|
||||
|
||||
#define FILEOPENERROR -1
|
||||
#define FILEOPEN(f,m) ibm_open(f, m, (((UWORD) m) == MODE_OLDFILE) ? S_IREAD : (S_IREAD | S_IWRITE))
|
||||
|
||||
#define FILECLOSE(fd) ibm_close(fd)
|
||||
#define FILEREAD(f,b,n) ibm_read(f,b,(WORD)(n))
|
||||
#define FILEWRITE(f,b,n) ibm_write(f,b,(WORD)(n))
|
||||
#define FILESEEK(f,b,n) ibm_lseek(f, b, n)
|
||||
#define FILEDELETE(f) ibm_unlink(f)
|
||||
#define CHANGEDIR(p) ibm_chdir(p)
|
||||
|
||||
#define FILENAMESIZE 13
|
||||
#define IO_CHUNK_SIZE 0xfff0UL
|
||||
|
||||
/*
|
||||
** Maximum number of file handles
|
||||
*/
|
||||
#define TABLE_MAX 20
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The file handle table */
|
||||
/*=========================================================================*/
|
||||
typedef struct {
|
||||
BOOL Empty; // Is this handle empty?
|
||||
WORD Handle; // DOS file handle (0 = resident).
|
||||
LONG Pos; // Current file position.
|
||||
LONG Start; // Offset of file from pointer.
|
||||
WORD Index; // FileData[] index.
|
||||
WORD Mode; // Access mode (WW).
|
||||
BYTE *Name; // File name pointer.
|
||||
} FileHandleType;
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILEIO.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
WORD ibm_getdisk(VOID);
|
||||
WORD ibm_setdisk(WORD drive);
|
||||
WORD ibm_close(WORD handle);
|
||||
WORD ibm_unlink(BYTE const *name);
|
||||
LONG ibm_lseek(WORD handle, LONG offset, WORD where);
|
||||
UWORD ibm_read(WORD handle, VOID *ptr, UWORD bytes);
|
||||
UWORD ibm_write(WORD handle, VOID *ptr, UWORD bytes);
|
||||
WORD ibm_open(BYTE const *name, UWORD mode, WORD attrib);
|
||||
WORD ibm_chdir(BYTE const *path);
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: FILELIB.CPP */
|
||||
/*=========================================================================*/
|
||||
|
||||
WORD cdecl Do_Open_Error(FileErrorType errormsgnum, BYTE const *file_name);
|
||||
VOID cdecl Do_IO_Error(FileErrorType errormsgnum, BYTE const *filename);
|
||||
LONG cdecl Read_File_With_Recovery( WORD handle, VOID *buf, UWORD bytes );
|
||||
int cdecl Open_File_With_Recovery( BYTE const *file_name, unsigned int mode );
|
||||
BOOL cdecl Cache_File(WORD index, WORD file_handle);
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: DEVICES.ASM */
|
||||
/*=========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern VOID Get_Devices(VOID);
|
||||
extern WORD Is_Device_Real(WORD device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: DEVTABLE.ASM */
|
||||
/*=========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern VOID Init_Device_Table(BYTE *table);
|
||||
extern WORD Max_Device(VOID);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* The following prototypes are for the file: HARDERR.ASM */
|
||||
/*=========================================================================*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern VOID Install_Hard_Error_Handler(VOID);
|
||||
extern VOID Remove_Hard_Error_Handler(VOID);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
/* Globale variables in the fileio system. */
|
||||
/*=========================================================================*/
|
||||
|
||||
extern BYTE CallingDOSInt;
|
||||
extern "C" extern BYTE MaxDevice,DefaultDrive;
|
||||
extern BYTE MultiDriveSearch;
|
||||
extern FileDataType *FileDataPtr;
|
||||
extern FileHandleType FileHandleTable[TABLE_MAX];
|
||||
extern UWORD NumFiles; // Number of files, except PAK, in file table.
|
||||
extern UWORD NumPAKFiles; // Number of PAK files in filetable.
|
||||
extern VOID *FileCacheHeap; // Pointer to the cache in memory.
|
||||
extern WORD DiskNumber;
|
||||
extern WORD MaxDirNum;
|
||||
|
||||
|
||||
/*=========================================================================*/
|
||||
|
||||
|
||||
|
||||
#endif // _FILE_H
|
||||
|
||||
|
Reference in New Issue
Block a user