esselfortium
Well-known member
It's been stated plenty of times on here that the official Mac port of Doom was less than great, and it's also well-known to perform terribly on 68k. It's also closed-source (unless you want to pay some eBayer $1000 to get your hands on a CD).
The official Doom source release in 1997 was for the Linux port, and has since been backported to countless other platforms, but never to 68k System 7. So, I thought I'd see if I could get anything compiling in CodeWarrior 6.0 (IDE 4.1).
While I've made a lot of progress in getting through the source, porting over the most crucial functionality and (for now) disabling things like sound for the sake of simplicity, I've run into some issues that I'm not sure how to solve. I've been doing lots of research in the official Mac Toolbox guides and contemporary Mac C programming books, which have been hugely educational and have made it possible to get this far, but I'm still running up against some problems I'm not sure how to solve.
(For further context: I am not an experienced C programmer, but I have taken courses on C and have many years of experience with other languages. This project is me jumping into the deep end of the pool and smashing my head on a rock repeatedly.)
The first big one: alloca. I found a single reference to alloca in an Apple dev guide from the 90s, but nothing more. CodeWarrior doesn't seem to recognize it. I'm unsure if I just need to #include something different, or if the affected code needs to be rewritten to use something completely different (in which case I am going to have bigger questions).
Here's an example of alloca in use in the Linuxdoom source, while compositing textures from one or multiple "patch" graphics:
What's the right way to handle this for System 7?
The official Doom source release in 1997 was for the Linux port, and has since been backported to countless other platforms, but never to 68k System 7. So, I thought I'd see if I could get anything compiling in CodeWarrior 6.0 (IDE 4.1).
While I've made a lot of progress in getting through the source, porting over the most crucial functionality and (for now) disabling things like sound for the sake of simplicity, I've run into some issues that I'm not sure how to solve. I've been doing lots of research in the official Mac Toolbox guides and contemporary Mac C programming books, which have been hugely educational and have made it possible to get this far, but I'm still running up against some problems I'm not sure how to solve.
(For further context: I am not an experienced C programmer, but I have taken courses on C and have many years of experience with other languages. This project is me jumping into the deep end of the pool and smashing my head on a rock repeatedly.)
The first big one: alloca. I found a single reference to alloca in an Apple dev guide from the 90s, but nothing more. CodeWarrior doesn't seem to recognize it. I'm unsure if I just need to #include something different, or if the affected code needs to be rewritten to use something completely different (in which case I am going to have bigger questions).
Here's an example of alloca in use in the Linuxdoom source, while compositing textures from one or multiple "patch" graphics:
Code:
//
// R_GenerateLookup
//
void R_GenerateLookup (int texnum)
{
texture_t* texture;
byte* patchcount; // patchcount[texture->width]
texpatch_t* patch;
patch_t* realpatch;
int x;
int x1;
int x2;
int i;
short* collump;
unsigned short* colofs;
texture = textures[texnum];
// Composited texture not created yet.
texturecomposite[texnum] = 0;
texturecompositesize[texnum] = 0;
collump = texturecolumnlump[texnum];
colofs = texturecolumnofs[texnum];
// Now count the number of columns
// that are covered by more than one patch.
// Fill in the lump / offset, so columns
// with only a single patch are all done.
patchcount = (byte *)alloca (texture->width);
memset (patchcount, 0, texture->width);
patch = texture->patches;
for (i=0 , patch = texture->patches;
i<texture->patchcount;
i++, patch++)
{
realpatch = W_CacheLumpNum (patch->patch, PU_CACHE);
x1 = patch->originx;
x2 = x1 + SHORT(realpatch->width);
if (x1 < 0)
x = 0;
else
x = x1;
if (x2 > texture->width)
x2 = texture->width;
for ( ; x<x2 ; x++)
{
patchcount[x]++;
collump[x] = patch->patch;
colofs[x] = LONG(realpatch->columnofs[x-x1])+3;
}
}
for (x=0 ; x<texture->width ; x++)
{
if (!patchcount[x])
{
printf ("R_GenerateLookup: column without a patch (%s)\n",
texture->name);
return;
}
// I_Error ("R_GenerateLookup: column without a patch");
if (patchcount[x] > 1)
{
// Use the cached block.
collump[x] = -1;
colofs[x] = texturecompositesize[texnum];
if (texturecompositesize[texnum] > 0x10000-texture->height)
{
I_Error ("R_GenerateLookup: texture %i is >64k",
texnum);
}
texturecompositesize[texnum] += texture->height;
}
}
}
What's the right way to handle this for System 7?