Core Wars ST Core Wars ST is an implementation of the program A. K. Dewdney describes in the "Computer Recreations" column of Scientific American in the May 1984, March 1985, and January 1987 issues. It includes the protect and split command. It also lets you run up to 3 programs at once. In Core Wars, each player writes a program with which they attempt to destroy the other player's program. Each program is placed at a random place in a 10,000 location circular area of memory called core. The programs are written in a simple language called REDCODE. Each instruction takes one location in core. In Core wars there are no absolute memory locations; everything is relative. For example, JMP 4 jumps forward 4 locations, not to location 4. A program dies if it tries to execute a DAT statement. The REDCODE instructions are: Instruction Mnemonic Arguments Explanation Move MOV A B Move contents of address A to address B. Add ADD A B Add contents of address A to address B. Subtract SUB A B Subtracts contents of address A from address B. Jump JMP A Transfer control to address A. Jump if zero JMZ A B Jump to A if the contents of address B are 0. Jump if JMG A B Jump to A if the contents of greater than address B are greater than 0. zero Decrement: DJZ A B Subtract 1 from the contents jump if zero of address B and jump to A if B is now zero. Decrement: DJN A B Subtract 1 from the contents jump if not of address B and jump to A if zero B is not zero. Compare CMP A B Skip the next instruction if the contents of address A equal the contents of address B. Split SPL A Split execution to the next instruction and address A. Protect PCT A Protect address A against the next MOV instruction Data DAT B A nonexecutable statement There are 4 different types of addressing modes: The direct mode is the default mode, where the argument is taken as an offset from the current address. For example, JMP -3 will jump backwards 3 locations. The indirect mode is denoted by the "@" symbol. The indicated relative address contains another relative address in the B argument. The DWARF program is a good example of the indirect addressing mode. DAT #-1 start ADD #5 -1 MOV #0 @-2 JMP -2 The DAT statement contains a pointer to where DWARF will launch bombs. The program starts at the ADD #5 -1 command, which makes the pointer equal to 4. The MOV #0 @-2 looks back 2 locations to the DAT statement, then moves a DAT #0 statement 4 addresses forward of the DAT statement (one beyond the JMP -2 command). It then jumps back to the ADD, and makes the pointer 9. Then it moves a DAT #0 9 addresses beyond the DAT statement, etc. Another indirect mode is denoted by the "<" symbol. This is like the indirect mode, but it decrements the B argument of the address pointed to before jumping. A good example of this is in the MICE program which uses the "<" addressing mode to make copies of itself. DAT #0 start MOV #12 -1 MOV @-2 <5 DJN -1 -3 SPL @3 ADD #653 2 JMZ -5 -6 DAT #833 This program uses two pointers. The first, stored at the beginning of the program keeps track of what statement it is going to copy. The second, at the end of the program, keeps track of where it is going to copy the statement. The program starts off by putting a 12 in the first pointer. Then, it moves the statement that the first pointer is pointing to (initially DAT #833) to what is pointed to by the second pointer, but first it subtracts 1 from the pointer. So, what it does is move the DAT #833 statement 832 addresses beyond the DAT #833 statement, and the DAT statement now holds 832. Then, the DJN command subtracts 1 from the first pointer and if it is not zero(which it isn't yet), it jumps backwards 1 command. This continues until the entire program is copied. Once it is copied, it splits to the new MICE, so it now has 2 running. The immediate mode is denoted by the "#" sign, and will take the number as an absolute number. SUB #2 -1 will subract 2 from the B argument of the statement 1 before it. It cannot be used as an address. For example, JMP #0 will not work, since you cannot use absolute memory locations. When the immediate mode is used with a MOV statement for the A argument(it cannot be used for the B argument), it will move a DAT statement with that number as the B argument to the correct address. Since the DAT statement is unexecutable, this is a good way to kill enemy programs as DWARF does. The split command will allow you to run multiple programs at once, but there is a drawback: you only get to execute one of your programs for every one program your opponent executes. For example, if you have 3 programs running (A1, A2, and A3) and your opponent has programs B1 and B2, the order of execution would be A1, B1, A2, B2, A3, B1, A1, B2, etc. The protect command protects an instruction from being written over. After an attempt has been made to write over a protected address, it is no longer protected. For some strategies to use with the protect instruction, see the March 1985 Scientific American. The protect command is not an official Core War command. It was included because it was suggested in the article. The programs must be stored in standard text files. The can be made with almost any editor, such as Micro Emacs. There can be any number of spaces between the beginning of the line and the instruction. There must be 1 and only 1 space between the mnemonic and the A argument, and between the A argument and the B argument. If the first line of the program to be executed is not the first line in the program, the first line to be executed must begin with "start". Notice: The DAT instruction does not use the A argument, so you need 2 spaces between the DAT statement and the argument. Core Wars ST will let you select up to 3 programs. If you want to run less than 3 programs, select Cancel on the file selecter after you have loaded all of the programs you would like. You are then asked how many turns you would like the programs to run. You can the programs run up to 999,999 turns. Next, you are shown the battle screen. On the bottom of the screen, the number of programs each program is running is displayed. This number will go up for a program when it splits, and will go down when a program tries to execute a DAT statement. If you want to abort early, hit one of the mouse buttons. Each program has a different color (or pattern in monochrome mode). A dot of the program's color will be put on the screen at the address a program executes or moves something to. The shortest program possible is called IMP: MOV 0 1 It copies itself forward one location, then advances to the next location etc. This program cannot win, because any other program it overwrites will just become an IMP, but it is hard to kill. An IMP GUN is: SPL 2 JMP -1 MOV 0 1 This sends out a continuous stream of IMPs, which are very hard to kill, but they move very slow. Take a look at the included core wars programs for more examples. Also, if you can, take a look at the Scientific American articles for more example programs and strategies. If you enjoy this program, please send me $5. If you would like the source code, send me $10, and I'll send you a disk with the source code. Send it to: Dan Crevier 2536 Foothill Road Santa Barbara, CA, 93015 If you have any questions or comments, contact me on GEnie or on my Bulletin Board -- The Sanctuary (805) 687-1075 300/1200/2400.