From a1effa1c42450312879db9f0fa6e34d52c9235be Mon Sep 17 00:00:00 2001 From: Egor Date: Sat, 14 Apr 2018 20:08:22 +0300 Subject: [PATCH] [th02/th03] Rebuild ZUN.COM Two DOS utilities were made for this: - gensize: generates TASM macro definitions with filesizes. - copycat: similar to copy/b a+b+c d, except a+b+c is specified in a separate file to avoid command line length limitations. th02/zun.com is bit-perfect th03/zun.com is almost there, with insignificant differences in zunsp.com and res_yume.com. --- .gitignore | 5 +- Makefile.mak | 48 +++++++++++- zuncom/copycat.c | 68 ++++++++++++++++ zuncom/gensize.c | 35 +++++++++ zuncom/moveup.asm | 11 +++ zuncom/zun_stub.asm | 187 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 351 insertions(+), 3 deletions(-) create mode 100644 zuncom/copycat.c create mode 100644 zuncom/gensize.c create mode 100644 zuncom/moveup.asm create mode 100644 zuncom/zun_stub.asm diff --git a/.gitignore b/.gitignore index 471a3621..a99baa03 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -bin/th* \ No newline at end of file +bin/th* +bin/TH* +bin/zuncom +bin/ZUNCOM diff --git a/Makefile.mak b/Makefile.mak index 52c5848e..4a8d0868 100644 --- a/Makefile.mak +++ b/Makefile.mak @@ -5,8 +5,8 @@ CFLAGS = -ls -Ilibs\master.lib\ -I. -Lbin\ -O -a2 TH01 = \zunsoft.com \op.exe \reiiden.exe \fuuin.exe -TH02 = \zuninit.com \zun_res.com \op.exe \main.exe \maine.exe -TH03 = \zunsp.com \res_yume.com \op.exe \main.exe \mainl.exe +TH02 = \zuninit.com \zun_res.com \op.exe \main.exe \maine.exe \zun.com +TH03 = \zunsp.com \res_yume.com \op.exe \main.exe \mainl.exe \zun.com TH04 = \res_huma.com \op.exe \main.exe \maine.exe TH05 = \res_kso.com \op.exe \main.exe \maine.exe @@ -72,3 +72,47 @@ bin\th04\op.exe: bin\th04\op.obj th04\op_02.c $(CC) $(CFLAGS) -ml -DGAME=4 -nbin\th04\ -eOP.EXE @&&| $** | + +# ZUN.COM packing + +bin\zuncom\gensize.com: zuncom\gensize.c + mkdir bin\zuncom + $(CC) $(CFLAGS) -mt -lt -nbin\zuncom\ -eGENSIZE.COM $** + +bin\zuncom\copycat.com: zuncom\copycat.c + mkdir bin\zuncom + $(CC) $(CLFAGS) -mt -lt -nbin\zuncom\ -eCOPYCAT.COM $** + +bin\zuncom\moveup.bin: zuncom\moveup.asm + mkdir bin\zuncom + tasm zuncom\moveup.asm,bin\zuncom\moveup + tlink -t bin\zuncom\moveup.obj,bin\zuncom\moveup.bin + +ZUNCOM_PREREQ = bin\zuncom\gensize.com bin\zuncom\copycat.com zuncom\zun_stub.asm bin\zuncom\moveup.bin + +bin\th02\zun.com : $(ZUNCOM_PREREQ) libs\kaja\ongchk.com bin\th02\zuninit.com bin\th02\zun_res.com bin\th01\zunsoft.com + bin\zuncom\gensize.com > bin\zuncom\gensize.inc + tasm -DGAME=2 zuncom\zun_stub.asm,bin\th02\zun_stub + tlink -t bin\th02\zun_stub.obj,bin\th02\zun_stub.bin + bin\zuncom\copycat &&| +bin\th02\zun_stub.bin +libs\kaja\ongchk.com +bin\th02\zuninit.com +bin\th02\zun_res.com +bin\th01\zunsoft.com +bin\zuncom\moveup.bin +| bin\th02\zun.com + +bin\th03\zun.com : $(ZUNCOM_PREREQ) libs\kaja\ongchk.com bin\th02\zuninit.com bin\th01\zunsoft.com bin\th03\zunsp.com bin\th03\res_yume.com + bin\zuncom\gensize.com > bin\zuncom\gensize.inc + tasm -DGAME=3 zuncom\zun_stub.asm,bin\th03\zun_stub + tlink -t bin\th03\zun_stub.obj,bin\th03\zun_stub.bin + bin\zuncom\copycat &&| +bin\th03\zun_stub.bin +libs\kaja\ongchk.com +bin\th02\zuninit.com +bin\th01\zunsoft.com +bin\th03\zunsp.com +bin\th03\res_yume.com +bin\zuncom\moveup.bin +| bin\th03\zun.com diff --git a/zuncom/copycat.c b/zuncom/copycat.c new file mode 100644 index 00000000..31ffe14c --- /dev/null +++ b/zuncom/copycat.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include + +int main(int argc, char** argv) { + static char path[MAXPATH+1]; + static char cluster[512]; + + FILE *fl, *fi, *fo; + size_t bytesread,byteswrite; + char *pathp; + + if(argc != 3) { + printf("Usage: copycat listfile.txt outfile.bin\n"); + return 1; + } + fl = fopen(argv[1],"r"); + if(!fl) { + printf("Error: couldn't open listfile: %s\n", strerror(errno)); + return 2; + } + fo = fopen(argv[2],"wb"); + if(!fo) { + fclose(fl); + printf("Error: couldn't open outfile: %s\n", strerror(errno)); + return 3; + } + + for(;!feof(fl);) { + if(!fgets(path, sizeof(path), fl)) break; + if(*path) { + pathp = path+strlen(path)-1; + if(*pathp == '\n') *pathp = '\0'; + } + if(*path) { + fi = fopen(path, "rb"); + if(!fi) { + fclose(fo); + fclose(fl); + printf("Error: couldn't open inputfile '%s': %s", path, strerror(errno)); + return 4; + } + while(!feof(fi)) { + bytesread = fread(cluster, 1, sizeof(cluster), fi); + if(bytesread) { + byteswrite = fwrite(cluster, 1, bytesread, fo); + if(byteswrite != bytesread) { + fclose(fi); + fclose(fo); + fclose(fl); + printf("Error: write error\n"); + return 5; + } + } + } + fclose(fi); + fflush(fo); + } + } + fclose(fl); + if(fclose(fo)) { + printf("Error: unsuccessful close\n"); + return 6; + } + return 0; +} diff --git a/zuncom/gensize.c b/zuncom/gensize.c new file mode 100644 index 00000000..9ede5f97 --- /dev/null +++ b/zuncom/gensize.c @@ -0,0 +1,35 @@ +#include +#include +#include + +struct { + const char path[13*3]; // up to 2 subdirectories + const char symbol[10]; // filename + optional number +} paths[] = { + {"libs/kaja/ongchk.com", "ONGCHK"}, + {"bin/th01/zunsoft.com", "ZUNSOFT"}, + {"bin/th02/zuninit.com", "ZUNINIT2"}, + {"bin/th02/zun_res.com", "ZUN_RES"}, + {"bin/th03/zunsp.com", "ZUNSP"}, + {"bin/th03/res_yume.com", "RES_YUME"}, + {"bin/th04/zuninit.com", "ZUNINIT4"}, + {"bin/th04/res_huma.com", "RES_HUMA"}, + {"bin/th04/memchk.com", "MEMCHK4"}, + {"bin/th05/zuninit.com", "ZUNINIT5"}, + {"bin/th05/res_kso.com", "RES_KSO"}, + {"bin/th05/gjinit.com", "GJINIT"}, + {"bin/th05/memchk.com", "MEMCHK5"}, +}; +#define PATHS_COUNT (sizeof(paths)/sizeof(paths[0])) +#define SYMBOL_PREFIX "GENSIZE_" + +int main() { + struct ffblk ff; + int i; + for(i=0;i