Commit 7df8774f authored by Steven Fuller's avatar Steven Fuller

More work on id_ca.c

parent 25227641
...@@ -67,16 +67,6 @@ char audioname[13]="AUDIO."; ...@@ -67,16 +67,6 @@ char audioname[13]="AUDIO.";
============================================================================= =============================================================================
*/ */
extern long far CGAhead;
extern long far EGAhead;
extern byte CGAdict;
extern byte EGAdict;
extern byte far maphead;
extern byte mapdict;
extern byte far audiohead;
extern byte audiodict;
char extension[5], // Need a string, not constant to change cache files char extension[5], // Need a string, not constant to change cache files
gheadname[10]="vgahead.", gheadname[10]="vgahead.",
gfilename[10]="vgagraph.", gfilename[10]="vgagraph.",
...@@ -103,7 +93,7 @@ long chunkcomplen, chunkexplen; ...@@ -103,7 +93,7 @@ long chunkcomplen, chunkexplen;
SDMode oldsoundmode; SDMode oldsoundmode;
void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, void CAL_CarmackExpand (unsigned *source, unsigned *dest,
unsigned length); unsigned length);
...@@ -164,28 +154,22 @@ void CAL_GetGrChunkLength (int chunk) ...@@ -164,28 +154,22 @@ void CAL_GetGrChunkLength (int chunk)
========================== ==========================
*/ */
boolean CA_FarRead (int handle, byte far *dest, long length) boolean CA_FarRead(int handle, byte *dest, long length)
{ {
if (length>0xffffl) ssize_t l;
Quit ("CA_FarRead doesn't support 64K reads yet!");
l = read(handle, dest, length);
asm push ds
asm mov bx,[handle] if (l == -1) {
asm mov cx,[WORD PTR length] perror("CA_FarRead");
asm mov dx,[WORD PTR dest] return false;
asm mov ds,[WORD PTR dest+2] } else if (l == 0) {
asm mov ah,0x3f // READ w/handle fprintf(stderr, "CA_FarRead hit EOF?\n");
asm int 21h
asm pop ds
asm jnc good
errno = _AX;
return false; return false;
good: } else if (l != length) {
asm cmp ax,[WORD PTR length] fprintf(stderr, "CA_FarRead only read %d out of %d\n", l, length);
asm je done
errno = EINVFMT; // user manager knows this is bad read
return false; return false;
done: }
return true; return true;
} }
...@@ -193,36 +177,28 @@ done: ...@@ -193,36 +177,28 @@ done:
/* /*
========================== ==========================
= =
= CA_SegWrite = CA_FarWrite
= =
= Write from a file to a far pointer = Write from a file to a far pointer
= =
========================== ==========================
*/ */
boolean CA_FarWrite (int handle, byte far *source, long length) boolean CA_FarWrite (int handle, byte *source, long length)
{ {
if (length>0xffffl) ssize_t l;
Quit ("CA_FarWrite doesn't support 64K reads yet!");
l = write(handle, source, length);
asm push ds if (l == -1) {
asm mov bx,[handle] perror("CA_FarWrite");
asm mov cx,[WORD PTR length]
asm mov dx,[WORD PTR source]
asm mov ds,[WORD PTR source+2]
asm mov ah,0x40 // WRITE w/handle
asm int 21h
asm pop ds
asm jnc good
errno = _AX;
return false; return false;
good: } else if (l == 0) {
asm cmp ax,[WORD PTR length] fprintf(stderr, "CA_FarWrite hit EOF?\n");
asm je done
errno = ENOMEM; // user manager knows this is bad write
return false; return false;
} else if (l != length) {
done: fprintf(stderr, "CA_FarWrite only wrote %d out of %d\n", l, length);
return false;
}
return true; return true;
} }
...@@ -242,7 +218,7 @@ boolean CA_ReadFile (char *filename, memptr *ptr) ...@@ -242,7 +218,7 @@ boolean CA_ReadFile (char *filename, memptr *ptr)
int handle; int handle;
long size; long size;
if ((handle = open(filename,O_RDONLY | O_BINARY, S_IREAD)) == -1) if ((handle = open(filename, O_RDONLY | O_BINARY, S_IREAD)) == -1)
return false; return false;
size = filelength (handle); size = filelength (handle);
...@@ -266,7 +242,7 @@ boolean CA_ReadFile (char *filename, memptr *ptr) ...@@ -266,7 +242,7 @@ boolean CA_ReadFile (char *filename, memptr *ptr)
========================== ==========================
*/ */
boolean CA_WriteFile (char *filename, void far *ptr, long length) boolean CA_WriteFile (char *filename, void *ptr, long length)
{ {
int handle; int handle;
long size; long size;
...@@ -320,43 +296,11 @@ boolean CA_LoadFile (char *filename, memptr *ptr) ...@@ -320,43 +296,11 @@ boolean CA_LoadFile (char *filename, memptr *ptr)
/* /*
============================================================================ ============================================================================
COMPRESSION routines, see JHUFF.C for more COMPRESSION routines
============================================================================ ============================================================================
*/ */
/*
===============
=
= CAL_OptimizeNodes
=
= Goes through a huffman table and changes the 256-511 node numbers to the
= actular address of the node. Must be called before CAL_HuffExpand
=
===============
*/
void CAL_OptimizeNodes (huffnode *table)
{
huffnode *node;
int i;
node = table;
for (i=0;i<255;i++)
{
if (node->bit0 >= 256)
node->bit0 = (unsigned)(table+(node->bit0-256));
if (node->bit1 >= 256)
node->bit1 = (unsigned)(table+(node->bit1-256));
node++;
}
}
/* /*
====================== ======================
= =
...@@ -368,182 +312,35 @@ void CAL_OptimizeNodes (huffnode *table) ...@@ -368,182 +312,35 @@ void CAL_OptimizeNodes (huffnode *table)
= =
====================== ======================
*/ */
/* From Ryan C. Gordon -- ryan_gordon@hotmail.com */
void CAL_HuffExpand (byte *source, byte *dest, void CAL_HuffExpand(byte *source, byte *dest, long length, huffnode *htable)
long length,huffnode *hufftable, boolean screenhack)
{ {
// unsigned bit,byte,node,code; huffnode *headptr; // remains constant head of huffman tree.
unsigned sourceseg,sourceoff,destseg,destoff,endoff; huffnode *nodeon; // for trailing down node trees...
huffnode *headptr; byte mask = 0x0001; // for bitwise testing.
byte mapmask; word path; // stores branch of huffman node.
// huffnode *nodeon; byte *endoff = (dest + length); // ptr to where uncompressed ends.
headptr = hufftable+254; // head node is allways node 254
source++; // normalize
source--;
dest++;
dest--;
if (screenhack)
{
mapmask = 1;
asm mov dx,SC_INDEX
asm mov ax,SC_MAPMASK + 256
asm out dx,ax
length >>= 2;
}
sourceseg = FP_SEG(source);
sourceoff = FP_OFF(source);
destseg = FP_SEG(dest);
destoff = FP_OFF(dest);
endoff = destoff+length;
//
// ds:si source
// es:di dest
// ss:bx node pointer
//
if (length <0xfff0)
{
//-------------------------- nodeon = headptr = htable + 254; // head node is always node 254.
// expand less than 64k of data
//--------------------------
asm mov bx,[headptr] do {
if ((*source) & mask)
asm mov si,[sourceoff] path = nodeon->bit1;
asm mov di,[destoff]
asm mov es,[destseg]
asm mov ds,[sourceseg]
asm mov ax,[endoff]
asm mov ch,[si] // load first byte
asm inc si
asm mov cl,1
expandshort:
asm test ch,cl // bit set?
asm jnz bit1short
asm mov dx,[ss:bx] // take bit0 path from node
asm shl cl,1 // advance to next bit position
asm jc newbyteshort
asm jnc sourceupshort
bit1short:
asm mov dx,[ss:bx+2] // take bit1 path
asm shl cl,1 // advance to next bit position
asm jnc sourceupshort
newbyteshort:
asm mov ch,[si] // load next byte
asm inc si
asm mov cl,1 // back to first bit
sourceupshort:
asm or dh,dh // if dx<256 its a byte, else move node
asm jz storebyteshort
asm mov bx,dx // next node = (huffnode *)code
asm jmp expandshort
storebyteshort:
asm mov [es:di],dl
asm inc di // write a decopmpressed byte out
asm mov bx,[headptr] // back to the head node for next bit
asm cmp di,ax // done?
asm jne expandshort
//
// perform screenhack if needed
//
asm test [screenhack],1
asm jz notscreen
asm shl [mapmask],1
asm mov ah,[mapmask]
asm cmp ah,16
asm je notscreen // all four planes done
asm mov dx,SC_INDEX
asm mov al,SC_MAPMASK
asm out dx,ax
asm mov di,[destoff]
asm mov ax,[endoff]
asm jmp expandshort
notscreen:;
}
else else
{ path = nodeon->bit0;
mask <<= 1;
//-------------------------- if (mask == 0x0000) { // fully cycled bit positions? Get next char.
// expand more than 64k of data mask = 0x0001;
//-------------------------- source++;
} // if
length--;
asm mov bx,[headptr]
asm mov cl,1
asm mov si,[sourceoff]
asm mov di,[destoff]
asm mov es,[destseg]
asm mov ds,[sourceseg]
asm lodsb // load first byte
expand:
asm test al,cl // bit set?
asm jnz bit1
asm mov dx,[ss:bx] // take bit0 path from node
asm jmp gotcode
bit1:
asm mov dx,[ss:bx+2] // take bit1 path
gotcode:
asm shl cl,1 // advance to next bit position
asm jnc sourceup
asm lodsb
asm cmp si,0x10 // normalize ds:si
asm jb sinorm
asm mov cx,ds
asm inc cx
asm mov ds,cx
asm xor si,si
sinorm:
asm mov cl,1 // back to first bit
sourceup:
asm or dh,dh // if dx<256 its a byte, else move node
asm jz storebyte
asm mov bx,dx // next node = (huffnode *)code
asm jmp expand
storebyte:
asm mov [es:di],dl
asm inc di // write a decopmpressed byte out
asm mov bx,[headptr] // back to the head node for next bit
asm cmp di,0x10 // normalize es:di
asm jb dinorm
asm mov dx,es
asm inc dx
asm mov es,dx
asm xor di,di
dinorm:
asm sub [WORD PTR ss:length],1
asm jnc expand
asm dec [WORD PTR ss:length+2]
asm jns expand // when length = ffff ffff, done
}
asm mov ax,ss
asm mov ds,ax
if (path < 256) { // if (path < 256) it's a byte, else move node.
*dest = (byte) path;
dest++;
nodeon = headptr;
} else // if
nodeon = (htable + (path - 256));
} while (dest != endoff); // written all data to *dest?
} }
...@@ -560,10 +357,10 @@ asm mov ds,ax ...@@ -560,10 +357,10 @@ asm mov ds,ax
#define NEARTAG 0xa7 #define NEARTAG 0xa7
#define FARTAG 0xa8 #define FARTAG 0xa8
void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned length) void CAL_CarmackExpand (unsigned *source, unsigned *dest, unsigned length)
{ {
unsigned ch,chhigh,count,offset; unsigned ch,chhigh,count,offset;
unsigned far *copyptr, far *inptr, far *outptr; unsigned *copyptr, *inptr, *outptr;
length/=2; length/=2;
...@@ -579,13 +376,13 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt ...@@ -579,13 +376,13 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt
count = ch&0xff; count = ch&0xff;
if (!count) if (!count)
{ // have to insert a word containing the tag byte { // have to insert a word containing the tag byte
ch |= *((unsigned char far *)inptr)++; ch |= *((unsigned char *)inptr)++;
*outptr++ = ch; *outptr++ = ch;
length--; length--;
} }
else else
{ {
offset = *((unsigned char far *)inptr)++; offset = *((unsigned char *)inptr)++;
copyptr = outptr - offset; copyptr = outptr - offset;
length -= count; length -= count;
while (count--) while (count--)
...@@ -597,7 +394,7 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt ...@@ -597,7 +394,7 @@ void CAL_CarmackExpand (unsigned far *source, unsigned far *dest, unsigned lengt
count = ch&0xff; count = ch&0xff;
if (!count) if (!count)
{ // have to insert a word containing the tag byte { // have to insert a word containing the tag byte
ch |= *((unsigned char far *)inptr)++; ch |= *((unsigned char *)inptr)++;
*outptr++ = ch; *outptr++ = ch;
length --; length --;
} }
...@@ -831,7 +628,6 @@ void CAL_SetupGrFile (void) ...@@ -831,7 +628,6 @@ void CAL_SetupGrFile (void)
read(handle, &grhuffman, sizeof(grhuffman)); read(handle, &grhuffman, sizeof(grhuffman));
close(handle); close(handle);
CAL_OptimizeNodes (grhuffman);
// //
// load the data offsets from ???head.ext // load the data offsets from ???head.ext
// //
...@@ -892,7 +688,6 @@ void CAL_SetupMapFile (void) ...@@ -892,7 +688,6 @@ void CAL_SetupMapFile (void)
// //
// load maphead.ext (offsets and tileinfo for map file) // load maphead.ext (offsets and tileinfo for map file)
// //
#ifndef MAPHEADERLINKED
strcpy(fname,mheadname); strcpy(fname,mheadname);
strcat(fname,extension); strcat(fname,extension);
...@@ -904,11 +699,6 @@ void CAL_SetupMapFile (void) ...@@ -904,11 +699,6 @@ void CAL_SetupMapFile (void)
MM_GetPtr (&(memptr)tinf,length); MM_GetPtr (&(memptr)tinf,length);
CA_FarRead(handle, tinf, length); CA_FarRead(handle, tinf, length);
close(handle); close(handle);
#else
tinf = (byte *)FP_SEG(&maphead);
#endif
// //
// open the data file // open the data file
...@@ -984,7 +774,7 @@ void CAL_SetupAudioFile (void) ...@@ -984,7 +774,7 @@ void CAL_SetupAudioFile (void)
length = filelength(handle); length = filelength(handle);
MM_GetPtr (&(memptr)audiostarts,length); MM_GetPtr (&(memptr)audiostarts,length);
CA_FarRead(handle, (byte far *)audiostarts, length); CA_FarRead(handle, (byte *)audiostarts, length);
close(handle); close(handle);
// //
...@@ -1155,7 +945,7 @@ cachein: ...@@ -1155,7 +945,7 @@ cachein:
====================== ======================
*/ */
void CAL_ExpandGrChunk (int chunk, byte far *source) void CAL_ExpandGrChunk (int chunk, byte *source)
{ {
long expanded; long expanded;
...@@ -1187,7 +977,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source) ...@@ -1187,7 +977,7 @@ void CAL_ExpandGrChunk (int chunk, byte far *source)
// //
// everything else has an explicit size longword // everything else has an explicit size longword
// //
expanded = *(long far *)source; expanded = *(long *)source;
source += 4; // skip over length source += 4; // skip over length
} }
...@@ -1279,7 +1069,7 @@ void CA_CacheScreen (int chunk) ...@@ -1279,7 +1069,7 @@ void CA_CacheScreen (int chunk)
{ {
long pos,compressed,expanded; long pos,compressed,expanded;
memptr bigbufferseg; memptr bigbufferseg;
byte far *source; byte *source;
int next; int next;
// //
...@@ -1298,7 +1088,7 @@ void CA_CacheScreen (int chunk) ...@@ -1298,7 +1088,7 @@ void CA_CacheScreen (int chunk)
CA_FarRead(grhandle,bigbufferseg,compressed); CA_FarRead(grhandle,bigbufferseg,compressed);
source = bigbufferseg; source = bigbufferseg;
expanded = *(long far *)source; expanded = *(long *)source;
source += 4; // skip over length source += 4; // skip over length
// //
...@@ -1328,7 +1118,7 @@ void CA_CacheMap (int mapnum) ...@@ -1328,7 +1118,7 @@ void CA_CacheMap (int mapnum)
int plane; int plane;
memptr *dest,bigbufferseg; memptr *dest,bigbufferseg;
unsigned size; unsigned size;
unsigned far *source; unsigned *source;
#ifdef CARMACIZED #ifdef CARMACIZED
memptr buffer2seg; memptr buffer2seg;
long expanded; long expanded;
...@@ -1358,7 +1148,7 @@ void CA_CacheMap (int mapnum) ...@@ -1358,7 +1148,7 @@ void CA_CacheMap (int mapnum)
source = bigbufferseg; source = bigbufferseg;
} }
CA_FarRead(maphandle,(byte far *)source,compressed); CA_FarRead(maphandle,(byte *)source,compressed);
#ifdef CARMACIZED #ifdef CARMACIZED
// //
// unhuffman, then unRLEW // unhuffman, then unRLEW
...@@ -1369,8 +1159,8 @@ void CA_CacheMap (int mapnum) ...@@ -1369,8 +1159,8 @@ void CA_CacheMap (int mapnum)
expanded = *source; expanded = *source;
source++; source++;
MM_GetPtr (&buffer2seg,expanded); MM_GetPtr (&buffer2seg,expanded);
CAL_CarmackExpand (source, (unsigned far *)buffer2seg,expanded); CAL_CarmackExpand (source, (unsigned *)buffer2seg,expanded);
CA_RLEWexpand (((unsigned far *)buffer2seg)+1,*dest,size, CA_RLEWexpand (((unsigned *)buffer2seg)+1,*dest,size,
((mapfiletype *)tinf)->RLEWtag); ((mapfiletype *)tinf)->RLEWtag);
MM_FreePtr (&buffer2seg); MM_FreePtr (&buffer2seg);
...@@ -1550,7 +1340,7 @@ void CA_CacheMarks (void) ...@@ -1550,7 +1340,7 @@ void CA_CacheMarks (void)
int i,next,numcache; int i,next,numcache;
long pos,endpos,nextpos,nextendpos,compressed; long pos,endpos,nextpos,nextendpos,compressed;
long bufferstart,bufferend; // file position of general buffer long bufferstart,bufferend; // file position of general buffer
byte far *source; byte *source;
memptr bigbufferseg; memptr bigbufferseg;
numcache = 0; numcache = 0;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define PACKED __attribute__((packed)) #define PACKED __attribute__((packed))
#ifndef O_BINARY #ifndef O_BINARY
#define O_BINARY #define O_BINARY 0
#endif #endif
......
///////////////////////////////////////
//
// TED5 Map Header for WLF
//
///////////////////////////////////////
//
// Map Names
//
typedef enum {
LEVEL_ONE_MAP, // 0
LEVEL_TWO_MAP, // 1
LEVEL_THREE_MAP, // 2
LEVEL_FOUR_MAP, // 3
LASTMAP
} mapnames;
#ifndef __VERSION_H__
#define __VERSION_H__
//#define SPEAR //#define SPEAR
//#define JAPAN //#define JAPAN
#define GOODTIMES #define GOODTIMES
...@@ -7,3 +10,7 @@ ...@@ -7,3 +10,7 @@
//#define DEBCHECK //#define DEBCHECK
#define CARMACIZED #define CARMACIZED
//#define UPLOAD //#define UPLOAD
#elif
#error "fix me: TODO"
#endif
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