[comp.sources.wanted] Core wars 2 part02

sbarr@hawk.ulowell.edu (bot man) (05/31/90)

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 2 (of 2)."
# Contents:  Makefile Makefile.sun aoutput.c assem.c bomb.rc chang1.rc
#   commando.rc dwarf.rc dwarfgun.rc gemini.rc imp.rc impstomp.rc
#   interp.c interp.h mice.rc selfcpy.rc sit.rc test.c testspl.rc
# Wrapped by billr@saab on Mon Feb 13 10:40:12 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(1010 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
Xall: assem disassem interp
X
XASM_OBJ = amain.o tokenize.o parse.o lookup.o aoutput.o assem.o
X
X# Standard curses version of interpreter
XINT_OBJ = main.o load.o output.o play.o inst.o
XLIBS = -lcurses -ltermcap
X
X# Sun version using pixrect lib of interpreter
XSINT_OBJ = main.o load.o output.o play.o inst.o interface2.o
XSLIBS = -lcurses -ltermcap -lpixrect
X
X# Define one of DEBUG, SMALL, SUN or BIG (BIG is buggy)
XCFLAGS = -O -DSMALL
X
Xassem: $(ASM_OBJ)
X	cc -o assem $(ASM_OBJ)
X
Xdisassem: disassem.c assem.h
X	cc -O disassem.c -o disassem
X
X# Standard version
Xinterp: $(INT_OBJ)
X	cc -o interp  $(INT_OBJ) $(LIBS)
X
X# Sun pixrect version
X#interp: $(SINT_OBJ)
X#	cc -o interp  $(SINT_OBJ) $(SLIBS)
X
Xamain.o: amain.c assem.h
Xtokenize.o: tokenize.c assem.h
Xparse.o: parse.c assem.h
Xlookup.o: lookup.c assem.h
Xoutput.o: aoutput.c assem.h
Xassem.o: assem.c assem.h
X
Xmain.o:	main.c interp.h
Xload.o: load.c interp.h
Xoutput.o: output.c interp.h
Xplay.o: play.c interp.h
Xinst.o: inst.c interp.h
Xinterface2.o: interface2.c interp.h
END_OF_FILE
if test 1010 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'Makefile.sun' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile.sun'\"
else
echo shar: Extracting \"'Makefile.sun'\" \(1008 characters\)
sed "s/^X//" >'Makefile.sun' <<'END_OF_FILE'
Xall: assem disassem interp
X
XASM_OBJ = amain.o tokenize.o parse.o lookup.o aoutput.o assem.o
X
X# Standard curses version of interpreter
XINT_OBJ = main.o load.o output.o play.o inst.o
XLIBS = -lcurses -ltermcap
X
X# Sun version using pixrect lib of interpreter
XSINT_OBJ = main.o load.o output.o play.o inst.o interface2.o
XSLIBS = -lcurses -ltermcap -lpixrect
X
X# Define one of DEBUG, SMALL, SUN or BIG (BIG is buggy)
XCFLAGS = -O -DSUN
X
Xassem: $(ASM_OBJ)
X	cc -o assem $(ASM_OBJ)
X
Xdisassem: disassem.c assem.h
X	cc -O disassem.c -o disassem
X
X# Standard version
X#interp: $(INT_OBJ)
X#	cc -o interp  $(INT_OBJ) $(LIBS)
X
X# Sun pixrect version
Xinterp: $(SINT_OBJ)
X	cc -o interp  $(SINT_OBJ) $(SLIBS)
X
Xamain.o: amain.c assem.h
Xtokenize.o: tokenize.c assem.h
Xparse.o: parse.c assem.h
Xlookup.o: lookup.c assem.h
Xoutput.o: aoutput.c assem.h
Xassem.o: assem.c assem.h
X
Xmain.o:	main.c interp.h
Xload.o: load.c interp.h
Xoutput.o: output.c interp.h
Xplay.o: play.c interp.h
Xinst.o: inst.c interp.h
Xinterface2.o: interface2.c interp.h
END_OF_FILE
if test 1008 -ne `wc -c <'Makefile.sun'`; then
    echo shar: \"'Makefile.sun'\" unpacked with wrong size!
