Skip to content

Commit

Permalink
2007-02-08 Krzysztof Kosciuszkiewicz <[email protected]>
Browse files Browse the repository at this point in the history
	* V126

	* Added SimpleHdr and SimpleHdrW to gamedata.c, changed rest of code to
	use new interface

	* Taken care about nasty bug related to structure packing and order of
	includes

	* Changed level of indentation for preprocessor macros to 0

	* Some of older changes were not checked in to CVS, possibly a bug in
	checkin2
  • Loading branch information
drvee committed Feb 8, 2007
1 parent e86d8aa commit 3b0a803
Show file tree
Hide file tree
Showing 23 changed files with 421 additions and 309 deletions.
2 changes: 1 addition & 1 deletion .indent.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
-npcs
-nprs
-pmt
-ppi3
-ppi0 /* indent level for preprocessor macros */
-psl
-saf
-sai
Expand Down
15 changes: 13 additions & 2 deletions Buzz_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,22 @@ typedef int32_t i32;
// EMS Includes
// #include "sv_lib.h"

#pragma pack(1)

int never_fail;

/* FIXME: non-portable. Used to get struct layout like in DOS days */
#pragma pack(1)

#include "data.h" // main data structures

/* get the alignment back to defaults */
/* #pragma pack() */

/* BIG FIXME: Unfortunately structures defined in some functions rely on tight
* packing. This setting mainly breaks things in gamedata.h, so we make sure
* we notice bad order of #includes. That's another good reason to make all
* code use the gamedata.c interfaces. */
#define ALTERED_STRUCTURE_PACKING

#include "proto.h" // prototypes and general defines
#include "music.h" // defines for music names

Expand Down
25 changes: 25 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2007-02-08 Krzysztof Kosciuszkiewicz <[email protected]>

* V126

* Added SimpleHdr and SimpleHdrW to gamedata.c, changed rest of code to
use new interface

* Taken care about nasty bug related to structure packing and order of
includes

* Changed level of indentation for preprocessor macros to 0

* Some of older changes were not checked in to CVS, possibly a bug in
checkin2

2007-02-07 Michael McCarty <[email protected]>

* V125
Expand Down Expand Up @@ -34,6 +49,16 @@
* Small change to confgure.in that seems to remove the need to run
aclocal with "-I m4" params

2007-02-06 Krzysztof Kosciuszkiewicz <[email protected]>

* V122

* From now on checkin2 will always check in Changelog and version.c

* Factored out some common functionality in replay.c

* Changes in place.c finish the first step towards removing *.frm files

2007-02-06 Krzysztof Kosciuszkiewicz <[email protected]>

* V121
Expand Down
16 changes: 7 additions & 9 deletions ast0.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// Programmed by Michael K McCarty
//

#include "gamedata.h"
#include "Buzz_inc.h"
#include "externs.h"

Expand Down Expand Up @@ -51,9 +52,8 @@ void Moon(char plr)
if (size>13) size=13;

in=sOpen("MOON.BUT","rb",0);
fseek(in,size*(sizeof table),SEEK_CUR);
fread(&table,sizeof table,1,in);
SwapSimpleHdr(&table);
fseek(in,sizeof_SimpleHdr * plr,SEEK_SET);
fread_SimpleHdr(&table,1,in);
fseek(in,table.offset,SEEK_SET);
GV(&local,104,82);
fread(&pal[384],384,1,in); // Individual Palette
Expand Down Expand Up @@ -369,17 +369,15 @@ void LMPict(char poff)
SimpleHdr table;
FILE *in;
in=sOpen("LMER.BUT","rb",0);
fread(&table,sizeof table,1,in);
SwapSimpleHdr(&table);
fseek(in,8*(sizeof table),SEEK_SET);
fread_SimpleHdr(&table,1,in);
fseek(in,8*sizeof_SimpleHdr,SEEK_SET);
fread(&pal[32*3],672,1,in);
fseek(in,table.offset,SEEK_SET);
fread(buffer,table.size,1,in);
GV(&local,156,89); GV(&local2,156,89);
RLED_img(buffer,local.vptr,table.size,local.w,local.h);
fseek(in,(poff)*(sizeof table),SEEK_SET);
fread(&table,sizeof table,1,in);
SwapSimpleHdr(&table);
fseek(in,(poff)*sizeof_SimpleHdr,SEEK_SET);
fread_SimpleHdr(&table,1,in);
fseek(in,table.offset,SEEK_SET);
fread(buffer,table.size,1,in);
RLED_img(buffer,local2.vptr,table.size,local2.w,local2.h);
Expand Down
8 changes: 4 additions & 4 deletions ast4.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// Programmed by Michael K McCarty
//

#include "gamedata.h"
#include "Buzz_inc.h"
#include "externs.h"

