From 3b0a8033a996372572c9e9579b9c61f7160f35a8 Mon Sep 17 00:00:00 2001 From: drvee Date: Thu, 8 Feb 2007 02:18:44 +0000 Subject: [PATCH] 2007-02-08 Krzysztof Kosciuszkiewicz * 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 --- .indent.pro | 2 +- Buzz_inc.h | 15 +- ChangeLog | 25 +++ ast0.c | 16 +- ast4.c | 8 +- checkin2 | 7 + data.h | 11 -- endianness.c | 12 -- endianness.h | 2 - gamedata.c | 38 ++++- gamedata.h | 23 +++ intel.c | 12 +- macros.h | 1 + mis_c.c | 2 +- news.c | 18 +- place.c | 21 ++- port.c | 15 +- prefs.c | 6 +- proto.h | 2 +- radar.c | 11 +- replay.c | 475 +++++++++++++++++++++++++++------------------------ review.c | 6 +- version.c | 2 +- 23 files changed, 421 insertions(+), 309 deletions(-) diff --git a/.indent.pro b/.indent.pro index 0e130d8..c9b4e31 100644 --- a/.indent.pro +++ b/.indent.pro @@ -24,7 +24,7 @@ -npcs -nprs -pmt --ppi3 +-ppi0 /* indent level for preprocessor macros */ -psl -saf -sai diff --git a/Buzz_inc.h b/Buzz_inc.h index 4146eaa..1775020 100644 --- a/Buzz_inc.h +++ b/Buzz_inc.h @@ -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 diff --git a/ChangeLog b/ChangeLog index a7d6242..ed8a0de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2007-02-08 Krzysztof Kosciuszkiewicz + + * 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 * V125 @@ -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 + + * 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 * V121 diff --git a/ast0.c b/ast0.c index 08dce27..b4e90ca 100644 --- a/ast0.c +++ b/ast0.c @@ -23,6 +23,7 @@ // Programmed by Michael K McCarty // +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" @@ -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 @@ -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); diff --git a/ast4.c b/ast4.c index 4724312..b35d62a 100644 --- a/ast4.c +++ b/ast4.c @@ -23,6 +23,7 @@ // Programmed by Michael K McCarty // +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" @@ -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); diff --git a/checkin2 b/checkin2 index 5d390c1..c9e13b4 100755 --- a/checkin2 +++ b/checkin2 @@ -2,6 +2,7 @@ mode=cvs +required_commits="ChangeLog version.c" lasttag=`cvs log -h version.c | sed '1,/symbolic names:/d' | @@ -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 diff --git a/data.h b/data.h index bd068c0..fb27671 100644 --- a/data.h +++ b/data.h @@ -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; diff --git a/endianness.c b/endianness.c index 13a7bd1..ef23de9 100644 --- a/endianness.c +++ b/endianness.c @@ -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) { @@ -125,9 +116,6 @@ SwapPatchHdrSmall(PatchHdrSmall *hdr) Swap16bit(hdr->size); Swap32bit(hdr->offset); } - - - #endif diff --git a/endianness.h b/endianness.h index 10c88d0..73acf8f 100644 --- a/endianness.h +++ b/endianness.h @@ -12,7 +12,6 @@ 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); @@ -20,7 +19,6 @@ void SwapPatchHdrSmall(PatchHdrSmall *hdr); #define Swap32bit(a) #define Swap16bit(a) -#define SwapSimpleHdr(a) #define SwapPatchHdr(a) #define SwapPatchHdrSmall(a) diff --git a/gamedata.c b/gamedata.c index f683907..9939a23 100644 --- a/gamedata.c +++ b/gamedata.c @@ -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; \ } \ @@ -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; \ @@ -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) diff --git a/gamedata.h b/gamedata.h index 4cdfc74..280b5bb 100644 --- a/gamedata.h +++ b/gamedata.h @@ -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 #include "int_types.h" /* auto-generated inttypes.h */ @@ -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. diff --git a/intel.c b/intel.c index cfb74af..7076b23 100644 --- a/intel.c +++ b/intel.c @@ -24,8 +24,10 @@ // // Museum Main Files +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" + extern struct mStr Mis; extern GXHEADER but; @@ -432,9 +434,8 @@ 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); @@ -442,9 +443,8 @@ void TopSecret(char plr,char poff) 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); diff --git a/macros.h b/macros.h index c633645..a8a56da 100644 --- a/macros.h +++ b/macros.h @@ -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));} diff --git a/mis_c.c b/mis_c.c index 31fb06a..f3520fa 100644 --- a/mis_c.c +++ b/mis_c.c @@ -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" diff --git a/news.c b/news.c index ed6d323..c683512 100644 --- a/news.c +++ b/news.c @@ -25,8 +25,10 @@ // // NewsCaster Main Files +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" +#include "macros.h" double load_news_anim_start; @@ -922,7 +924,6 @@ FILE * LoadNewsAnim(ui8 Index, ui8 Mode, FILE * fp) { GXHEADER local; - int i; int aframe; unsigned MAX = 0, TOT = 0; @@ -999,22 +1000,13 @@ LoadNewsAnim(ui8 Index, ui8 Mode, FILE * fp) if (!fp) fp = sOpen("TOTNEWS.CDR", "rb", 0); fseek(fp, 0x00, SEEK_SET); - fread(&hdr, sizeof hdr, 1, fp); - - Swap32bit(hdr[Index].size); - Swap32bit(hdr[Index].offset); + fread_SimpleHdrW(hdr, ARRAY_LENGTH(hdr), fp); totnews_offset = hdr[Index].offset; fseek(fp, hdr[Index].offset, SEEK_SET); fread(&aChart, sizeof aChart, 1, fp); - fread(table, sizeof(SimpleHdr), aChart.frames, fp); - - for (i = 0; i < aChart.frames; i++) - { - SwapSimpleHdr(&table[i]); - } - + fread_SimpleHdr(table, aChart.frames, fp); fread(&pal[96], 1, 672, fp); Frame = 1; @@ -1220,3 +1212,5 @@ ShowEvt(char plr, char crd) } // EOF + + diff --git a/place.c b/place.c index 9c88d6d..074d53b 100644 --- a/place.c +++ b/place.c @@ -15,9 +15,15 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "race.h" +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" +#ifdef CONFIG_THEORA_VIDEO +#include "av.h" +#endif + extern char IDT[5],IKEY[5],AL_CALL,AI[2]; extern struct mStr Mis; extern char Option,MAIL; @@ -345,9 +351,8 @@ void BigHardMe(char plr,int x,int y,char hw,char unit,char sh,unsigned char coff if (sh==0) { size=(plr*32)+(hw*8)+unit; in=sOpen("RDFULL.BUT","rb",0); - fseek(in,size*(sizeof table),SEEK_CUR); - fread(&table,sizeof table,1,in); - SwapSimpleHdr(&table); + fseek(in,size*sizeof_SimpleHdr,SEEK_CUR); + fread_SimpleHdr(&table,1,in); fseek(in,table.offset,SEEK_SET); GV(&local,104,77);GV(&local2,104,77); fread(&pal[coff*3],96*3,1,in); // Individual Palette @@ -707,7 +712,7 @@ void Draw_Mis_Stats(char plr, char index, int *where,char mode) if(key>0) delay(150); DrawMisHist(plr,where); key=0; - return; + goto done; } else if (mode==1 && ((x>=245 && y>=5 && x<=314 && y<=17 && mousebuttons==1) || key==K_ENTER)) { @@ -718,7 +723,7 @@ void Draw_Mis_Stats(char plr, char index, int *where,char mode) if (!AI[plr]) KillMusic(); FadeOut(2,pal,10,0,0); key=0; - return; /* Done */ + goto done; /* Done */ } else if ((x>=216 && y>=136 && x<=308 && y<=146 && mousebuttons==1) || (key=='R')) { @@ -793,6 +798,12 @@ void Draw_Mis_Stats(char plr, char index, int *where,char mode) }; // if }; // while +done: +#ifdef CONFIG_THEORA_VIDEO + video_rect.w = 0; + video_rect.h = 0; +#endif + } diff --git a/port.c b/port.c index 443eca0..09131a8 100644 --- a/port.c +++ b/port.c @@ -23,6 +23,7 @@ // Programmed by Michael K McCarty // +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" @@ -128,20 +129,20 @@ struct sIMG { -i16 sCount,Vab_Spot; // sCount is the number of steps +int16_t sCount,Vab_Spot; // sCount is the number of steps FILE *sFin; SimpleHdr hSPOT; // Filled by Seek_sOff(); struct sPATH sPath,sPathOld; struct sIMG sImg,sImgOld; -ui32 pTable,pLoc; +uint32_t pTable,pLoc; -void Seek_sOff(int where) +void +Seek_sOff(int where) { - fseek(sFin,where*(sizeof hSPOT)+(MSPOT.sOff),SEEK_SET); - fread(&hSPOT,sizeof hSPOT,1,sFin); - SwapSimpleHdr(&hSPOT); - fseek(sFin,hSPOT.offset,SEEK_SET); + fseek(sFin, where * sizeof_SimpleHdr + MSPOT.sOff, SEEK_SET); + fread_SimpleHdr(&hSPOT, 1, sFin); + fseek(sFin, hSPOT.offset, SEEK_SET); } void Seek_pOff(int where) diff --git a/prefs.c b/prefs.c index 08a5791..4eee770 100644 --- a/prefs.c +++ b/prefs.c @@ -23,6 +23,7 @@ // Programmed by Michael K McCarty // +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" @@ -124,9 +125,8 @@ void HModel(char mode,char tx) FILE *in; in=sOpen("PRFX.BUT","rb",0); - fseek(in,(mode==0 || mode==1)*(sizeof table),SEEK_CUR); - fread(&table,sizeof table,1,in); - SwapSimpleHdr(&table); + fseek(in,(mode==0 || mode==1)*sizeof_SimpleHdr,SEEK_CUR); + fread_SimpleHdr(&table,1,in); fseek(in,table.offset,SEEK_SET); GV(&local,127,80); fread(&pal[112*3],96*3,1,in); // Individual Palette diff --git a/proto.h b/proto.h index 3418b91..c6095a1 100644 --- a/proto.h +++ b/proto.h @@ -662,7 +662,7 @@ void UpdateRecords(char Ty); // REPLAY.C void RLEF(void *dest, void *src, unsigned int src_size); void DispBaby(int x, int y, int loc,char neww); -void AbzFrame(char plr,int num,int dx,int dy,int width,int height,char *Type,char mde); +void AbzFrame(char plr,int num,int dx,int dy,int width,int height,char *Type,char mode); void Replay(char plr,int num,int dx,int dy,int width,int height,char *Type); // REVIEW.C diff --git a/radar.c b/radar.c index 54bba39..6e205cb 100644 --- a/radar.c +++ b/radar.c @@ -23,6 +23,7 @@ // Programmed by Michael K McCarty // +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" @@ -232,17 +233,15 @@ void PadPict(char poff) SimpleHdr table; FILE *in; in=sOpen("LFACIL.BUT","rb",0); - fread(&table,sizeof table,1,in); - SwapSimpleHdr(&table); - fseek(in,6*(sizeof table),SEEK_SET); + fread_SimpleHdr(&table,1,in); + fseek(in,6*sizeof_SimpleHdr,SEEK_SET); fread(pal,768,1,in); fseek(in,table.offset,SEEK_SET); fread(buffer,table.size,1,in); GV(&local,148,148); GV(&local2,148,148); 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); diff --git a/replay.c b/replay.c index 2817a96..1af140f 100644 --- a/replay.c +++ b/replay.c @@ -22,9 +22,10 @@ // Designed by Fritz Bronner // Programmed by Michael K McCarty // +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" -#include "gamedata.h" +#include #ifdef CONFIG_THEORA_VIDEO #include "mmfile.h" @@ -33,15 +34,15 @@ #ifdef DEADCODE -#define FRM_Delay 25 +#define FRM_Delay 25 -#define STL_OFF 26715 -#define ANIM_PARTS 297 +#define STL_OFF 26715 +#define ANIM_PARTS 297 -extern char STEPnum,loc[4]; +extern char STEPnum, loc[4]; extern struct MisEval Mev[60]; -extern char MANNED[2],STEP,pal2[768],AI[2]; -extern int tFrames,cFrame; +extern char MANNED[2], STEP, pal2[768], AI[2]; +extern int tFrames, cFrame; extern long aLoc; extern GXHEADER dply; extern struct AnimType AHead; @@ -49,76 +50,142 @@ extern struct BlockHead BHead; #endif #if 0 -void RLEF(char *dest, char *src, unsigned int src_size) +void +RLEF(char *dest, char *src, unsigned int src_size) { - asm push es; // preserve ES - asm push ds; // preserve DS - asm les di,dest; // move dest into ES:DI - asm lds si,src; // move src into DS:SI - asm mov cx,0; // clear CX - asm mov bx,src_size; // move counter into BX -loa: - asm lodsb; // move byte into AL - asm dec bx; // decrement CX - asm cmp al,0; // compare AL to 0 - asm jl repeat; // if al < 0 jump to repeat - // copy bytes - asm mov ah,0; // clear AH - asm inc al; // increment AL - asm mov cl,al; // put value of AL into CL - asm rep movsb; // move CX bytes from DS:SI to ES:DI - asm sub bx,ax; // increment BX by approp value - asm cmp bx,0; // see if finished - asm jg loa; // if not then loop - asm jmp bot; // else jump to bottom - -repeat: - asm neg al; // negate AL - asm inc al; // increment AL by 1 - asm mov cl,al; // move counter value to CX - asm lodsb; // load value to copy -lob: - asm stosb; // copy AL into ES:DI - asm loop lob; // do while CX >0 - asm dec bx; // decrement bx; - - asm cmp bx,100h; - asm jg sk; - asm int 03h; - -sk: - asm cmp bx,0; // see if finished - asm jg loa; // if not then loop - -bot: // bottom of routine - asm pop ds; // restore ds - asm pop es; // restore es - - return; + asm push es; // preserve ES + asm push ds; // preserve DS + asm les di, dest; // move dest into ES:DI + asm lds si, src; // move src into DS:SI + asm mov cx, 0; // clear CX + asm mov bx, src_size; // move counter into BX + + loa: + asm lodsb; // move byte into AL + asm dec bx; // decrement CX + asm cmp al, 0; // compare AL to 0 + asm jl repeat; // if al < 0 jump to repeat + + // copy bytes + asm mov ah, 0; // clear AH + asm inc al; // increment AL + asm mov cl, al; // put value of AL into CL + asm rep movsb; // move CX bytes from DS:SI to ES:DI + asm sub bx, ax; // increment BX by approp value + asm cmp bx, 0; // see if finished + asm jg loa; // if not then loop + asm jmp bot; // else jump to bottom + + repeat: + asm neg al; // negate AL + asm inc al; // increment AL by 1 + asm mov cl, al; // move counter value to CX + asm lodsb; // load value to copy + + lob: + asm stosb; // copy AL into ES:DI + asm loop lob; // do while CX >0 + asm dec bx; // decrement bx; + + asm cmp bx, 100 h; + asm jg sk; + asm int 03 h; + + sk: + asm cmp bx, 0; // see if finished + asm jg loa; // if not then loop + + bot: // bottom of routine + asm pop ds; // restore ds + asm pop es; // restore es + + return; } #endif +/* find and fill REPLAY structure and return 0, or -1 if failed. + * if grp != NULL and oGROUP at offset rep->off[0] is found, then fill grp too + */ +static int +find_replay(REPLAY * rep, struct oGROUP *grp, char player, int num, + const char *type) +{ + FILE *fseq = NULL; + struct oGROUP group; + size_t offset = 0; + int retval = 0; + + assert(rep); + + fseq = sOpen("SEQ.DAT", "rb", 0); + if (!fseq) + return -1; + + if (strncmp("OOOO", type, 4) == 0) + { + FILE *f = sOpen("REPLAY.DAT", "rb", 1); + + offset = (player * 100) + num; + fseek(f, offset * (sizeof *rep), SEEK_SET); + /* TODO: fread_REPLAY(&Rep, 1, f); */ + fread(rep, (sizeof *rep), 1, f); + fclose(f); + if (grp && fseek(fseq, sizeof_oGROUP * rep->Off[0], SEEK_SET) == 0) + fread_oGROUP(grp, 1, fseq); + } + else + { + int j = 0; + + while (fread_oGROUP(&group, 1, fseq)) + { + if (strncmp(group.ID, "XXXX", 4) == 0) + { + /* bad sequence? */ + retval = -1; + goto done; + } + if (strcmp(&group.ID[3], type) == 0) + break; + j++; + } + rep->Qty = 1; + rep->Off[0] = j; + if (grp) + memcpy(grp, &group, sizeof(group)); + } + done: + if (fseq) + fclose(fseq); + + return retval; +} + void Replay(char plr, int num, int dx, int dy, int width, int height, char *Type) { int keep_going; - int i, j, kk, mode, max; + int i, kk, mode, max; FILE *seqf, *fseqf; long offset; struct oGROUP group; struct oFGROUP fgroup; struct Table table; REPLAY Rep; + #ifdef CONFIG_THEORA_VIDEO mm_file vidfile; - char fname[1000]; - float fps; + char fname[1000]; + float fps; #else GXHEADER dopy, snzy; struct frm *frm = NULL; int update_map = 0; #endif + if (find_replay(&Rep, NULL, plr, num, Type) < 0) + return; + seqf = sOpen("SEQ.DAT", "rb", 0); fseqf = sOpen("FSEQ.DAT", "rb", 0); @@ -131,60 +198,18 @@ Replay(char plr, int num, int dx, int dy, int width, int height, char *Type) return; } - if (strncmp("OOOO", Type, 4) == 0) - { - FILE *f = sOpen("REPLAY.DAT", "rb", 1); - - offset = (plr * 100) + num; - fseek(f, offset * (sizeof Rep), SEEK_SET); - /* TODO: fread_REPLAY(&Rep, 1, f); */ - fread(&Rep, sizeof Rep, 1, f); - fclose(f); - } - else - { // Find correct Sequence -#if 0 - bSeq = (struct oGROUP *) &vhptr.vptr[35000]; - fin = sOpen(SEQ_DAT, "rb", 0); - fread_oGROUP(bSeq, (vhptr.h * vhptr.w - 35000) / sizeof_oGROUP, fin); - fclose(fin); - mode = 0; - j = 0; - while (strncmp(bSeq[j].ID, "XXXX", 4) != 0 - && strncmp(&bSeq[j].ID[3], Type, strlen(&bSeq[j].ID[3])) != 0) - j++; - if (strncmp(bSeq[j].ID, "XXXX", 4) == 0) - return; // bad sequence - Rep.Qty = 1; - Rep.Off[0] = j; -#endif - mode = 0; - j = 0; - while (fread_oGROUP(&group, 1, seqf)) - { - if (strncmp(group.ID, "XXXX", 4) == 0) - /* XXX: bad sequence? */ - return; - if (strcmp(&group.ID[3], Type) == 0) - break; - j++; - } - Rep.Qty = 1; - Rep.Off[0] = j; - }; - #ifndef CONFIG_THEORA_VIDEO GV(&snzy, width, height); GV(&dopy, 160, 100); #endif - WaitForMouseUp(); + WaitForMouseUp(); - printf("******\n"); - printf("%d segments\n", Rep.Qty); + /* INFO */ printf("******\n"); + /* INFO */ printf("%d segments\n", Rep.Qty); for (kk = 0; kk < Rep.Qty; kk++) { - printf("segment %d: %d\n", kk, Rep.Off[kk]); + /* INFO */ printf("segment %d: %d\n", kk, Rep.Off[kk]); UpdateMusic(); if (Rep.Off[kk] < 1000) //Specs: success seq { @@ -214,7 +239,7 @@ Replay(char plr, int num, int dx, int dy, int width, int height, char *Type) i = 0; keep_going = 1; - // update_map = 0; + // update_map = 0; while (keep_going && i < max) { int frm_idx; @@ -266,36 +291,37 @@ Replay(char plr, int num, int dx, int dy, int width, int height, char *Type) i++; #else - /* here we should create YUV Overlay, but we can't use it on - * pallettized surface, so we use a global Overlay initialized in - * sdl.c. */ - sprintf(fname, "%s/%s.ogg", movies_dir, seq_filename(frm_idx, mode)); - /* INFO */ printf("mm_open(%s)\n", fname); + /* here we should create YUV Overlay, but we can't use it on + * pallettized surface, so we use a global Overlay initialized in + * sdl.c. */ + sprintf(fname, "%s/%s.ogg", movies_dir, seq_filename(frm_idx, + mode)); + /* INFO */ printf("mm_open(%s)\n", fname); if (mm_open(&vidfile, fname) <= 0) goto done; - /* TODO do not ignore width/height */ - if (mm_video_info(&vidfile, NULL, NULL, &fps) <= 0) - goto done; + /* TODO do not ignore width/height */ + if (mm_video_info(&vidfile, NULL, NULL, &fps) <= 0) + goto done; while (keep_going) { UpdateMusic(); - video_rect.x = dx; - video_rect.y = dy; - video_rect.w = width; - video_rect.h = height; + video_rect.x = dx; + video_rect.y = dy; + video_rect.w = width; + video_rect.h = height; - /* TODO track decoding time and adjust delays */ - if (mm_decode_video(&vidfile, video_overlay) <= 0) - break; + /* TODO track decoding time and adjust delays */ + if (mm_decode_video(&vidfile, video_overlay) <= 0) + break; if (bioskey(0) || grGetMouseButtons()) keep_going = 0; - /* TODO idle_loop is too inaccurate for this */ - idle_loop_secs(1.0 / fps); + /* TODO idle_loop is too inaccurate for this */ + idle_loop_secs(1.0 / fps); } mm_close(&vidfile); @@ -310,116 +336,127 @@ Replay(char plr, int num, int dx, int dy, int width, int height, char *Type) if (frm) frm_close(frm); #else - mm_close(&vidfile); - video_rect.w = 0; - video_rect.h = 0; + mm_close(&vidfile); + video_rect.w = 0; + video_rect.h = 0; #endif fclose(fseqf); fclose(seqf); return; } -void DispBaby(int x, int y, int loc,char neww) +void +DispBaby(int x, int y, int loc, char neww) { - int i; - FILE *fin; - GXHEADER boob; - ui16 *bot,off=0; - long locl; - - off=224; - - GV(&boob,68,46); - bot=(ui16 *) boob.vptr; - - fin=sOpen("BABYPICX.CDR","rb",0); - locl=(long) 1612*loc; // First Image - fseek(fin,locl,SEEK_SET); - for (i=0;i<48;i++) pal[off*3+i]=0; - if (neww) gxSetDisplayPalette(pal); - fread(&pal[off*3],48,1,fin); - fread(boob.vptr,1564,1,fin); - fclose(fin); - - for (i=0;i<782;i++) { - bot[i+782]=((bot[i]&0xF0F0)>>4); - bot[i]=(bot[i]&0x0F0F); - } - for (i=0;i<1564;i++) { - boob.vptr[i]+=off; - boob.vptr[1564+i]+=off; - } - - gxPutImage(&boob,gxSET,x,y,0); - if (neww) gxSetDisplayPalette(pal); - DV(&boob); - - return; + int i; + FILE *fin; + GXHEADER boob; + ui16 *bot, off = 0; + long locl; + + off = 224; + + GV(&boob, 68, 46); + bot = (ui16 *) boob.vptr; + + fin = sOpen("BABYPICX.CDR", "rb", 0); + locl = (long) 1612 *loc; // First Image + + fseek(fin, locl, SEEK_SET); + for (i = 0; i < 48; i++) + pal[off * 3 + i] = 0; + if (neww) + gxSetDisplayPalette(pal); + fread(&pal[off * 3], 48, 1, fin); + fread(boob.vptr, 1564, 1, fin); + fclose(fin); + + for (i = 0; i < 782; i++) + { + bot[i + 782] = ((bot[i] & 0xF0F0) >> 4); + bot[i] = (bot[i] & 0x0F0F); + } + for (i = 0; i < 1564; i++) + { + boob.vptr[i] += off; + boob.vptr[1564 + i] += off; + } + + gxPutImage(&boob, gxSET, x, y, 0); + if (neww) + gxSetDisplayPalette(pal); + DV(&boob); + + return; } -void AbzFrame(char plr,int num,int dx,int dy,int width,int height,char *Type,char mde) +void +AbzFrame(char plr, int num, int dx, int dy, int width, int height, + char *Type, char mode) { - int j; - FILE *fin,*kfin; - long offset; - struct oGROUP *bSeq,aSeq; - char *SEQ_DAT="SEQ.DAT\0"; - REPLAY Rep; - GXHEADER dopy,snzy; - struct frm *frm; - - bSeq=(struct oGROUP *)&vhptr.vptr[35000]; - j = 0; - - GV(&snzy,width,height); - GV(&dopy,160,100); - - if (mde)EMPTY_BODY; - - fin=sOpen(SEQ_DAT,"rb",0); - offset = fread(&vhptr.vptr[35000],1,vhptr.h*vhptr.w-35000,fin); - fclose(fin); - - if (strncmp("OOOO",Type,4)==0) { - kfin=sOpen("REPLAY.DAT","rb",1); - offset=(plr*100)+num; - fseek(kfin,offset * (sizeof Rep),SEEK_SET); - fread(&Rep,sizeof Rep,1,kfin); - fclose(kfin); - } - else { // Find correct Sequence - j=0; - while ( strncmp(bSeq[j].ID,"XXXX",4)!=0 && strncmp(&bSeq[j].ID[3],Type,strlen(&bSeq[j].ID[3]))!=0 ) - j++; - if (strncmp(bSeq[j].ID,"XXXX",4)==0) goto done; // bad sequence - Rep.Qty=1; - Rep.Off[0]=j; - } - - if (strncmp(bSeq[j].ID,"XXXX",4)==0) goto done; - memcpy(&aSeq,&bSeq[Rep.Off[0]].ID[0],sizeof aSeq); - - - - if ((frm = frm_open_seq (aSeq.oLIST[0].aIdx, 0)) != NULL) { - frm_get2 (frm, dopy.vptr, &pal[384]); - frm_close (frm); - } else { - memset (dopy.vptr, 0, 160 * 100); - memset (&pal[384], 0, 384); - } - - gxVirtualScale(&dopy,&snzy); - - VBlank(); - RectFill(dx,dy,dx+width,dy+height-1,0); - gxPutImage(&snzy,gxSET,dx,dy,0); - - -done: - DV(&dopy);DV(&snzy); - return; -} + int idx = 0; + struct oGROUP grp; + REPLAY Rep; + /* force mode to zero */ + mode = 0; +#ifndef CONFIG_THEORA_VIDEO + GXHEADER dopy, snzy; + struct frm *frm; +#else + char fname[100]; + mm_file vidfile; +#endif + + memset(&grp, 0, sizeof grp); + if (find_replay(&Rep, &grp, plr, num, Type) < 0) + return; + + idx = grp.oLIST[0].aIdx; + +#ifndef CONFIG_THEORA_VIDEO + GV(&snzy, width, height); + GV(&dopy, 160, 100); + + if ((frm = frm_open_seq(idx, mode)) != NULL) + { + frm_get2(frm, dopy.vptr, &pal[384]); + frm_close(frm); + } + else + { + memset(dopy.vptr, 0, 160 * 100); + memset(&pal[384], 0, 384); + } + + gxVirtualScale(&dopy, &snzy); + VBlank(); + RectFill(dx, dy, dx + width, dy + height - 1, 0); + gxPutImage(&snzy, gxSET, dx, dy, 0); + + DV(&dopy); + DV(&snzy); +#else + sprintf(fname, "%s/%s.ogg", movies_dir, seq_filename(idx, mode)); + + /* INFO */ printf("mm_open(%s)\n", fname); + if (mm_open(&vidfile, fname) <= 0) + return; + + if (mm_video_info(&vidfile, NULL, NULL, NULL) <= 0) + goto done; + + if (mm_decode_video(&vidfile, video_overlay) <= 0) + goto done; + + video_rect.x = dx; + video_rect.y = dy; + video_rect.w = width; + video_rect.h = height; + + done: + mm_close(&vidfile); +#endif +} diff --git a/review.c b/review.c index b5abf8d..37ee4e5 100644 --- a/review.c +++ b/review.c @@ -24,6 +24,7 @@ // // Review Main Files +#include "gamedata.h" #include "Buzz_inc.h" #include "externs.h" @@ -196,9 +197,8 @@ void PresPict(char poff) SimpleHdr table; FILE *in; in=sOpen("PRESR.BUT","rb",0); - 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(&pal[96],672,1,in); fread(buffer,table.size,1,in); diff --git a/version.c b/version.c index e712d32..026933d 100644 --- a/version.c +++ b/version.c @@ -1,2 +1,2 @@ -125 +126