fi
# end of 'Makefile.sun'
fi
if test -f 'aoutput.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'aoutput.c'\"
else
echo shar: Extracting \"'aoutput.c'\" \(1140 characters\)
sed "s/^X//" >'aoutput.c' <<'END_OF_FILE'
X/*	Copyrighted (C) 1989 by Na Choon Piaw.  All rights reserved       */
X
X
X
X/*	This program and documentation is Public Domain, and may be	  */
X/*	distributed and copied by everyone provided this header		  */
X/*	remains intact							  */
X
X/* output.c --- output routine for the asssembler.
X   11/25/88  --- NCP                             */
X
X/* algorithm:
X   1.	write number of instructions into file
X   2.	write code number of start instruction
X   3.	while there are still instructions do
X   4.		write instruction n
X   5.   end
X*/
X#include "assem.h"
X#include <stdio.h>
X
X#define IO(i,j) if ((i) < (j)) { printf("error in writing file  --- output\n" \
X				 ); }
X
Xoutput(f, table, code, no)
XFILE	*f;		/* file to output to */
Xtag1	table[];	/* table of symbols */
Xmemory	code[];		/* code itself */
Xint	no;		/* number of instructions */
X{
X	int	check,	/* check on how many bytes have been written */
X		start;	/* starting instruction */
X
X	check = fwrite(&no, sizeof(int), 1, f);
X	IO(check,1)
X
X	start = getsym("START",table);
X	check = fwrite(&start, sizeof(int), 1, f);
X	IO(check,1);
X
X	check = fwrite(code, sizeof(memory), no, f);
X	IO(check,no);
X}
END_OF_FILE
if test 1140 -ne `wc -c <'aoutput.c'`; then
    echo shar: \"'aoutput.c'\" unpacked with wrong size!
fi
# end of 'aoutput.c'
fi
if test -f 'assem.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'assem.c'\"
else
echo shar: Extracting \"'assem.c'\" \(1394 characters\)
sed "s/^X//" >'assem.c' <<'END_OF_FILE'
X/*	Copyrighted (C) 1989 by Na Choon Piaw.  All rights reserved       */
X
X
X
X/*	This program and documentation is Public Domain, and may be	  */
X/*	distributed and copied by everyone provided this header		  */
X/*	remains intact							  */
X
X/* assembler portion of the program */
X/* 11/14 '88
X  Implementing a one-pass "text in memory" assembler that handle tokens
X  as well.  Symbol table is a linear table.
X   Algorithm:
X	1)	Tokenize the input file (i.e. produce a list of symbols in mem)
X	2)	Run through once, parsing instructions but not turning
X		into machine code yet.  Insert all new symbols into symbol
X		table.
X	3)	Run through second time,  turning it into machine code
X		and looking up symbols.  -- the real error phase.
X*/
X#include <stdio.h>
X#include <malloc.h>
X#include "assem.h"
X
X/* symbol table */
Xstatic tag1	table[SYMBOLS];
X
X/* instructions list */
Xstatic memory	elements[MAXINST];
X
X/* declaring the functions */
Xtokenlist	*tokenize();
X
X/* top level connections for assembler hooks up tokenize, parse, lookup
X   and output so that they can be written independently (no global
X   variables in this program                                         */
Xassemble(infile, outfile)
XFILE	*infile,*outfile;
X{
X	tokenlist	*head;
X	int		i;		/* number of instructions */
X
X	head = tokenize(infile);
X	parse(head, table);
X	i = lookup(head, table, elements);
X	output(outfile, table, elements, i);
X}
X
END_OF_FILE
if test 1394 -ne `wc -c <'assem.c'`; then
    echo shar: \"'assem.c'\" unpacked with wrong size!
fi
# end of 'assem.c'
fi
if test -f 'bomb.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'bomb.rc'\"
else
echo shar: Extracting \"'bomb.rc'\" \(52 characters\)
sed "s/^X//" >'bomb.rc' <<'END_OF_FILE'
Xstart:
Xmov	#0	@ptr
Xadd	#1	ptr
Xjmp	start
Xptr:	dat	#1
END_OF_FILE
if test 52 -ne `wc -c <'bomb.rc'`; then
    echo shar: \"'bomb.rc'\" unpacked with wrong size!
fi
# end of 'bomb.rc'
fi
if test -f 'chang1.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'chang1.rc'\"
else
echo shar: Extracting \"'chang1.rc'\" \(201 characters\)
sed "s/^X//" >'chang1.rc' <<'END_OF_FILE'
X; chang 1 corewars program
X	mov	#0	-1
X	jmp	-1 ;;nothing
X	dat		+9	;complete tester
Xstart:	spl	-2
X	spl	4
X	add	#-16	-3	; nothing
X	mov	#5	@-4
Xhelp:	jmp	-4
X	spl	2
X	jmp	-1
Xfinish: next: odd:	mov	0	1
Xfinito:
END_OF_FILE
if test 201 -ne `wc -c <'chang1.rc'`; then
    echo shar: \"'chang1.rc'\" unpacked with wrong size!