Expand Down Expand Up @@ -164,10 +165,9 @@ void PlaceEquip(char plr,char prog)

GV(&local,80,50);GV(&local2,80,50);
fin=sOpen("APROG.BUT","rb",0);
fseek(fin,(plr*7+prog)*(sizeof table),SEEK_SET);
fread(&table,sizeof table,1,fin);
SwapSimpleHdr(&table);
fseek(fin,14*(sizeof table),SEEK_SET);
fseek(fin,(plr*7+prog)*sizeof_SimpleHdr,SEEK_SET);
fread_SimpleHdr(&table,1,fin);
fseek(fin,14*sizeof_SimpleHdr,SEEK_SET);
fread(&pal[0],768,1,fin);

fseek(fin,table.offset,SEEK_SET);
Expand Down
7 changes: 7 additions & 0 deletions checkin2
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mode=cvs

required_commits="ChangeLog version.c"

lasttag=`cvs log -h version.c |
sed '1,/symbolic names:/d' |
Expand Down Expand Up @@ -58,6 +59,12 @@ then
exit 1
fi

if [ $# -ne 0 ] ; then
# correct me if I'm wrong - it does not hurt to have same argument
# twice in cvs commit...
set -- "$@" $required_commits
fi

cvs -z9 commit -R -m "$msg" "$@"
if [ $? != 0 ]
then
Expand Down
11 changes: 0 additions & 11 deletions data.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,17 +503,6 @@ enum SpacePortOverlays
PORT_SVHQ, // 34 Strategic Visions H.Q.
};

// Typical size/offset file header used for image files
typedef struct _simpleheader6 {
uint16_t size;
uint32_t offset;
} SimpleHdr;

typedef struct _simpleheader8 {
uint32_t size;
uint32_t offset;
} SimpleHdrW;

// Typical
typedef struct _patch {
int16_t w;
Expand Down
12 changes: 0 additions & 12 deletions endianness.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ void SwapGameDat(void)
}

#ifdef __BIG_ENDIAN__
void
SwapSimpleHdr(SimpleHdr *hdr)
{
assert(hdr);

Swap16bit(hdr->size);
Swap32bit(hdr->offset);
}

void
SwapPatchHdr(PatchHdr *hdr)
{
Expand All @@ -125,9 +116,6 @@ SwapPatchHdrSmall(PatchHdrSmall *hdr)
Swap16bit(hdr->size);
Swap32bit(hdr->offset);
}



#endif


2 changes: 0 additions & 2 deletions endianness.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ void SwapGameDat(void);

#define Swap32bit(a) (a) = _Swap32bit((a))
#define Swap16bit(a) (a) = _Swap16bit((a))
void SwapSimpleHdr(SimpleHdr *hdr);
void SwapPatchHdr(PatchHdr *hdr);
void SwapPatchHdrSmall(PatchHdrSmall *hdr);

#else

#define Swap32bit(a)
#define Swap16bit(a)
#define SwapSimpleHdr(a)
#define SwapPatchHdr(a)
#define SwapPatchHdrSmall(a)

Expand Down
38 changes: 34 additions & 4 deletions gamedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ fread_##type(struct type *dst, size_t num, FILE *f) \
elems = fread(tmp, sizeof_##type, elems, f); \
if (!elems) \
break; \
for (i = 0; i < elems; ++i, ++dst) \
get_##type(dst, tmp+i*sizeof_##type); \
for (i = 0; i < elems; ++i) \
get_##type(dst++, tmp+i*sizeof_##type); \
total += elems; \
num -= elems; \
} \
Expand All @@ -145,8 +145,8 @@ fwrite_##type(const struct type *src, size_t num, FILE *f) \
while (num > 0) \
{ \
elems = (num < (bufelems)) ? num : (bufelems); \
for (i = 0; i < elems; ++i, ++src) \
put_##type(tmp+i*sizeof_##type, src); \
for (i = 0; i < elems; ++i) \
put_##type(tmp+i*sizeof_##type, src++); \
elems = fwrite(tmp, sizeof_##type, elems, f); \
if (!elems) \
break; \
Expand Down Expand Up @@ -272,6 +272,36 @@ DECL_PUT_END
DECL_FREAD(struct, oFGROUP, 32)
/* DECL_FWRITE(struct, oFGROUP, 32) */

/* SimpleHdr */

DECL_GET_START(, SimpleHdr)
DECL_GET_FIELD_SCALAR(uint16_t, size, 1)
DECL_GET_FIELD_SCALAR(uint32_t, offset, 1)
DECL_GET_END

DECL_PUT_START(, SimpleHdr)
DECL_PUT_FIELD_SCALAR(uint16_t, size, 1)
DECL_PUT_FIELD_SCALAR(uint32_t, offset, 1)
DECL_PUT_END

DECL_FREAD(, SimpleHdr, 32)
/* DECL_FWRITE(, SimpleHdr, 32) */

/* SimpleHdrW */

DECL_GET_START(, SimpleHdrW)
DECL_GET_FIELD_SCALAR(uint32_t, size, 1)
DECL_GET_FIELD_SCALAR(uint32_t, offset, 1)
DECL_GET_END

DECL_PUT_START(, SimpleHdrW)
DECL_PUT_FIELD_SCALAR(uint32_t, size, 1)
DECL_PUT_FIELD_SCALAR(uint32_t, offset, 1)
DECL_PUT_END

DECL_FREAD(, SimpleHdrW, 32)
/* DECL_FWRITE(, SimpleHdrW, 32) */

#if 0
/* REPLAY */
DECL_GET_START(, REPLAY)
Expand Down
23 changes: 23 additions & 0 deletions gamedata.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifndef _GAMEDATA_H
#define _GAMEDATA_H

/* See Buzz_inc.h for comments on this */
#ifdef ALTERED_STRUCTURE_PACKING
#error Make sure that gamedata.h is included before Buzz_inc.h
#undefined /* to make errors appear on all compilers */
#endif

#include "race.h"
#include <stdio.h>
#include "int_types.h" /* auto-generated inttypes.h */
Expand Down Expand Up @@ -82,6 +88,23 @@ struct oFGROUP {
#define sizeof_oFGROUP (15 + 5*sizeof_oLIST)
extern size_t fread_oFGROUP(struct oFGROUP *dst, size_t num, FILE *f);

/* used in: MOON.BUT, LMER.BUT, APROG.BUT, INTEL.BUT,
* RDFULL.BUT, PRFX.BUT, LFACIL.BUT, PRESR.BUT */
typedef struct {
uint16_t size;
uint32_t offset;
} SimpleHdr;
#define sizeof_SimpleHdr (2+4)
extern size_t fread_SimpleHdr(SimpleHdr *dst, size_t num, FILE *f);

/* used in TOTNEWS.CDR */
typedef struct {
uint32_t size;
uint32_t offset;
} SimpleHdrW;

#define sizeof_SimpleHdrW (4+4)
extern size_t fread_SimpleHdrW(SimpleHdrW * dst, size_t num, FILE * f);
/*
* File: REPLAY.DAT
* Desc: Contains indices to animation sequences of past player missions.
Expand Down
12 changes: 6 additions & 6 deletions intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
//
// Museum Main Files

#include "gamedata.h"
#include "Buzz_inc.h"
#include "externs.h"

extern struct mStr Mis;

extern GXHEADER but;
Expand Down Expand Up @@ -432,19 +434,17 @@ void TopSecret(char plr,char poff)
if (poff<56)
if (plr==1) poff=poff+28;
in=sOpen("INTEL.BUT","rb",0);
fread(&table,sizeof table,1,in);
SwapSimpleHdr(&table);
fseek(in,71*(sizeof table),SEEK_SET);
fread_SimpleHdr(&table,1,in);
fseek(in,71*sizeof_SimpleHdr,SEEK_SET);
fread(&pal[0],768,1,in);
fseek(in,table.offset,SEEK_SET);
fread(buffer,table.size,1,in);
GV(&local,157,100); GV(&local2,157,100);
RLED_img(buffer,local.vptr,table.size,local.w,local.h);
if (poff!=100)
{
fseek(in,(poff+1)*(sizeof table),SEEK_SET);
fread(&table,sizeof table,1,in);
SwapSimpleHdr(&table);
fseek(in,(poff+1)*sizeof_SimpleHdr,SEEK_SET);
fread_SimpleHdr(&table,1,in);
fseek(in,table.offset,SEEK_SET);
fread(buffer,table.size,1,in);
RLED_img(buffer,local2.vptr,table.size,local.w,local.h);
Expand Down
1 change: 1 addition & 0 deletions macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifndef __MACROS_H__
#define __MACROS_H__

#define ARRAY_LENGTH(arr) ((sizeof (arr)) / (sizeof ((arr)[0])))

#define IRBox(a,b,c,d,e) {InBox((a),(b),(c),(d));RectFill((a)+1,(b)+1,(c)-1,(d)-1,(e));}
#define ORBox(a,b,c,d,e) {OutBox((a),(b),(c),(d));RectFill((a)+1,(b)+1,(c)-1,(d)-1,(e));}
Expand Down
2 changes: 1 addition & 1 deletion mis_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
// Programmed by Michael K McCarty
//

#include "gamedata.h"
#include "Buzz_inc.h"
#include "externs.h"
#include "mis.h"
#include "gamedata.h"

#ifdef CONFIG_THEORA_VIDEO
#include "av.h"
Expand Down
Loading

0 comments on commit 3b0a803

Please sign in to comment.