Commit 67a3124e authored by Steven Fuller's avatar Steven Fuller

Wolf3d builds and a simple resource loader added. Now to implement

everything else.
parent 5a6541f6
......@@ -10,6 +10,9 @@
#include <string.h>
#include <stdio.h>
unsigned char *VideoPointer;
Word VideoWidth;
LongWord YTable[480];
Word FontX;
Word FontY;
......@@ -22,6 +25,10 @@ Word FontLoaded;
Word FontInvisible;
unsigned char FontOrMask[16];
Word SystemState=3;
#define BRGR 0x42524752
/**********************************
Sound sub-system
......@@ -47,7 +54,7 @@ void SoundOff(void)
void PlaySound(Word SoundNum)
{
if (SoundNum && (SystemState&SfxActive)) {
if (SoundNum) {
SoundNum+=127;
if (SoundNum&0x8000) { /* Mono sound */
EndSound(SoundNum&0x7fff);
......@@ -74,7 +81,6 @@ static Word LastSong = -1;
void PlaySong(Word Song)
{
if (Song) {
KilledSong = Song;
if (SystemState&MusicActive) {
if (Song!=LastSong) {
BeginSongLooped(Song);
......@@ -606,17 +612,7 @@ void FadeToPtr(unsigned char *PalPtr)
void *LoadAResource(Word RezNum)
{
return(LoadAResource2(RezNum,'BRGR'));
}
/**********************************
Load a global resource
**********************************/
void *LoadAResource2(Word RezNum,LongWord Type)
{
return(LoadAResource2(RezNum, BRGR));
}
/**********************************
......@@ -627,17 +623,7 @@ void *LoadAResource2(Word RezNum,LongWord Type)
void ReleaseAResource(Word RezNum)
{
ReleaseAResource2(RezNum,'BRGR');
}
/**********************************
Release a global resource
**********************************/
void ReleaseAResource2(Word RezNum,LongWord Type)
{
ReleaseAResource2(RezNum, BRGR);
}
/**********************************
......@@ -648,17 +634,7 @@ void ReleaseAResource2(Word RezNum,LongWord Type)
void KillAResource(Word RezNum)
{
KillAResource2(RezNum,'BRGR');
}
/**********************************
Kill a global resource
**********************************/
void KillAResource2(Word RezNum,LongWord Type)
{
KillAResource2(RezNum, BRGR);
}
void SaveJunk(void *AckPtr,Word Length)
......@@ -716,11 +692,13 @@ void DLZSS(Byte *Dest,Byte *Src,LongWord Length)
if (Length >= RunCount) {
Length -= RunCount;
} else {
printf("Overrun: l:%d r:%d\n", Length, RunCount);
RunCount = Length;
Length = 0;
}
do {
while (RunCount--) {
*Dest++ = *BackPtr++;
} while (--RunCount);
}
Src+=2;
}
BitBucket>>=1;
......
......@@ -18,7 +18,7 @@ void Intro(void)
FadeToBlack(); /* Fade out the video */
PackPtr = LoadAResource(rMacPlayPic);
PackLength = PackPtr[0];
PackLength = lMSB(PackPtr[0]);
ShapePtr = AllocSomeMem(PackLength);
DLZSS(ShapePtr,(Byte *) &PackPtr[1],PackLength);
DrawShape(0,0,ShapePtr);
......@@ -35,7 +35,7 @@ void Intro(void)
ClearTheScreen(BLACK);
BlastScreen();
PackPtr = LoadAResource(rYummyPic);
PackLength = PackPtr[0];
PackLength = lMSB(PackPtr[0]);
ShapePtr = AllocSomeMem(PackLength);
DLZSS(ShapePtr,(Byte *) &PackPtr[1],PackLength);
DrawShape((SCREENWIDTH-320)/2,(SCREENHEIGHT-200)/2,ShapePtr);
......
......@@ -119,9 +119,9 @@ Boolean TitleScreen (void)
NewGameWindow(1); /* Set to 512 mode */
FadeToBlack(); /* Fade out the video */
PackPtr = LoadAResource(rTitlePic);
PackLen = PackPtr[0];
PackLen = lMSB(PackPtr[0]);
ShapePtr = (Byte *)AllocSomeMem(PackLen);
DLZSS(ShapePtr,(Byte *) &PackPtr[1],PackLen);
DLZSS(ShapePtr, (Byte *)&PackPtr[1], PackLen);
DrawShape(0,0,ShapePtr);
ReleaseAResource(rTitlePic);
FreeSomeMem(ShapePtr);
......@@ -144,9 +144,8 @@ jmp_buf ResetJmp;
Boolean JumpOK;
extern Word NumberIndex;
int main(int argc, char *argv[])
int WolfMain(int argc, char *argv[])
{
InitTools(); /* Init the system environment */
WaitTick(); /* Wait for a system tick to go by */
playstate = (exit_t)setjmp(ResetJmp);
NumberIndex = 36; /* Force the score to redraw properly */
......
......@@ -9,8 +9,8 @@ CFLAGS = -g
OBJS = Data.o Doors.o EnMove.o EnThink.o Intro.o Level.o \
Missiles.o Music.o PlMove.o PlStuff.o PlThink.o PushWall.o \
RefBsp.o RefSprite.o Refresh.o Refresh2.o Sight.o Main.o \
StateDef.o WolfMain.o WolfIO.o InterMis.o Burger.o
SOBJS = $(OBJS)
StateDef.o WolfMain.o WolfIO.o InterMis.o Burger.o stub.o res.o
SOBJS = $(OBJS) vi_svga.o
XOBJS = $(OBJS)
GOBJS = $(OBJS)
......@@ -25,11 +25,12 @@ NASM = nasm
.SUFFIXES: .asm
all: swolf3d xwolf3d gwolf3d
#all: swolf3d xwolf3d gwolf3d
all: swolf3d
$(SOBJS):
$(XOBJS):
$(GOBJS):
$(SOBJS): Sounds.h Sprites.h States.h Wolf.h burger.h wolfdef.h
$(XOBJS): Sounds.h Sprites.h States.h Wolf.h burger.h wolfdef.h
$(GOBJS): Sounds.h Sprites.h States.h Wolf.h burger.h wolfdef.h
.asm.o:
$(NASM) -f elf -o $@ $<
......
......@@ -190,7 +190,6 @@ void DrawAutomap(Word tx,Word ty)
Boolean StartupRendering(Word NewSize)
{
#ifdef __MAC__
int i;
Word minz;
int x;
......@@ -199,14 +198,11 @@ Boolean StartupRendering(Word NewSize)
LongWord focallength;
Word j;
Word *ScalePtr;
#endif
if (NewSize == MathSize) { /* Already loaded? */
return TRUE;
}
#ifdef __MAC__ /* Only the mac version will calculate the tables */
/* generate scaleatz*/
ScalePtr = scaleatzptr;
......@@ -290,28 +286,6 @@ Boolean StartupRendering(Word NewSize)
viewangletox[i] = SCREENWIDTH;
}
}
#if 0 /* Should I save these tables? */
if (!NewSize) {
SaveJunk(scaleatzptr,sizeof(Word)*MAXZ);
SaveJunk(finetangent,sizeof(short)*FINEANGLES/2);
SaveJunk(finesine,sizeof(short)*FINEANGLES/2);
SaveJunk(viewangletox,sizeof(short)*FINEANGLES/2);
SaveJunk(xtoviewangle,sizeof(short)*(SCREENWIDTH+1));
GoodBye();
}
#endif
#else
/* All other versions load the tables from disk (MUCH FASTER!!) */
if (MathSize==-1) {
finetangent = LoadAResource(rFineTangent);
finesine = LoadAResource(rFineSine);
}
scaleatzptr = LoadAResource(rScaleAtZ);
viewangletox = LoadAResource(rViewAngleToX);
xtoviewangle = LoadAResource(rXToViewAngle);
#endif
clipshortangle = xtoviewangle[0]<<ANGLETOFINESHIFT; /* Save leftmost angle for view */
clipshortangle2 = clipshortangle*2; /* Double the angle for constant */
......
......@@ -121,13 +121,10 @@ Word tantoangle[513] = {
void GetTableMemory(void)
{
#ifdef __MAC__ /* Only the mac version will calculate the tables */
/* All other versions will load precalc'd tables from disk */
scaleatzptr = (Word *)AllocSomeMem(sizeof(Word)*MAXZ);
viewangletox = (short *)AllocSomeMem(sizeof(short)*FINEANGLES/2);
xtoviewangle = (short *)AllocSomeMem(sizeof(short)*(1024+1));
finetangent = (short *)AllocSomeMem(sizeof(short)*FINEANGLES/2);
finesine = (short *) AllocSomeMem(sizeof(short)*FINEANGLES/2);
#endif
MathSize = -1; /* No math data is loaded... */
}
typedef unsigned int Word;
typedef unsigned long LongWord;
typedef unsigned char Byte;
typedef unsigned char Boolean;
#define BLACK 255
#define DARKGREY 250
#define BROWN 101
#define PURPLE 133
#define BLUE 210
#define DARKGREEN 229
#define ORANGE 23
#define RED 216
#define BEIGE 14
#define YELLOW 5
#define GREEN 225
#define LIGHTBLUE 150
#define LILAC 48
#define PERIWINKLE 120
#define LIGHTGREY 43
#define WHITE 0
#define SfxActive 1
#define MusicActive 2
#define VideoSize 64000
#define SetAuxType(x,y)
#define SetFileType(x,y)
extern unsigned char *VideoPointer;
extern Word KeyModifiers;
extern Word ScanCode;
extern Word KilledSong;
extern Word SystemState;
extern Word VideoWidth;
extern LongWord LastTick;
extern LongWord YTable[480];
void DLZSS(Byte *Dest, Byte *Src,LongWord Length);
LongWord SwapLong(LongWord Val);
unsigned short SwapUShort(unsigned short Val);
short SwapShort(short Val);
void WaitTick(void);
void WaitTicks(Word TickCount);
Word WaitTicksEvent(Word TickCount);
Word WaitEvent(void);
LongWord ReadTick(void);
void *AllocSomeMem(LongWord Size);
void FreeSomeMem(void *MemPtr);
Word GetAKey(void);
Word AllKeysUp(void);
Word WaitKey(void);
void FlushKeys(void);
void SoundOff(void);
void PlaySound(Word SndNum);
void StopSound(Word SndNum);
void PlaySong(Word SongNum);
void ClearTheScreen(Word Color);
void ShowPic(Word PicNum);
void InitYTable(void);
void InstallAFont(Word FontNum);
void FontUseMask(void);
void FontUseZero(void);
void SetFontXY(Word x,Word y);
void FontSetColor(Word Index,Word Color);
void DrawAString(char *TextPtr);
void DrawAChar(Word Letter);
void ultoa(LongWord Val,char *TextPtr);
Word GetRandom(Word Range);
void Randomize(void);
void DrawShape(Word x,Word y,void *ShapePtr);
void DrawXMShape(Word x,Word y,void *ShapePtr);
void DrawMShape(Word x,Word y,void *ShapePtr);
void EraseMBShape(Word x,Word y, void *ShapePtr,void *BackPtr);
Word TestMShape(Word x,Word y,void *ShapePtr);
Word TestMBShape(Word x,Word y,void *ShapePtr,void *BackPtr);
void SetAPalette(Word PalNum);
void SetAPalettePtr(unsigned char *PalPtr);
void FadeTo(Word PalNum);
void FadeToBlack(void);
void FadeToPtr(unsigned char *PalPtr);
void *LoadAResource(Word RezNum);
void ReleaseAResource(Word RezNum);
void KillAResource(Word RezNum);
void *LoadAResource2(Word RezNum,LongWord Type);
void ReleaseAResource2(Word RezNum,LongWord Type);
void KillAResource2(Word RezNum,LongWord Type);
void SaveJunk(void *AckPtr,Word Length);
#include <stdio.h>
#include <stdlib.h>
#include "wolfdef.h"
typedef struct ResItem_t
{
long type;
Word item;
Byte *dat;
struct ResItem_t *next;
} ResItem;
ResItem *lr;
int InitResources(char *name)
{
FILE *fp;
ResItem **cur = &lr, *t;
int resfork, resmap, forklen, maplen;
int typelist, namelist, typecount;
int datalen;
int i;
fp = fopen(name, "rb");
if (fp == NULL)
return -1;
resfork = (fgetc(fp) << 24) | (fgetc(fp) << 16) | (fgetc(fp) << 8) | (fgetc(fp) << 0);
resmap = (fgetc(fp) << 24) | (fgetc(fp) << 16) | (fgetc(fp) << 8) | (fgetc(fp) << 0);
forklen = (fgetc(fp) << 24) | (fgetc(fp) << 16) | (fgetc(fp) << 8) | (fgetc(fp) << 0);
maplen = (fgetc(fp) << 24) | (fgetc(fp) << 16) | (fgetc(fp) << 8) | (fgetc(fp) << 0);
fseek(fp, resmap, SEEK_SET);
fseek(fp, 24, SEEK_CUR); /* Skip over reserved */
typelist = (fgetc(fp) << 8) | (fgetc(fp) << 0);
namelist = (fgetc(fp) << 8) | (fgetc(fp) << 0);
typecount = ((fgetc(fp) << 8) | (fgetc(fp) << 0)) + 1;
for (i = 0; i < typecount; i++) {
int type;
int off, bak, bak2, data, count, x, c, z;
int d1, d2, d3, d4;
type = (fgetc(fp) << 24) | (fgetc(fp) << 16) | (fgetc(fp) << 8) | (fgetc(fp) << 0);
count = ((fgetc(fp) << 8) | fgetc(fp)) + 1;
off = (fgetc(fp) << 8) | fgetc(fp);
bak = ftell(fp);
fseek(fp, resmap + typelist + off, SEEK_SET);
for (x = 0; x < count; x++) {
int id;
id = (fgetc(fp) << 8) | fgetc(fp);
off = (fgetc(fp) << 8) | fgetc(fp);
fgetc(fp);
data = (fgetc(fp) << 16) | (fgetc(fp) << 8) | (fgetc(fp) << 0);
fgetc(fp); fgetc(fp); fgetc(fp); fgetc(fp);
bak2 = ftell(fp);
fseek(fp, resfork + data, SEEK_SET);
datalen = (fgetc(fp) << 24) | (fgetc(fp) << 16) | (fgetc(fp) << 8) | (fgetc(fp) << 0);
t = (ResItem *)malloc(sizeof(ResItem));
t->next = NULL;
t->type = type;
t->item = id;
t->dat = (Byte *)malloc(datalen);
fread(t->dat, datalen, 1, fp);
*cur = t;
cur = &((*cur)->next);
fseek(fp, bak2, SEEK_SET);
}
fseek(fp, bak, SEEK_SET);
}
fclose(fp);
return 0;
}
void *LoadAResource2(Word RezNum, LongWord Type)
{
ResItem *c = lr;
while (c != NULL) {
if ( (c->type == Type) && (c->item == RezNum) )
return c->dat;
c = c->next;
}
fprintf(stderr, "ERROR: %d/%d was not found!\n", Type, RezNum);
exit(EXIT_FAILURE);
}
void ReleaseAResource2(Word RezNum, LongWord Type)
{
ResItem *c = lr;
while (c != NULL) {
c = c->next;
}
}
void KillAResource2(Word RezNum, LongWord Type)
{
ResItem *c = lr;
while (c != NULL) {
c = c->next;
}
}
void FreeResources()
{
ResItem *c = lr;
while (c) {
ResItem *t = c;
if (c->dat)
free(c->dat);
c = c->next;
free(t);
}
lr = NULL;
}
#include "wolfdef.h"
unsigned long lMSB(unsigned long x)
{
int x1 = (x & 0x000000FF) << 24;
int x2 = (x & 0x0000FF00) << 8;
int x3 = (x & 0x00FF0000) >> 8;
int x4 = (x & 0xFF000000) >> 24;
return x1 | x2 | x3 | x4;
}
void IO_ScaleWallColumn(Word x,Word scale,Word tile,Word column)
{
}
void IO_ScaleMaskedColumn(Word x,Word scale,unsigned short *sprite,Word column)
{
}
Boolean SetupScalers(void)
{
return 1;
}
void ReleaseScalers()
{
}
void MakeSmallFont(void)
{
}
void KillSmallFont(void)
{
}
void DrawSmall(Word x,Word y,Word tile)
{
}
void ShowGetPsyched(void)
{
}
void DrawPsyched(Word Index)
{
}
void EndGetPsyched(void)
{
}
void FlushKeys(void)
{
/* TODO: read all keys in keyboard buffer */
}
void ReadSystemJoystick(void)
{
/* TODO: do key stuff here */
}
void ShareWareEnd(void)
{
SetAPalette(rGamePal);
printf("ShareWareEnd()\n");
SetAPalette(rBlackPal);
}
Word WaitEvent(void)
{
return 0;
}
LongWord ReadTick()
{
return 0;
}
void WaitTick()
{
}
void WaitTicks(Word Count)
{
}
Word WaitTicksEvent(Word Time)
{
return 0;
}
void FreeSong()
{
}
void BeginSongLooped(Song)
{
}
void EndSong()
{
}
void BeginSound(short int theID, long theRate)
{
}
void EndSound(short int theID)
{
}
void EndAllSound(void)
{
}
void PurgeAllSounds(unsigned long minMemory)
{
}
void BlastScreen2(Rect *BlastRect)
{
}
void BlastScreen(void)
{
}
Word NewGameWindow(Word NewVidSize)
{
}
void BailOut()
{
printf("BailOut()\n");
exit(1);
}
Word ChooseGameDiff(void)
{
}
void FinishLoadGame(void)
{
}
#include <stdio.h>
#include <stdlib.h>
#include <vga.h>
#include <vgakeyboard.h>
#include "wolfdef.h"
int main(int argc, char *argv[])
{
if (argc != 2) {
fprintf(stderr, "usage: %s <mac wolf3d resource fork>\n", argv[0]);
exit(EXIT_FAILURE);
}
if (InitResources(argv[1])) {
fprintf(stderr, "could not load %s\n", argv[1]);
exit(EXIT_FAILURE);
}
return WolfMain(argc, argv);
}
......@@ -15,6 +15,11 @@ typedef struct {
int bottom;
} Rect;
unsigned short int sLSB(unsigned short int i);
unsigned short int sMSB(unsigned short int i);
unsigned long lLSB(unsigned long i);
unsigned long lMSB(unsigned long i);
/* an angle_t occupies an entire 16 bits so wraparound is automatically handled */
#define SHORTTOANGLESHIFT 7 /* 0x10000 to ANGLES */
......@@ -782,7 +787,6 @@ extern void SetupPlayScreen(void);
extern void RunAutoMap(void);
extern void StartGame(void);
extern Boolean TitleScreen(void);
extern void WolfMain(void);
/* In Intermis.c */
......
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