fi
# end of 'chang1.rc'
fi
if test -f 'commando.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'commando.rc'\"
else
echo shar: Extracting \"'commando.rc'\" \(279 characters\)
sed "s/^X//" >'commando.rc' <<'END_OF_FILE'
X;;; an implementation of a k dewdney's commando program
X
Xcount:	dat	#14
Xptr:	dat	#200
Ximps:	mov	#0	-1	; imp stomper
X	jmp	imps
X	mov	#14	count
X	mov	#100	ptr
Xstart:	mov	imp	1000
X	spl	999
Xloop:	mov	@count	@ptr
X	sub	#1	ptr
X	djn	loop	count
X	add	#4	ptr
X	spl	@ptr
X	jmp	imps
Ximp:	mov	0	1
END_OF_FILE
if test 279 -ne `wc -c <'commando.rc'`; then
    echo shar: \"'commando.rc'\" unpacked with wrong size!
fi
# end of 'commando.rc'
fi
if test -f 'dwarf.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dwarf.rc'\"
else
echo shar: Extracting \"'dwarf.rc'\" \(43 characters\)
sed "s/^X//" >'dwarf.rc' <<'END_OF_FILE'
X dat	-1
Xstart: add	#5	-1
Xmov	#0	@-2
XJMP	-2
END_OF_FILE
if test 43 -ne `wc -c <'dwarf.rc'`; then
    echo shar: \"'dwarf.rc'\" unpacked with wrong size!
fi
# end of 'dwarf.rc'
fi
if test -f 'dwarfgun.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dwarfgun.rc'\"
else
echo shar: Extracting \"'dwarfgun.rc'\" \(549 characters\)
sed "s/^X//" >'dwarfgun.rc' <<'END_OF_FILE'
X;;; dwarfgun program.
X;;; Choon Piaw
Xstomp:	mov	#0	-1
X	jmp	stomp
Xstart:	spl	init
X	jmp	stomp
Xcount:  dat	#4
Xptr:	dat	#500
X
X;;;; dwarf part
X
Xdwf:	dat	#5000
Xloop:	mov	#0	@dwf
X	djn	loop	dwf
X;;; initialization
Xinit:	mov	#-200	ptr2
X	mov	#0	count2
X	mov	#500	ptr
X	mov	#4	count
X;;; dwarf copy part
Xdwfcp:	mov	@count	@ptr
X	sub	#1	ptr
X	djn	dwfcp	count
X	add	#3	ptr
X	spl	@ptr		; leave dwarf running.
X;;;; copy self upstream
Xselfcp:	mov	@count2	@ptr2
X	sub	#1	count2
X	sub	#1	ptr2
X	cmp	count2	#-27
X	jmp	selfcp
X	add	#3	ptr2
X	jmp	@ptr2
Xptr2:	dat	#-200
Xcount2:	dat	#0
END_OF_FILE
if test 549 -ne `wc -c <'dwarfgun.rc'`; then
    echo shar: \"'dwarfgun.rc'\" unpacked with wrong size!
fi
# end of 'dwarfgun.rc'
fi
if test -f 'gemini.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'gemini.rc'\"
else
echo shar: Extracting \"'gemini.rc'\" \(95 characters\)
sed "s/^X//" >'gemini.rc' <<'END_OF_FILE'
Xdat	#0
Xdat	#99
Xstart:	mov	@-2	@-1
Xcmp	-3	#9
Xjmp	4
Xadd	#1	-5
Xadd	#1	-5
Xjmp	-5
Xmov	#99	93
Xjmp	93
END_OF_FILE
if test 95 -ne `wc -c <'gemini.rc'`; then
    echo shar: \"'gemini.rc'\" unpacked with wrong size!
fi
# end of 'gemini.rc'
fi
if test -f 'imp.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'imp.rc'\"
else
echo shar: Extracting \"'imp.rc'\" \(15 characters\)
sed "s/^X//" >'imp.rc' <<'END_OF_FILE'
Xstart: mov	0	1
END_OF_FILE
if test 15 -ne `wc -c <'imp.rc'`; then
    echo shar: \"'imp.rc'\" unpacked with wrong size!
fi
# end of 'imp.rc'
fi
if test -f 'impstomp.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'impstomp.rc'\"
else
echo shar: Extracting \"'impstomp.rc'\" \(28 characters\)
sed "s/^X//" >'impstomp.rc' <<'END_OF_FILE'
Xstart:	mov	#0	-1
X	jmp start
END_OF_FILE
if test 28 -ne `wc -c <'impstomp.rc'`; then
    echo shar: \"'impstomp.rc'\" unpacked with wrong size!
fi
# end of 'impstomp.rc'
fi
if test -f 'interp.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'interp.c'\"
else
echo shar: Extracting \"'interp.c'\" \(0 characters\)
sed "s/^X//" >'interp.c' <<'END_OF_FILE'
END_OF_FILE
if test 0 -ne `wc -c <'interp.c'`; then
    echo shar: \"'interp.c'\" unpacked with wrong size!
