[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.
This commit is contained in:
Egor 2018-04-14 20:08:22 +03:00
parent 88fdde46b1
commit a1effa1c42
6 changed files with 351 additions and 3 deletions

5
.gitignore vendored
View File

@ -1 +1,4 @@
bin/th*
bin/th*
bin/TH*
bin/zuncom
bin/ZUNCOM

View File

@ -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

68
zuncom/copycat.c Normal file
View File

@ -0,0 +1,68 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <dir.h>
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;
}

35
zuncom/gensize.c Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <dir.h>
#include <dos.h>
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<PATHS_COUNT;i++) {
if(!findfirst(paths[i].path,&ff,FA_NORMAL)) {
printf(SYMBOL_PREFIX "%s=%ld\n",paths[i].symbol,ff.ff_fsize);
}
}
return 0;
}

11
zuncom/moveup.asm Normal file
View File

@ -0,0 +1,11 @@
.8086
.model tiny
.code
org 100h ;doesn't matter, needed for linker
moveup:
rep movsb
pop ax
mov ax, 100h
push ax
retn
END moveup

187
zuncom/zun_stub.asm Normal file
View File

@ -0,0 +1,187 @@
.8086
.model tiny
.code
org 100h
start:
jmp short entry
var102 dw 0
aNoComSoft db 'No COM-Soft !!!',13,10,10,'$'
entry:
cld
mov cx, word ptr proc_count
or cx, cx
jz short error
mov si, 80h
lodsb
or al, al
jz short print_procs
@scanargs:
lodsb
cmp al, 13
jz short print_procs
cmp al, 32
jz short @scanargs
jmp short findentry
; Outputs names of all embedded COM files and then exits
print_procs:
mov cx, word ptr proc_count
mov si, offset proc_names
mov dl, 13
mov ah, 2 ; INT=21/AH=02h - WRITE CHARACTER TO STANDARD OUTPUT
int 21h
mov dl, 10
int 21h
@outerloop:
push cx
mov dl, 32
int 21h
mov cx, 8
@innerloop:
lodsb
mov dl, al
int 21h
loop @innerloop
mov dl, 32
int 21h
pop cx
loop @outerloop
mov dl, 13
int 21h
mov dl, 10
int 21h
mov ah, 4Ch ; INT=21/AH=4Ch - TERMINATE WITH RETURN CODE
int 21h
; ---------------------------------------------------------------------------
findentry:
mov bx, offset proc_entries
mov cx, word ptr proc_count
mov si, offset proc_names
@loop:
mov word ptr var102, si
mov di, 5Dh ; Standard FCB 1 filename
push cx
mov cx, 8
repe cmpsb
jz short fixup
add bx, 2
mov si, word ptr var102
add si, 8
pop cx
loop @loop
error:
mov dx, offset aNoComSoft
mov ah, 9 ; INT=21/AH=09h - WRITE STRING TO STANDARD OUTPUT
int 21h
mov ah, 4Ch ; INT=21/AH=4Ch - TERMINATE WITH RETURN CODE
int 21h
; ---------------------------------------------------------------------------
; Fixup FCB and args before continuing
; BX points to the entry in proc_entries
fixup:
; Copy FCB 2 into FCB 1
mov di, 5Ch
mov si, 6Ch
mov cx, 10h
rep movsb
; Move arguments
mov si, 80h
lodsb
mov dl, al
@skipspace:
lodsb
dec dl
cmp al, 32
jz short @skipspace
@skipnonspace:
lodsb
dec dl
cmp al, 13
jz short @moveargs
cmp al, 32
jnz short @skipnonspace
@moveargs:
inc dl
mov di, 80h
mov al, dl
stosb
or dl,dl
jz short @emptyargs
dec si
mov cl, dl
xor ch, ch
rep movsb
@emptyargs:
mov byte ptr [di], 13
; setup registers for moventry
mov ax, [bx]
mov cx, [bx+2]
mov si, ax
sub cx, ax
mov di, 100h
jmp moveup_indirect
; ---------------------------------------------------------------------------
include bin\zuncom\gensize.inc
IF GAME EQ 2
proc_count dw 4
proc_names db 'ONGCHK '
db 'ZUNINIT '
db 'ZUN_RES '
db 'ZUNSOFT '
db 28 dup(' ')
proc_entries dw offset ongchk
dw offset zuninit
dw offset zun_res
dw offset zunsoft
dw offset moveup ; last entry points to moveup
dw 28 dup(0)
moveup_indirect:
call moveup
ongchk: org $+GENSIZE_ONGCHK
zuninit: org $+GENSIZE_ZUNINIT2
zun_res: org $+GENSIZE_ZUN_RES
zunsoft: org $+GENSIZE_ZUNSOFT
ELSEIF GAME EQ 3
proc_count dw 5
proc_names db '-1 '
db '-2 '
db '-3 '
db '-4 '
db '-5 '
db 27 dup(' ')
proc_entries dw offset ongchk
dw offset zuninit
dw offset zunsoft
dw offset zunsp
dw offset res_yume
dw offset moveup ; last entry points to moveup
dw 27 dup(0)
moveup_indirect:
call moveup
ongchk: org $+GENSIZE_ONGCHK
zuninit: org $+GENSIZE_ZUNINIT2
zunsoft: org $+GENSIZE_ZUNSOFT
zunsp: org $+GENSIZE_ZUNSP
res_yume: org $+GENSIZE_RES_YUME
ENDIF
; ---------------------------------------------------------------------------
moveup: ; the following code is split into moveup.asm
;rep movsb
;pop ax
;mov ax, 100h
;push ax
;retn
; ---------------------------------------------------------------------------
END start