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]);
=>
SD_StartMusic(chunk);
------------------------------------------------------------------------------
* use int16_t, etc (stdint)
* serialize reads/writes
* fix fix fix different size stuff
works alright at some res, but breaks on most others currently
......
This diff is collapsed.
......@@ -8,11 +8,11 @@
typedef struct
{
long planestart[3];
word planelength[3];
word width, height;
int planestart[3];
int planelength[3];
int width, height;
char name[16];
} PACKED maptype;
} maptype;
/* ======================================================================== */
......@@ -64,11 +64,11 @@ void MM_SortMem();
typedef struct {
longword offset; // Offset of chunk into file
word length; // Length of the chunk
int length; // Length of the chunk
memptr addr;
} PageListStruct;
extern word ChunksInFile, PMSpriteStart, PMSoundStart;
extern int ChunksInFile, PMSpriteStart, PMSoundStart;
extern PageListStruct *PMPages;
......
......@@ -22,7 +22,7 @@ typedef bool boolean;
#endif
#define PACKED
#pragma pack(1) /* TODO: this unfortunately packs every struct... */
#pragma pack(1)
#define ssize_t SSIZE_T
......@@ -35,7 +35,6 @@ typedef bool boolean;
#include <glob.h>
#define PACKED __attribute__((packed))
#define LONGLONG long long
#ifdef __cplusplus
typedef bool boolean;
......@@ -54,13 +53,13 @@ typedef enum { false, true } boolean;
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>
#include <math.h>
#ifndef O_BINARY
#define O_BINARY 0
#endif
#include "misc.h"
#include "version.h"
/* ------------------------------------------------------------------------ */
......@@ -106,6 +105,8 @@ typedef struct {
Point ul, lr;
} Rect;
#include "misc.h"
#include "vi_comm.h"
#include "sd_comm.h"
......
......@@ -103,7 +103,7 @@ boolean FizzleFade(unsigned xx, unsigned yy, unsigned width, unsigned height, un
void VL_FillPalette(int red, int green, int blue)
{
char pal[768];
byte pal[768];
int i;
for (i = 0; i < 256; i++) {
......
......@@ -38,7 +38,6 @@ unsigned long get_TimeCount()
struct timeval t1;
long secs, usecs;
long tc;
//double d;
gettimeofday(&t1, NULL);
secs = t1.tv_sec - t0.tv_sec;
......@@ -47,11 +46,8 @@ unsigned long get_TimeCount()
usecs += 1000000;
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;
}
......@@ -200,3 +196,132 @@ void DisplayTextSplash(byte *text, int l)
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);
#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
......@@ -17,27 +17,40 @@
/* #define SPEARDEMO */
#define UPLOAD
#define GAMENAME "Wolfenstein 3D Shareware"
#define GAMEEXT "wl1"
#define GAMETYPE "WL1\0"
#elif WMODE == 1
/* #define SPEAR */
/* #define SPEARDEMO */
/* #define UPLOAD */
#define GAMENAME "Wolfenstein 3D"
#define GAMEEXT "wl6"
#define GAMETYPE "WL6\0"
#elif WMODE == 2
#define SPEAR
#define SPEARDEMO
/* #define UPLOAD */
#define GAMENAME "Spear of Destiny Demo"
#define GAMEEXT "sdm"
#define GAMETYPE "SDM\0"
#elif WMODE == 3
#define SPEAR
/* #define SPEARDEMO */
/* #define UPLOAD */
#define GAMENAME "Spear of Destiny"
#define GAMEEXT "sod"
#define GAMETYPE "SOD\0"
#else
#error "please edit version.h and fix WMODE"
#endif
#define GAMEHDR "WOLF3D\0\0"
#define SAVTYPE "SAV\0"
#define CFGTYPE "CFG\0"
#endif
......@@ -419,7 +419,7 @@ typedef enum {
typedef enum {
ac_badobject = -1,
ac_no,
ac_yes,
ac_yes
} activetype;
typedef enum {
......@@ -702,8 +702,8 @@ void NewViewSize (int width);
boolean LoadTheGame(int file,int x,int y);
boolean SaveTheGame(int file,int x,int y);
void ShowViewSize (int width);
void ShutdownId (void);
void WriteConfig(void);
void ShutdownId();
int WriteConfig();
int WolfMain(int argc, char *argv[]);
......@@ -738,6 +738,7 @@ void RecordDemo();
void DrawHighScores();
void DrawPlayBorder();
void DrawPlayBorderSides();
void DrawStatusBar();
#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)
......
......@@ -35,7 +35,7 @@ static unsigned postx;
static void AsmRefresh();
//#define NOASM
#define NOASM
#ifndef NOASM
#define FixedByFrac(x, y) \
......
......@@ -633,6 +633,18 @@ void DrawPlayBorder()
}
}
void DrawStatusBar()
{
DrawFace();
DrawHealth();
DrawLives();
DrawLevel();
DrawAmmo();
DrawKeys();
DrawWeapon();
DrawScore();
}
/*
===================
=
......@@ -652,14 +664,7 @@ void DrawPlayScreen()
CA_UnCacheGrChunk(STATUSBARPIC);
DrawFace();
DrawHealth();
DrawLives();
DrawLevel();
DrawAmmo();
DrawKeys();
DrawWeapon();
DrawScore();
DrawStatusBar();
}
//==========================================================================
......
......@@ -60,9 +60,9 @@ char **_argv;
fixed FixedByFrac(fixed a, fixed b)
{
LONGLONG ra = a;
LONGLONG rb = b;
LONGLONG r;
int64_t ra = a;
int64_t rb = b;
int64_t r;
r = ra * rb;
r >>= 16;
......@@ -101,6 +101,7 @@ void CalcTics()
/* ======================================================================== */
#if 0
/*
====================
=
......@@ -143,21 +144,6 @@ void ReadConfig()
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;
MainItems.curpos=0;
}
......@@ -169,24 +155,7 @@ void ReadConfig()
viewsize = 15;
}
if (SoundBlasterPresent || AdLibPresent)
{
sd = sdm_AdLib;
sm = smm_AdLib;
}
else
{
sd = sdm_PC;
sm = smm_Off;
}
if (SoundBlasterPresent)
sds = sds_SoundBlaster;
else
sds = sds_Off;
if (MousePresent)
mouseenabled = true;
mouseenabled = false;
joystickenabled = false;
joypadenabled = false;
......@@ -194,9 +163,9 @@ void ReadConfig()
mouseadjustment = 5;
SD_SetMusicMode(sm);
SD_SetSoundMode(sd);
SD_SetDigiDevice(sds);
SD_SetMusicMode(smm_AdLib);
SD_SetSoundMode(sdm_AdLib);
SD_SetDigiDevice(sds_SoundBlaster);
}
......@@ -240,31 +209,7 @@ void WriteConfig()
}
}
/*
=====================
=
= 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;
}
#endif
void DiskFlopAnim(int x, int y)
{
......@@ -279,7 +224,6 @@ void DiskFlopAnim(int x, int y)
which ^= 1;
}
long DoChecksum(byte *source, unsigned size, long checksum)
{
int i;
......@@ -290,6 +234,58 @@ long DoChecksum(byte *source, unsigned size, long 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)
==================
*/
boolean SaveTheGame(int file,int x,int y)
boolean SaveTheGame(int file, int x, int y)
{
long checksum;
objtype *ob,nullobj;
......@@ -1046,6 +1042,32 @@ void ShutdownId()
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;
}
/*
==========================
=
......
......@@ -1187,14 +1187,8 @@ int CP_LoadGame(int quick)
loadedgame=false;
close(handle);
DrawFace ();
DrawHealth ();
DrawLives ();
DrawLevel ();
DrawAmmo ();
DrawKeys ();
DrawWeapon ();
DrawScore ();
DrawStatusBar();
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