fi
# end of 'interp.c'
fi
if test -f 'interp.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'interp.h'\"
else
echo shar: Extracting \"'interp.h'\" \(961 characters\)
sed "s/^X//" >'interp.h' <<'END_OF_FILE'
X/* MARS redcode interpreter:
X	Header file
X	Started December '88
X	Na Choon Piaw		*/
X
X/* instruction set */
Xtypedef enum { dat, mov, add, sub, jmp, jmz, jmn, djn, cmp, spl } instr;
X
X/* addressing modes */
Xtypedef enum { immed, direct, indirect } mode;
X
X/* this is the new definition of a memory cell */
Xtypedef struct
X{
X	instr	inst;		/* instruction */
X	int	para1, para2;	/* first parameter, second parameter */
X	mode	m1, m2;		/* addressing modes */
X	int	lastmod;	/* last modified by */
X} cell;
X
X/* old assembler definition of memory cell */
Xtypedef struct
X{
X	instr	inst;
X	int	para1, para2;
X	mode	m1, m2;
X} memory;
X
X/* doubly circularly linked list for streams of execution */
Xtypedef struct tag0
X{
X	int		pc;	/* program counter */
X	struct tag0	*next, *prev;
X} stream;
X
X/* interpreter limits */
X#define MAXINST	200		/* maximum number of instructions */
X#define SIZE	8000		/* size of array */
X#define MAXPLAY	3		/* maximum number of players */
X#define RANDIVISOR 33
END_OF_FILE
if test 961 -ne `wc -c <'interp.h'`; then
    echo shar: \"'interp.h'\" unpacked with wrong size!
fi
# end of 'interp.h'
fi
if test -f 'mice.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mice.rc'\"
else
echo shar: Extracting \"'mice.rc'\" \(232 characters\)
sed "s/^X//" >'mice.rc' <<'END_OF_FILE'
X; mouse program --- The First Core War tournament
X
Xptr:	dat	#0		;hell
Xstart:	mov	#9	ptr	;you
Xloop:	mov	@ptr	@7	;know
X	sub	#1	6
X	djn	loop	ptr	;i hate testing
X	add	#1	4
X	spl	@3		;assemblers
X	add	#653	2	;like
X	jmz	-7	-8	;this
X	dat	833
END_OF_FILE
if test 232 -ne `wc -c <'mice.rc'`; then
    echo shar: \"'mice.rc'\" unpacked with wrong size!
fi
# end of 'mice.rc'
fi
if test -f 'selfcpy.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'selfcpy.rc'\"
else
echo shar: Extracting \"'selfcpy.rc'\" \(164 characters\)
sed "s/^X//" >'selfcpy.rc' <<'END_OF_FILE'
Ximps:	mov	#0	-1
X	jmp	imps
Xstart:	spl	imps
X	jmp	loop
Xcount:	dat	#7
Xptr:	dat	#57
X	mov	#7	count
X	mov	#57	ptr
Xloop:	mov	@count	@ptr
X	sub	#1	ptr
X	djn	loop	count
X	jmp	46
END_OF_FILE
if test 164 -ne `wc -c <'selfcpy.rc'`; then
    echo shar: \"'selfcpy.rc'\" unpacked with wrong size!
fi
# end of 'selfcpy.rc'
fi
if test -f 'sit.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sit.rc'\"
else
echo shar: Extracting \"'sit.rc'\" \(17 characters\)
sed "s/^X//" >'sit.rc' <<'END_OF_FILE'
Xstart: jmp start
END_OF_FILE
if test 17 -ne `wc -c <'sit.rc'`; then
    echo shar: \"'sit.rc'\" unpacked with wrong size!
fi
# end of 'sit.rc'
fi
if test -f 'test.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'test.c'\"
else
echo shar: Extracting \"'test.c'\" \(104 characters\)
sed "s/^X//" >'test.c' <<'END_OF_FILE'
Xmain()
X{
X	int	i, j;
X
X	for (i = 0; i <8000;)
X	{
X		for (j = 0; j < 10; j++, i++)
X			printf("%d", j);
X	}
X}
END_OF_FILE
if test 104 -ne `wc -c <'test.c'`; then
    echo shar: \"'test.c'\" unpacked with wrong size!
fi
# end of 'test.c'
fi
if test -f 'testspl.rc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'testspl.rc'\"
else
echo shar: Extracting \"'testspl.rc'\" \(51 characters\)
sed "s/^X//" >'testspl.rc' <<'END_OF_FILE'
Xstart: spl after
X	mov	#0	-3
X	jmp -1
Xafter: mov 0 1
END_OF_FILE
if test 51 -ne `wc -c <'testspl.rc'`; then
    echo shar: \"'testspl.rc'\" unpacked with wrong size!
fi
# end of 'testspl.rc'
fi
echo shar: End of archive 2 \(of 2\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0