Commit b8f18ac7 authored by Steven Fuller's avatar Steven Fuller

Part A of File IO Rewrite.

misc.c, misc.h: New functions which wrap around open/read/write/etc

id_ca.c: Updated to use these new functions.
parent faa76f57
...@@ -20,6 +20,7 @@ SD_StartMusic((MusicGroup *)audiosegs[STARTMUSIC + chunk]); ...@@ -20,6 +20,7 @@ SD_StartMusic((MusicGroup *)audiosegs[STARTMUSIC + chunk]);
=> =>
SD_StartMusic(chunk); SD_StartMusic(chunk);
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
* use int16_t, etc (stdint)
* serialize reads/writes * serialize reads/writes
* fix fix fix different size stuff * fix fix fix different size stuff
works alright at some res, but breaks on most others currently works alright at some res, but breaks on most others currently
......
This diff is collapsed.
...@@ -8,20 +8,20 @@ ...@@ -8,20 +8,20 @@
typedef struct typedef struct
{ {
long planestart[3]; int planestart[3];
word planelength[3]; int planelength[3];
word width, height; int width, height;
char name[16]; char name[16];
} PACKED maptype; } maptype;
/* ======================================================================== */ /* ======================================================================== */
extern int mapon; extern int mapon;
extern word *mapsegs[MAPPLANES]; extern word *mapsegs[MAPPLANES];
extern maptype *mapheaderseg[NUMMAPS]; extern maptype *mapheaderseg[NUMMAPS];
extern byte *audiosegs[NUMSNDCHUNKS]; extern byte *audiosegs[NUMSNDCHUNKS];
extern byte *grsegs[NUMCHUNKS]; extern byte *grsegs[NUMCHUNKS];
extern char extension[5]; extern char extension[5];
...@@ -63,12 +63,12 @@ void MM_SortMem(); ...@@ -63,12 +63,12 @@ void MM_SortMem();
#define PMPageSize 4096 #define PMPageSize 4096
typedef struct { typedef struct {
longword offset; // Offset of chunk into file longword offset; // Offset of chunk into file
word length; // Length of the chunk int length; // Length of the chunk
memptr addr; memptr addr;
} PageListStruct; } PageListStruct;
extern word ChunksInFile, PMSpriteStart, PMSoundStart; extern int ChunksInFile, PMSpriteStart, PMSoundStart;
extern PageListStruct *PMPages; extern PageListStruct *PMPages;
......
...@@ -22,7 +22,7 @@ typedef bool boolean; ...@@ -22,7 +22,7 @@ typedef bool boolean;
#endif #endif
#define PACKED #define PACKED
#pragma pack(1) /* TODO: this unfortunately packs every struct... */ #pragma pack(1)
#define ssize_t SSIZE_T #define ssize_t SSIZE_T
...@@ -35,7 +35,6 @@ typedef bool boolean; ...@@ -35,7 +35,6 @@ typedef bool boolean;
#include <glob.h> #include <glob.h>
#define PACKED __attribute__((packed)) #define PACKED __attribute__((packed))
#define LONGLONG long long
#ifdef __cplusplus #ifdef __cplusplus
typedef bool boolean; typedef bool boolean;
...@@ -54,13 +53,13 @@ typedef enum { false, true } boolean; ...@@ -54,13 +53,13 @@ typedef enum { false, true } boolean;
#include <time.h> #include <time.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h>
#include <math.h> #include <math.h>
#ifndef O_BINARY #ifndef O_BINARY
#define O_BINARY 0 #define O_BINARY 0
#endif #endif
#include "misc.h"
#include "version.h" #include "version.h"
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
...@@ -106,6 +105,8 @@ typedef struct { ...@@ -106,6 +105,8 @@ typedef struct {
Point ul, lr; Point ul, lr;
} Rect; } Rect;
#include "misc.h"
#include "vi_comm.h" #include "vi_comm.h"
#include "sd_comm.h" #include "sd_comm.h"
......
...@@ -103,7 +103,7 @@ boolean FizzleFade(unsigned xx, unsigned yy, unsigned width, unsigned height, un ...@@ -103,7 +103,7 @@ boolean FizzleFade(unsigned xx, unsigned yy, unsigned width, unsigned height, un
void VL_FillPalette(int red, int green, int blue) void VL_FillPalette(int red, int green, int blue)
{ {
char pal[768]; byte pal[768];
int i; int i;
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
......
...@@ -38,7 +38,6 @@ unsigned long get_TimeCount() ...@@ -38,7 +38,6 @@ unsigned long get_TimeCount()
struct timeval t1; struct timeval t1;
long secs, usecs; long secs, usecs;
long tc; long tc;
//double d;
gettimeofday(&t1, NULL); gettimeofday(&t1, NULL);
secs = t1.tv_sec - t0.tv_sec; secs = t1.tv_sec - t0.tv_sec;
...@@ -47,12 +46,9 @@ unsigned long get_TimeCount() ...@@ -47,12 +46,9 @@ unsigned long get_TimeCount()
usecs += 1000000; usecs += 1000000;
secs--; secs--;
} }
//d = (double)tc0 + (double)secs * 70.0 + (double)usecs * 70.0 / 1000000.0;
//d = (double)tc0 + ((double)secs * 1000000.0 + (double)usecs) / (1000000.0/70.0);
//tc = (long)d;
tc = tc0 + secs * 70 + usecs * 70 / 1000000; tc = tc0 + secs * 70 + usecs * 70 / 1000000;
return tc; return tc;
} }
...@@ -200,3 +196,132 @@ void DisplayTextSplash(byte *text, int l) ...@@ -200,3 +196,132 @@ void DisplayTextSplash(byte *text, int l)
printf("\n"); printf("\n");
} }
} }
/* ** */
static int16_t SwapInt16L(int16_t i)
{
#if __BYTE_ORDER == __BIG_ENDIAN
return ((uint16_t)i >> 8) | ((uint16_t)i << 8);
#else
return i;
#endif
}
static int32_t SwapInt32L(int32_t i)
{
#if __BYTE_ORDER == __BIG_ENDIAN
return ((uint32_t)(i & 0xFF000000) >> 24) |
((uint32_t)(i & 0x00FF0000) >> 8) |
((uint32_t)(i & 0x0000FF00) << 8) |
((uint32_t)(i & 0x000000FF) << 24);
#else
return i;
#endif
}
/* ** */
int OpenWrite(char *fn)
{
int fp;
/* fp = creat(fn, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); */
fp = open(fn, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
return fp;
}
void CloseWrite(int fp)
{
close(fp);
}
int WriteSeek(int fp, int offset, int whence)
{
return lseek(fp, offset, whence);
}
int WriteInt8(int fp, int8_t d)
{
return write(fp, &d, 1);
}
int WriteInt16(int fp, int16_t d)
{
int16_t b = SwapInt16L(d);
return write(fp, &b, 2) / 2;
}
int WriteInt32(int fp, int32_t d)
{
int32_t b = SwapInt32L(d);
return write(fp, &b, 4) / 4;
}
int WriteBytes(int fp, byte *d, int len)
{
return write(fp, d, len);
}
int OpenRead(char *fn)
{
int fp;
fp = open(fn, O_RDONLY | O_BINARY);
return fp;
}
void CloseRead(int fp)
{
close(fp);
}
int ReadSeek(int fp, int offset, int whence)
{
return lseek(fp, offset, whence);
}
int ReadLength(int fp)
{
return filelength(fp);
}
int8_t ReadInt8(int fp)
{
int8_t d;
read(fp, &d, 1);
return d;
}
int16_t ReadInt16(int fp)
{
int16_t d;
read(fp, &d, 2);
d = SwapInt16L(d);
return d;
}
int32_t ReadInt32(int fp)
{
int32_t d;
read(fp, &d, 4);
d = SwapInt32L(d);
return d;
}
int ReadBytes(int fp, byte *d, int len)
{
return read(fp, d, len);
}
...@@ -24,4 +24,25 @@ char *ultoa(unsigned long value, char *string, int radix); ...@@ -24,4 +24,25 @@ char *ultoa(unsigned long value, char *string, int radix);
#endif /* DOSISM */ #endif /* DOSISM */
extern int OpenWrite(char *fn);
extern void CloseWrite(int fp);
extern int WriteSeek(int fp, int offset, int whence);
extern int WriteInt8(int fp, int8_t d);
extern int WriteInt16(int fp, int16_t d);
extern int WriteInt32(int fp, int32_t d);
extern int WriteBytes(int fp, byte *d, int len);
extern int OpenRead(char *fn);
extern void CloseRead(int fp);
extern int ReadSeek(int fp, int offset, int whence);
extern int ReadLength(int fp);
extern int8_t ReadInt8(int fp);
extern int16_t ReadInt16(int fp);
extern int32_t ReadInt32(int fp);
extern int ReadBytes(int fp, byte *d, int len);
#endif #endif
...@@ -16,28 +16,41 @@ ...@@ -16,28 +16,41 @@
/* #define SPEAR */ /* #define SPEAR */
/* #define SPEARDEMO */ /* #define SPEARDEMO */
#define UPLOAD #define UPLOAD
#define GAMENAME "Wolfenstein 3D Shareware" #define GAMENAME "Wolfenstein 3D Shareware"
#define GAMEEXT "wl1"
#define GAMETYPE "WL1\0"
#elif WMODE == 1 #elif WMODE == 1
/* #define SPEAR */ /* #define SPEAR */
/* #define SPEARDEMO */ /* #define SPEARDEMO */
/* #define UPLOAD */ /* #define UPLOAD */
#define GAMENAME "Wolfenstein 3D" #define GAMENAME "Wolfenstein 3D"
#define GAMEEXT "wl6"
#define GAMETYPE "WL6\0"
#elif WMODE == 2 #elif WMODE == 2
#define SPEAR #define SPEAR
#define SPEARDEMO #define SPEARDEMO
/* #define UPLOAD */ /* #define UPLOAD */
#define GAMENAME "Spear of Destiny Demo" #define GAMENAME "Spear of Destiny Demo"
#define GAMEEXT "sdm"
#define GAMETYPE "SDM\0"
#elif WMODE == 3 #elif WMODE == 3
#define SPEAR #define SPEAR
/* #define SPEARDEMO */ /* #define SPEARDEMO */
/* #define UPLOAD */ /* #define UPLOAD */
#define GAMENAME "Spear of Destiny" #define GAMENAME "Spear of Destiny"
#define GAMEEXT "sod"
#define GAMETYPE "SOD\0"
#else #else
#error "please edit version.h and fix WMODE" #error "please edit version.h and fix WMODE"
#endif #endif
#define GAMEHDR "WOLF3D\0\0"
#define SAVTYPE "SAV\0"
#define CFGTYPE "CFG\0"
#endif #endif
...@@ -419,7 +419,7 @@ typedef enum { ...@@ -419,7 +419,7 @@ typedef enum {
typedef enum { typedef enum {
ac_badobject = -1, ac_badobject = -1,
ac_no, ac_no,
ac_yes, ac_yes
} activetype; } activetype;
typedef enum { typedef enum {
...@@ -702,8 +702,8 @@ void NewViewSize (int width); ...@@ -702,8 +702,8 @@ void NewViewSize (int width);
boolean LoadTheGame(int file,int x,int y); boolean LoadTheGame(int file,int x,int y);
boolean SaveTheGame(int file,int x,int y); boolean SaveTheGame(int file,int x,int y);
void ShowViewSize (int width); void ShowViewSize (int width);
void ShutdownId (void); void ShutdownId();
void WriteConfig(void); int WriteConfig();
int WolfMain(int argc, char *argv[]); int WolfMain(int argc, char *argv[]);
...@@ -738,6 +738,7 @@ void RecordDemo(); ...@@ -738,6 +738,7 @@ void RecordDemo();
void DrawHighScores(); void DrawHighScores();
void DrawPlayBorder(); void DrawPlayBorder();
void DrawPlayBorderSides(); void DrawPlayBorderSides();
void DrawStatusBar();
#define PlaySoundLocTile(s,tx,ty) PlaySoundLocGlobal(s,(((long)(tx) << TILESHIFT) + (1L << (TILESHIFT - 1))),(((long)ty << TILESHIFT) + (1L << (TILESHIFT - 1)))) #define PlaySoundLocTile(s,tx,ty) PlaySoundLocGlobal(s,(((long)(tx) << TILESHIFT) + (1L << (TILESHIFT - 1))),(((long)ty << TILESHIFT) + (1L << (TILESHIFT - 1))))
#define PlaySoundLocActor(s,ob) PlaySoundLocGlobal(s,(ob)->x,(ob)->y) #define PlaySoundLocActor(s,ob) PlaySoundLocGlobal(s,(ob)->x,(ob)->y)
......
...@@ -35,7 +35,7 @@ static unsigned postx; ...@@ -35,7 +35,7 @@ static unsigned postx;
static void AsmRefresh(); static void AsmRefresh();
//#define NOASM #define NOASM
#ifndef NOASM #ifndef NOASM
#define FixedByFrac(x, y) \ #define FixedByFrac(x, y) \
......
...@@ -633,6 +633,18 @@ void DrawPlayBorder() ...@@ -633,6 +633,18 @@ void DrawPlayBorder()
} }
} }
void DrawStatusBar()
{
DrawFace();
DrawHealth();
DrawLives();
DrawLevel();
DrawAmmo();
DrawKeys();
DrawWeapon();
DrawScore();
}
/* /*
=================== ===================
= =
...@@ -652,14 +664,7 @@ void DrawPlayScreen() ...@@ -652,14 +664,7 @@ void DrawPlayScreen()
CA_UnCacheGrChunk(STATUSBARPIC); CA_UnCacheGrChunk(STATUSBARPIC);
DrawFace(); DrawStatusBar();
DrawHealth();
DrawLives();
DrawLevel();
DrawAmmo();
DrawKeys();
DrawWeapon();
DrawScore();
} }
//========================================================================== //==========================================================================
......
...@@ -60,9 +60,9 @@ char **_argv; ...@@ -60,9 +60,9 @@ char **_argv;
fixed FixedByFrac(fixed a, fixed b) fixed FixedByFrac(fixed a, fixed b)
{ {
LONGLONG ra = a; int64_t ra = a;
LONGLONG rb = b; int64_t rb = b;
LONGLONG r; int64_t r;
r = ra * rb; r = ra * rb;
r >>= 16; r >>= 16;
...@@ -101,6 +101,7 @@ void CalcTics() ...@@ -101,6 +101,7 @@ void CalcTics()
/* ======================================================================== */ /* ======================================================================== */
#if 0
/* /*
==================== ====================
= =
...@@ -143,21 +144,6 @@ void ReadConfig() ...@@ -143,21 +144,6 @@ void ReadConfig()
close(file); close(file);
if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)
{
sd = sdm_PC;
sd = smm_Off;
}
if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||
(sds == sds_SoundSource && !SoundSourcePresent))
sds = sds_Off;
if (!MousePresent)
mouseenabled = false;
if (!JoysPresent[joystickport])
joystickenabled = false;
MainMenu[6].active=1; MainMenu[6].active=1;
MainItems.curpos=0; MainItems.curpos=0;
} }
...@@ -169,34 +155,17 @@ void ReadConfig() ...@@ -169,34 +155,17 @@ void ReadConfig()
viewsize = 15; viewsize = 15;
} }
if (SoundBlasterPresent || AdLibPresent) mouseenabled = false;
{
sd = sdm_AdLib;
sm = smm_AdLib;
}
else
{
sd = sdm_PC;
sm = smm_Off;
}
if (SoundBlasterPresent)
sds = sds_SoundBlaster;
else
sds = sds_Off;
if (MousePresent) joystickenabled = false;
mouseenabled = true; joypadenabled = false;
joystickport = 0;
joystickenabled = false; mouseadjustment = 5;
joypadenabled = false;
joystickport = 0;
mouseadjustment = 5; SD_SetMusicMode(smm_AdLib);
SD_SetSoundMode(sdm_AdLib);
SD_SetMusicMode(sm); SD_SetDigiDevice(sds_SoundBlaster);
SD_SetSoundMode(sd);
SD_SetDigiDevice(sds);
} }
...@@ -240,31 +209,7 @@ void WriteConfig() ...@@ -240,31 +209,7 @@ void WriteConfig()
} }
} }
/* #endif
=====================
=
= NewGame
=
= Set up new game to start from the beginning
=
=====================
*/
void NewGame(int difficulty, int episode)
{
memset(&gamestate,0,sizeof(gamestate));
gamestate.difficulty = difficulty;
gamestate.weapon = gamestate.bestweapon
= gamestate.chosenweapon = wp_pistol;
gamestate.health = 100;
gamestate.ammo = STARTAMMO;
gamestate.lives = 3;
gamestate.nextextra = EXTRAPOINTS;
gamestate.episode = episode;
startgame = true;
}
void DiskFlopAnim(int x, int y) void DiskFlopAnim(int x, int y)
{ {
...@@ -279,7 +224,6 @@ void DiskFlopAnim(int x, int y) ...@@ -279,7 +224,6 @@ void DiskFlopAnim(int x, int y)
which ^= 1; which ^= 1;
} }
long DoChecksum(byte *source, unsigned size, long checksum) long DoChecksum(byte *source, unsigned size, long checksum)
{ {
int i; int i;
...@@ -290,6 +234,58 @@ long DoChecksum(byte *source, unsigned size, long checksum) ...@@ -290,6 +234,58 @@ long DoChecksum(byte *source, unsigned size, long checksum)
return checksum; return checksum;
} }
int WriteConfig()
{
int fd;
fd = OpenWrite(configname);
if (fd != -1) {
CloseWrite(fd);
}
return 0;
}
int ReadConfig()
{
int fd;
fd = OpenRead(configname);
if (fd != -1) {
CloseRead(fd);
#ifdef UPLOAD
MainMenu[readthis].active = 1;
MainItems.curpos = 0;
#endif
}
mouseenabled = false;
joystickenabled = false;
joypadenabled = false;
joystickport = 0;
mouseadjustment = 5;
SD_SetMusicMode(smm_AdLib);
SD_SetSoundMode(sdm_AdLib);
SD_SetDigiDevice(sds_SoundBlaster);
return 0;
}
int SaveGame()
{
return 0;
}
int LoadGame()
{
return 0;
}
/* /*
================== ==================
...@@ -299,7 +295,7 @@ long DoChecksum(byte *source, unsigned size, long checksum) ...@@ -299,7 +295,7 @@ long DoChecksum(byte *source, unsigned size, long checksum)
================== ==================
*/ */
boolean SaveTheGame(int file,int x,int y) boolean SaveTheGame(int file, int x, int y)
{ {
long checksum; long checksum;
objtype *ob,nullobj; objtype *ob,nullobj;
...@@ -1046,6 +1042,32 @@ void ShutdownId() ...@@ -1046,6 +1042,32 @@ void ShutdownId()
MM_Shutdown(); MM_Shutdown();
} }
/*
=====================
=
= NewGame
=
= Set up new game to start from the beginning
=
=====================
*/
void NewGame(int difficulty, int episode)
{
memset(&gamestate, 0, sizeof(gamestate));
gamestate.difficulty = difficulty;
gamestate.weapon = gamestate.bestweapon
= gamestate.chosenweapon = wp_pistol;
gamestate.health = 100;
gamestate.ammo = STARTAMMO;
gamestate.lives = 3;
gamestate.nextextra = EXTRAPOINTS;
gamestate.episode = episode;
startgame = true;
}
/* /*
========================== ==========================
= =
......
...@@ -90,22 +90,22 @@ CtlMenu[]= ...@@ -90,22 +90,22 @@ CtlMenu[]=
NewEmenu[]= NewEmenu[]=
{ {
{1,"Episode 1\n" {1,"Episode 1\n"
"Escape from Wolfenstein",0}, "Escape from Wolfenstein",0},
{0,"",0}, {0,"",0},
{3,"Episode 2\n" {3,"Episode 2\n"
"Operation: Eisenfaust",0}, "Operation: Eisenfaust",0},
{0,"",0}, {0,"",0},
{3,"Episode 3\n" {3,"Episode 3\n"
"Die, Fuhrer, Die!",0}, "Die, Fuhrer, Die!",0},
{0,"",0}, {0,"",0},
{3,"Episode 4\n" {3,"Episode 4\n"
"A Dark Secret",0}, "A Dark Secret",0},
{0,"",0}, {0,"",0},
{3,"Episode 5\n" {3,"Episode 5\n"
"Trail of the Madman",0}, "Trail of the Madman",0},
{0,"",0}, {0,"",0},
{3,"Episode 6\n" {3,"Episode 6\n"
"Confrontation",0} "Confrontation",0}
}, },
#endif #endif
...@@ -1187,14 +1187,8 @@ int CP_LoadGame(int quick) ...@@ -1187,14 +1187,8 @@ int CP_LoadGame(int quick)
loadedgame=false; loadedgame=false;
close(handle); close(handle);
DrawFace (); DrawStatusBar();
DrawHealth ();
DrawLives ();
DrawLevel ();
DrawAmmo ();
DrawKeys ();
DrawWeapon ();
DrawScore ();
return 1; return 1;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment