├── README.md ├── makefile ├── make.bat ├── .gitignore ├── io-ports.c ├── j1-emu.c ├── j1-dis.c ├── j1.h ├── j1.src ├── j1-parse.c ├── j1.lst └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # J1 2 | A Forth J1 CPU emulator in C 3 | 4 | The J1 white paper is here: https://excamera.com/files/j1.pdf 5 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | ARCH ?= 32 2 | CFLAGS = -O3 -m$(ARCH) 3 | srcfiles := $(shell find . -name "*.c") 4 | incfiles := $(shell find . -name "*.h") 5 | 6 | j1-emu: j1-emu.c j1.h 7 | $(CC) $(CFLAGS) j1-emu.c -o $@ 8 | 9 | j1-parse: j1-parse.c j1-dis.c j1.h 10 | $(CC) $(CFLAGS) j1-parse.c j1-dis.c -o $@ 11 | 12 | run: j1-emu 13 | ./j1-emu 14 | 15 | clean: 16 | rm -f j1-emu 17 | rm -f j1-parse 18 | 19 | test: j1-parse j1-emu 20 | ./j1-parse 21 | ./j1-emu 22 | 23 | bin: j1-emu 24 | cp -u -p j1-emu ~/bin/ 25 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if "--%1%--" == "----" goto make-j1 4 | if "--%1%--" == "--j1--" goto make-j1 5 | goto unknown 6 | 7 | :make-j1 8 | set output=j1 9 | set c-files=j1-emu.c 10 | set c-files=%c-files% j1-main.c io-ports.c 11 | echo making %output% ... 12 | echo gcc -o %output% %c-files% 13 | gcc -o %output% %c-files% 14 | if "--%2%--" == "----" goto done 15 | j1 -f:j1 -c:1000 16 | goto done 17 | 18 | :unknown 19 | echo Unknown make. I know how to make these: 20 | echo. 21 | echo j1 - makes j1.exe 22 | echo. 23 | echo NOTE: if arg2 is given it then runs the program 24 | 25 | :done 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.bin 35 | *.app 36 | *.i*86 37 | *.x86_64 38 | *.hex 39 | 40 | # Debug files 41 | *.dSYM/ 42 | *.su 43 | *.idb 44 | *.pdb 45 | 46 | # Kernel Module Compile Results 47 | *.mod* 48 | *.cmd 49 | .tmp_versions/ 50 | modules.order 51 | Module.symvers 52 | Mkfile.old 53 | dkms.conf 54 | 55 | # my files 56 | j1 57 | j1-emu 58 | j1-parse 59 | -------------------------------------------------------------------------------- /io-ports.c: -------------------------------------------------------------------------------- 1 | // Support for project-specific IO ports 2 | 3 | #include 4 | #include 5 | 6 | #ifndef emitPort 7 | #define emitPort 1 8 | #define dotPort 2 9 | #endif 10 | 11 | // --------------------------------------------------------------------- 12 | void writePort_String(const char *str); 13 | void writePort_StringF(const char *fmt, ...); 14 | 15 | // --------------------------------------------------------------------- 16 | unsigned short readPort(unsigned short portNum) { 17 | portNum = (portNum & 0x0FFF); 18 | writePort_StringF("WARN: readPort(0x%04x) not implemented.", portNum); 19 | return 0; 20 | } 21 | 22 | // --------------------------------------------------------------------- 23 | void writePort(unsigned short portNum, unsigned short val) { 24 | portNum = (portNum & 0x0FFF); 25 | if (portNum == emitPort) { putc(val, stdout); } 26 | if (portNum == dotPort) { writePort_StringF(" %d", val); } 27 | } 28 | 29 | // --------------------------------------------------------------------- 30 | void writePort_String(const char *str) 31 | { 32 | while (*str) { 33 | writePort(emitPort, *(str++)); 34 | } 35 | } 36 | 37 | // --------------------------------------------------------------------- 38 | void writePort_StringF(const char *fmt, ...) 39 | { 40 | char buf[64]; 41 | va_list args; 42 | va_start(args, fmt); 43 | vsnprintf(buf, sizeof(buf), fmt, args); 44 | va_end(args); 45 | writePort_String(buf); 46 | } 47 | -------------------------------------------------------------------------------- /j1-emu.c: -------------------------------------------------------------------------------- 1 | // J1 white paper is here: https://excamera.com/files/j1.pdf 2 | 3 | #include "j1.h" 4 | 5 | WORD the_memory[MEM_SZ]; 6 | CELL dstk[STK_SZ+1], DSP; 7 | CELL rstk[STK_SZ+1], RSP; 8 | CELL PC, debugOn = false; 9 | 10 | void push(CELL val) { if (DSP < STK_SZ) { dstk[++DSP] = val; } } 11 | CELL pop() { return (0 < DSP) ? dstk[DSP--] : 0; } 12 | void rpush(CELL val) { if (RSP < STK_SZ) { rstk[++RSP] = val; } } 13 | 14 | void storeWord(WORD addr, WORD val) { 15 | if (BTWI(addr, 0, MEM_SZ-1)) { the_memory[addr] = val; } 16 | else if ((addr & 0x0FFF) == emitPort) { putc(val%0xff, stdout); } 17 | else if ((addr & 0x0FFF) == dotPort) { printf(" %d", val); } 18 | } 19 | 20 | WORD readWord(WORD addr) { 21 | if (BTWI(addr, 0, MEM_SZ-1)) { return the_memory[addr]; } 22 | else { 23 | printf("WARN: readWord(0x%04x) not implemented.", addr & 0x0FFF); 24 | return 0; 25 | } 26 | } 27 | 28 | WORD deriveNewT(WORD op) { 29 | switch (op & 0x0F) { 30 | case tpTgetsT: return T; 31 | case tpTgetsN: return N; 32 | case tpTplusN: return (T + N); 33 | case tpTandN: return (T & N); 34 | case tpTorN: return (T | N); 35 | case tpTxorN: return (T ^ N); 36 | case tpNotT: return (~T); 37 | case tpTeqN: return (N == T) ? 1 : 0; 38 | case tpTltN: return (N < T) ? 1 : 0; 39 | case tpSHR: return (N >> T); 40 | case tpDecT: return (T-1); 41 | case tpTgetsR: return R; 42 | case tpFetch: return readWord(T); 43 | case tpSHL: return (N << T); 44 | case tpDepth: return DSP; 45 | default: return 0; // tpNullT 46 | } 47 | } 48 | 49 | void j1_emu(WORD PC) { 50 | while (1) { 51 | WORD IR = the_memory[PC++]; 52 | if ((IR & opLIT) == opLIT) { 53 | push(IR & 0x7FFF); 54 | } else if ((IR & INSTR_MASK) == opALU) { 55 | CELL currentT = T, currentN = N; 56 | CELL currentR = R, newT = deriveNewT(IR>>8); 57 | if (IR & bitIncRSP) { if (RSP < STK_SZ) { RSP++; } } 58 | if (IR & bitDecRSP) { RSP -= 1; } 59 | if (IR & bitIncDSP) { if (DSP < STK_SZ) { DSP++; } } 60 | if (IR & bitDecDSP) { if (0 < DSP) { DSP--; } } 61 | if (IR & bitRtoPC) { PC = currentR; } 62 | if (IR & bitTtoR) { R = currentT; } 63 | if (IR & bitTtoN) { N = currentT; } 64 | if (IR & bitStore) { storeWord(currentT, currentN); } 65 | T = newT; 66 | } else if ((IR & INSTR_MASK) == opCALL) { 67 | rpush(PC); 68 | PC = (IR & ADDR_MASK); 69 | } else if ((IR & INSTR_MASK) == opJMPZ) { 70 | if (pop() == 0) PC = (IR & ADDR_MASK); 71 | } else if ((IR & INSTR_MASK) == opJMP) { 72 | PC = IR & ADDR_MASK; 73 | } 74 | if (RSP < 0) { RSP = 0; return; } 75 | } 76 | } 77 | 78 | void main(int argc, char *argv[]) { 79 | FILE *fp = fopen("j1.bin", "rb"); 80 | if (!fp) { 81 | printf(" ERROR: unable to open file 'j1.bin'\n"); 82 | } else { 83 | PC = DSP = RSP = 0; 84 | fread(the_memory, 2, MEM_SZ, fp); 85 | fclose(fp); 86 | j1_emu(0); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /j1-dis.c: -------------------------------------------------------------------------------- 1 | // J1 white paper is here: https://excamera.com/files/j1.pdf 2 | 3 | #include "j1.h" 4 | 5 | extern CELL PC; 6 | 7 | void dumpState(bool lastPC, WORD IR) { 8 | printf("\nPC: %04X DSP: %-2d N: %-5d T: %-5d", PC, DSP, N, T); 9 | printf(" RSP: %-2d R: %-3d cycle: %-4ld", RSP, R); 10 | printf(" IR: %04X", the_memory[PC - ((lastPC) ? 1 : 0)]); 11 | disIR(IR, NULL); 12 | } 13 | 14 | void dumpStack(int sp, WORD *stk) { 15 | printf("( "); 16 | for (int i = 1; i <= sp; i++) { 17 | printf("%d ", stk[i]); 18 | } 19 | printf(")"); 20 | } 21 | 22 | void disALU(WORD IR, char *output) { 23 | strcat(output, "\n "); 24 | 25 | WORD aluOp = IR & 0x0F00; 26 | if (aluOp == aluTgetsT) { strcat(output, "T"); } 27 | if (aluOp == aluTgetsN) { strcat(output, "N"); } 28 | if (aluOp == aluTgetsR) { strcat(output, "R"); } 29 | if (aluOp == aluTplusN) { strcat(output, "T+N"); } 30 | if (aluOp == aluTandN) { strcat(output, "T&N"); } 31 | if (aluOp == aluTorN) { strcat(output, "T|N"); } 32 | if (aluOp == aluTxorN) { strcat(output, "T^N"); } 33 | if (aluOp == aluNotT) { strcat(output, "~T"); } 34 | if (aluOp == aluTeqN) { strcat(output, "N==T"); } 35 | if (aluOp == aluTltN) { strcat(output, "N>T"); } 37 | if (aluOp == aluDecT) { strcat(output, "T-1"); } 38 | if (aluOp == aluFetch) { strcat(output, "[T]"); } 39 | if (aluOp == aluSHL) { strcat(output, "N<PC"); } 44 | if (IR & bitStore) { strcat(output, " N->[T]"); } 45 | if (IR & bitIncRSP) { strcat(output, " r+1"); } 46 | if (IR & bitDecRSP) { strcat(output, " r-1"); } 47 | if (IR & bitTtoR) { strcat(output, " T->R"); } 48 | if (IR & bitTtoN) { strcat(output, " T->N"); } 49 | if (IR & bitUnused) { strcat(output, " (unused)"); } 50 | if (IR & bitDecDSP) { strcat(output, " d-1"); } 51 | if (IR & bitIncDSP) { strcat(output, " d+1"); } 52 | } 53 | 54 | void disIR(WORD IR, char *output) { 55 | char buf[128]; 56 | WORD arg; 57 | sprintf(buf, "Unknown IR %04X", IR); 58 | if ((IR & opLIT) == opLIT) { 59 | arg = (IR & 0x7FFF); 60 | sprintf(buf, "%-8s %-5d # (0x%04X)", "LIT", arg, arg); 61 | } else if ((IR & INSTR_MASK) == opJMP) { 62 | arg = (IR & ADDR_MASK); 63 | sprintf(buf, "%-8s %-5d # (0x%04X)", "JMP", arg, arg); 64 | } else if ((IR & INSTR_MASK) == opJMPZ) { 65 | arg = (IR & ADDR_MASK); 66 | sprintf(buf, "%-8s %-5d # (0x%04X)", "JMPZ", arg, arg); 67 | } else if ((IR & INSTR_MASK) == opCALL) { 68 | arg = (IR & ADDR_MASK); 69 | sprintf(buf, "%-8s %-5d # (0x%04X)", "CALL", arg, arg); 70 | } else if ((IR & INSTR_MASK) == opALU) { 71 | arg = (IR & ADDR_MASK); 72 | sprintf(buf, "%-8s %-5d # (0x%04X)", "ALU", arg, arg); 73 | disALU(IR, buf); 74 | } 75 | if (output) { 76 | strcpy(output, buf); 77 | } else { 78 | printf("%s", "\n"); 79 | printf("%s", buf); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /j1.h: -------------------------------------------------------------------------------- 1 | // J1 white paper is here: https://excamera.com/files/j1.pdf 2 | 3 | // The top 3 bits identify the class of opcode ... 4 | // 1xxx => LIT (1xxx xxxx xxxx xxxx) (IR & 0x8000) == 0x8000 5 | // 011x => ALU (011x xxxx xxxx xxxx) (IR & 0xE000) == 0x6000 6 | // 010x => CALL (010x xxxx xxxx xxxx) (IR & 0xE000) == 0x4000 7 | // 001x => JMPZ (001x xxxx xxxx xxxx) (IR & 0xE000) == 0x2000 8 | // 000x => JMP (000x xxxx xxxx xxxx) (IR & 0xE000) == 0x0000 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define STK_SZ 32 15 | #define MEM_SZ 0x4000 16 | 17 | #define CELL short 18 | #define CELL_SZ 2 19 | #define WORD unsigned short 20 | #define byte unsigned char 21 | 22 | #define bool int 23 | #define true 1 24 | #define false 0 25 | #define BTWI(n,l,h) (((l)<=(n)) && ((n)<=(h))) 26 | 27 | #define INSTR_MASK 0xE000 28 | #define ADDR_MASK 0x1FFF 29 | 30 | #define bitIncRSP (0x0001) 31 | #define bitDecRSP (0x0002) 32 | #define bitIncDSP (0x0004) 33 | #define bitDecDSP (0x0008) 34 | #define bitUnused (0x0010) 35 | #define bitStore (0x0020) 36 | #define bitTtoR (0x0040) 37 | #define bitTtoN (0x0080) 38 | #define bitRtoPC (0x1000) 39 | 40 | #define opJMP (0x0000) 41 | #define opJMPZ (0x2000) 42 | #define opCALL (0x4000) 43 | #define opALU (0x6000) 44 | #define opLIT (0x8000) 45 | 46 | #define aluTgetsT (0x0000) 47 | #define aluTgetsN (0x0100) 48 | #define aluTplusN (0x0200) 49 | #define aluTandN (0x0300) 50 | #define aluTorN (0x0400) 51 | #define aluTxorN (0x0500) 52 | #define aluNotT (0x0600) 53 | #define aluTeqN (0x0700) 54 | #define aluTltN (0x0800) 55 | #define aluSHR (0x0900) 56 | #define aluDecT (0x0A00) 57 | #define aluTgetsR (0x0B00) 58 | #define aluFetch (0x0C00) 59 | #define aluSHL (0x0D00) 60 | #define aluDepth (0x0E00) 61 | #define aluNuLtT (0x0F00) 62 | 63 | #define tpTgetsT (0x00) 64 | #define tpTgetsN (0x01) 65 | #define tpTplusN (0x02) 66 | #define tpTandN (0x03) 67 | #define tpTorN (0x04) 68 | #define tpTxorN (0x05) 69 | #define tpNotT (0x06) 70 | #define tpTeqN (0x07) 71 | #define tpTltN (0x08) 72 | #define tpSHR (0x09) 73 | #define tpDecT (0x0A) 74 | #define tpTgetsR (0x0B) 75 | #define tpFetch (0x0C) 76 | #define tpSHL (0x0D) 77 | #define tpDepth (0x0E) 78 | #define tpNullT (0x0F) 79 | 80 | #define setALUcode(op, code) (op |= ((code & 0x0f) << 8)) 81 | 82 | #define MAKE_LIT(val) (0x8000 | val) 83 | #define MAKE_JMP(addr) (0x0000 | addr) 84 | #define MAKE_JMPZ(addr) (0x2000 | addr) 85 | #define MAKE_CALL(addr) (0x4000 | addr) 86 | #define MAKE_ALU(val) (0x6000 | val) 87 | 88 | #define T dstk[DSP] 89 | #define N dstk[(DSP > 0) ? (DSP-1) : 0] 90 | #define R rstk[RSP] 91 | 92 | #define emitPort 1 93 | #define dotPort 2 94 | 95 | typedef struct { 96 | char name[24]; 97 | byte flags; 98 | byte len; 99 | WORD xt; 100 | WORD macroVal; 101 | } DICT_T; 102 | 103 | // --------------------------------------------------------------------- 104 | extern WORD the_memory[]; 105 | extern CELL dstk[], DSP; 106 | extern CELL rstk[], RSP; 107 | 108 | void push(CELL val); 109 | CELL pop(); 110 | void dumpStack(int sp, WORD *stk); 111 | void dumpState(bool, WORD); 112 | void disIR(WORD IR, char *output); 113 | // --------------------------------------------------------------------- 114 | -------------------------------------------------------------------------------- /j1.src: -------------------------------------------------------------------------------- 1 | // ( Base words implemented in assembler JCB 13:10 08/24/10) 2 | 3 | : noop T alu ; MACRO 4 | : + T+N d-1 alu ; MACRO 5 | : xor T^N d-1 alu ; MACRO 6 | : and T&N d-1 alu ; MACRO 7 | : or T|N d-1 alu ; MACRO 8 | : invert ~T alu ; MACRO 9 | : = N==T d-1 alu ; MACRO 10 | : < NN alu ; MACRO 13 | : dup T T->N d+1 alu ; MACRO 14 | : drop N d-1 alu ; MACRO 15 | : over N T->N d+1 alu ; MACRO 16 | : nip T d-1 alu ; MACRO 17 | \ >r N T->R r+1 d-1 alu ; 18 | \ r> rT T->N r-1 d+1 alu ; 19 | \ r@ rT T->N d+1 alu ; 20 | : @ [T] alu ; MACRO 21 | : ! T N->[T] d-1 alu 22 | N d-1 alu ; 23 | : depth dsp T->N d+1 alu ; MACRO 24 | : lshift N<>T d-1 alu ; MACRO 26 | : 1- T-1 alu ; MACRO 27 | : 2r> rT T->N r-1 d+1 alu 28 | rT T->N r-1 d+1 alu 29 | N T->N alu ; 30 | : 2>r N T->N alu 31 | N T->R r+1 d-1 alu 32 | N T->R r+1 d-1 alu ; 33 | : 2r@ rT T->N r-1 d+1 alu 34 | rT T->N r-1 d+1 alu 35 | N T->N d+1 alu 36 | N T->N d+1 alu 37 | N T->R r+1 d-1 alu 38 | N T->R r+1 d-1 alu 39 | N T->N alu ; 40 | : unloop 41 | T r-1 alu 42 | T r-1 alu ; 43 | \ : exit return ; 44 | 45 | \ Elided words 46 | : dup@ [T] T->N d+1 alu ; MACRO 47 | : dup>r T T->R r+1 alu ; 48 | : 2dupxor T^N T->N d+1 alu ; MACRO 49 | : 2dup= N==T T->N d+1 alu ; MACRO 50 | : !nip T N->[T] d-1 alu ; MACRO 51 | : 2dup! T N->[T] alu ; MACRO 52 | 53 | \ Words used to implement pick 54 | : up1 T d+1 alu ; MACRO 55 | : down1 T d-1 alu ; MACRO 56 | : copy N alu ; MACRO 57 | 58 | \ Input/output 59 | : emit $4001 ! ; 60 | : . $4002 ! ; 61 | 62 | // **************************** 63 | // TESTS 64 | // **************************** 65 | 66 | : cr #13 emit #10 emit ; : bl $20 emit ; 67 | : t cr . bl ; 68 | : test-dup 1 t 36 dup . . ; // expect 36 36 69 | : test-nip 2 t 11 22 34 nip . . ; // expect 34 11 70 | : test-swap 3 t 11 22 swap . . ; // expect 11 22 71 | : test-drop 4 t 11 22 35 drop . . ; // expect 22 11 72 | : test-over 5 t 83 19 over . . . ; // expect 83 19 83 73 | : test-0000 6 t 0 . ; // expect 0 74 | : test-dot 7 t 12345 . ; // expect 12345 75 | : test->r 8 t 71 123 >r . 654 . r> . ; // expect 71 654 123 76 | : test-r@ 9 t 81 >r 234 . r@ . r> . ; // expect 234 81 81 77 | : test-add 10 t 1 2 3 4 + + + . ; // expect 10 78 | : test-depth 11 t 7 8 9 depth . . . . ; // expect 3 9 8 7 79 | : test-1- 12 t 3345 1- . ; // expect 3344 80 | : OK 'O' emit 'K' emit ; 81 | : bench drop ; // begin 1- dup while drop ; 82 | : mbench drop ; // dup begin over bench 1- dup while drop ; 83 | : do-bench $5759 mbench ; 84 | : main test-dup test-nip test-swap 85 | test-drop test-over test-0000 86 | test-dot test->r test-r@ 87 | test-add test-depth test-1- 88 | cr 's' emit do-bench 'e' emit 89 | cr OK cr ; 90 | // : newMain test-depth ; 91 | -------------------------------------------------------------------------------- /j1-parse.c: -------------------------------------------------------------------------------- 1 | #include "j1.h" 2 | 3 | char base_fn[32]; 4 | bool save_output = true; 5 | bool debug_flag = false; 6 | int exitStatus = 0; 7 | long maxCycles = 0; 8 | 9 | WORD the_memory[MEM_SZ]; 10 | CELL dstk[STK_SZ+1], DSP; 11 | CELL rstk[STK_SZ+1], RSP; 12 | CELL PC, debugOn = false; 13 | long cycle; 14 | 15 | #define LAST_OP the_memory[HERE-1] 16 | #define COMMA(val) the_memory[HERE++] = val 17 | 18 | #define TIB_SZ 1024 19 | char tib[TIB_SZ]; 20 | char *toIn; 21 | 22 | DICT_T words[2048]; 23 | WORD numWords = 0; 24 | 25 | WORD HERE = 0; 26 | WORD STATE = 0; 27 | 28 | // --------------------------------------------------------------------- 29 | void j1_init() { PC = DSP = RSP = 0; } 30 | void push(CELL val) { if (DSP < STK_SZ) { dstk[++DSP] = val; } } 31 | CELL pop() { return (0 < DSP) ? dstk[DSP--] : 0; } 32 | 33 | // --------------------------------------------------------------------- 34 | int getWord(char *word) { 35 | int len = 0; 36 | while (BTWI(*toIn,1,32)) { ++toIn; } 37 | while (BTWI(*toIn,33,126)) { word[len++] = *(toIn++); } 38 | word[len] = 0; 39 | return len; 40 | } 41 | 42 | // --------------------------------------------------------------------- 43 | int isNumber(char *w, WORD *value) { 44 | WORD n=0, b=10, isNeg=0; 45 | if ((w[0]==39) && (w[2]==39) && (w[3]==0)) { *value=w[1]; return 1; } 46 | if (w[0]=='#') { b=10; w++; } 47 | if (w[0]=='$') { b=16; w++; } 48 | if (w[0]=='%') { b=2; w++; } 49 | if (w[0]=='-') { isNeg=1; w++; } 50 | if (w[0]==0) { return 0; } 51 | while (*w) { 52 | int c = *(w++); 53 | int x = BTWI(c,'0','9') ? c-'0' : 99; 54 | if (BTWI(c,'A','F')) { x = (c-'A'+10); } 55 | if (BTWI(c,'a','f')) { x = (c-'a'+10); } 56 | if (BTWI(x, 0, b-1)) { n = (n*b)+x; } else { return 0; } 57 | } 58 | *value = (isNeg ? -n : n); 59 | return 1; 60 | } 61 | 62 | // --------------------------------------------------------------------- 63 | void defineWord(char *name) { 64 | DICT_T *p = &words[numWords++]; 65 | strcpy(p->name, name); 66 | p->xt = HERE; 67 | p->flags = 0; 68 | p->len = 0; 69 | if (debug_flag) printf("\nDefined (%d) [%s] at addr %02X", numWords-1, name, HERE); 70 | } 71 | 72 | // --------------------------------------------------------------------- 73 | DICT_T *findWord(char *word) { 74 | for (int i = numWords-1; i >= 0; i--) { 75 | if (strcmp(words[i].name, word) == 0) { 76 | return &words[i]; 77 | } 78 | } 79 | return NULL; 80 | } 81 | 82 | // --------------------------------------------------------------------- 83 | void parseWord(char *word) { 84 | // if (debug_flag) printf("\n[%s] (HERE=%d), LAST_OP=%04X", word, HERE, LAST_OP); 85 | WORD num = 0; 86 | WORD op = LAST_OP; 87 | if (isNumber(word, &num)) { 88 | if ((num & 0x8000) == 0) { 89 | op = MAKE_LIT(num); 90 | COMMA(op); 91 | } else { 92 | // For numbers larger than 0x7FFF 93 | num = ~num; 94 | COMMA(MAKE_LIT(num)); 95 | COMMA(MAKE_ALU(0x0030)); 96 | } 97 | return; 98 | } 99 | DICT_T *w = findWord(word); 100 | if (w) { 101 | // INLINE is only for words where the last operation is ALU 102 | if (w->flags & 0x01) { 103 | WORD a = w->xt; 104 | for (WORD i = 0; i < w->len; i++) { 105 | COMMA(the_memory[a++]); 106 | } 107 | // Clear the R->PC and --RSP bits 108 | LAST_OP &= ~(bitRtoPC|bitDecRSP); 109 | } else if (w->flags & 0x08) { 110 | // MACRO 111 | COMMA(w->macroVal); 112 | } else { 113 | op = MAKE_CALL(w->xt); 114 | COMMA(op); 115 | } 116 | return; 117 | } 118 | if (strcmp(word, ":") == 0) { 119 | getWord(word); 120 | defineWord(word); 121 | STATE = 1; 122 | return; 123 | } 124 | if (strcmp(word, "MACRO") == 0) { 125 | DICT_T *w = &words[numWords-1]; 126 | if (w->len == 1) { 127 | op = the_memory[--HERE]; 128 | the_memory[HERE] = 0; 129 | op &= ~(bitRtoPC|bitDecRSP); 130 | w->xt = 0x0000; 131 | w->flags = 0x08; 132 | w->macroVal = op; 133 | if (debug_flag) { printf("MACRO: [%s], val=%02X", w->name, w->macroVal); } 134 | } else { 135 | printf("\nWARN: [%s] length must be 1 for MACRO", w->name); 136 | } 137 | return; 138 | } 139 | if (strcmp(word, "INLINE") == 0) { 140 | if ((LAST_OP & 0xE000) == opALU) { 141 | words[numWords-1].flags |= 1; 142 | } 143 | return; 144 | } 145 | if (strcmp(word, ";") == 0) { 146 | STATE = 0; 147 | words[numWords-1].len = (HERE - words[numWords-1].xt); 148 | // Change last operation to JMP if CALL 149 | if ((LAST_OP & 0xE000) == opCALL) { 150 | LAST_OP = (LAST_OP & 0x1FFF) | opJMP; 151 | if (debug_flag) printf("\nchanged op at %d to JMP", HERE-1); 152 | return; 153 | } 154 | bool canAddRet = true; 155 | if ((LAST_OP & 0xE000) != opALU) canAddRet = false; // not ALU 156 | if ((LAST_OP & bitRtoPC) != 0) canAddRet = false; // R->PC already set 157 | if ((LAST_OP & bitIncRSP) != 0) canAddRet = false; // R++ set 158 | if ((LAST_OP & bitDecRSP) != 0) canAddRet = false; // R-- already set 159 | if (canAddRet) { 160 | LAST_OP |= bitRtoPC; 161 | LAST_OP |= bitDecRSP; 162 | if (debug_flag) printf("\nAdded %04X to ALU op at %d", (bitDecDSP|bitRtoPC), HERE-1); 163 | return; 164 | } 165 | // cannot include in previous op :( 166 | op = opALU; 167 | op |= bitRtoPC; 168 | op |= bitDecRSP; 169 | COMMA(op); 170 | words[numWords-1].len = (HERE - words[numWords-1].xt); 171 | return; 172 | } 173 | if (strcmp(word, "alu") == 0) { 174 | if (debug_flag) printf(" putting ALU %04X to [%d]", HERE); 175 | op = MAKE_ALU(pop()); 176 | COMMA(op); 177 | return; 178 | } 179 | if (strcmp(word, "T") == 0) { push(aluTgetsT); return; } 180 | if (strcmp(word, "N") == 0) { push(aluTgetsN); return; } 181 | if (strcmp(word, "rT") == 0) { push(aluTgetsR); return; } 182 | if (strcmp(word, "T+N") == 0) { push(aluTplusN); return; } 183 | if (strcmp(word, "T&N") == 0) { push(aluTandN); return; } 184 | if (strcmp(word, "T|N") == 0) { push(aluTorN); return; } 185 | if (strcmp(word, "T^N") == 0) { push(aluTxorN); return; } 186 | if (strcmp(word, "~T") == 0) { push(aluNotT); return; } 187 | if (strcmp(word, "N==T") == 0) { push(aluTeqN); return; } 188 | if (strcmp(word, "N>T") == 0) { push(aluSHR); return; } 190 | if (strcmp(word, "N<[T]") == 0) { T |= bitStore; return; } 196 | if (strcmp(word, "R->PC") == 0) { T |= bitRtoPC; return; } 197 | if (strcmp(word, "T->N") == 0) { T |= bitTtoN; return; } 198 | if (strcmp(word, "T->R") == 0) { T |= bitTtoR; return; } 199 | if (strcmp(word, "r+1") == 0) { T |= bitIncRSP; return; } 200 | if (strcmp(word, "r-1") == 0) { T |= bitDecRSP; return; } 201 | if (strcmp(word, "d+1") == 0) { T |= bitIncDSP; return; } 202 | if (strcmp(word, "d-1") == 0) { T |= bitDecDSP; return; } 203 | if (strcmp(word, ">r") == 0) { 204 | op = MAKE_ALU(aluTgetsN|bitTtoR|bitIncRSP|bitDecDSP); 205 | COMMA(op); 206 | return; 207 | } 208 | if (strcmp(word, "r>") == 0) { 209 | op = MAKE_ALU(aluTgetsR|bitDecRSP|bitIncDSP); 210 | COMMA(op); 211 | return; 212 | } 213 | if (strcmp(word, "r@") == 0) { 214 | op = MAKE_ALU(aluTgetsR|bitIncDSP); 215 | COMMA(op); 216 | return; 217 | } 218 | if (strcmp(word, "XXX") == 0) { 219 | // do something ... 220 | return; 221 | } 222 | printf("\nERROR: unknown word: [%s]\n", word); 223 | exitStatus = 1; 224 | } 225 | 226 | // --------------------------------------------------------------------- 227 | void parseLine(char *line) { 228 | char word[32]; 229 | toIn = line; 230 | while (true) { 231 | int len = getWord(word); 232 | // printf("[%s]", word); 233 | if (len) { 234 | if (strcmp(word, "\\") == 0) { return; } 235 | if (strcmp(word, "//") == 0) { return; } 236 | parseWord(word); 237 | } else { 238 | return; 239 | } 240 | } 241 | } 242 | 243 | // --------------------------------------------------------------------- 244 | void doCompile(FILE *fp) { 245 | char *inSave = toIn; 246 | while (true) { 247 | if (fgets(tib, TIB_SZ, fp) == tib) { 248 | parseLine(tib); 249 | } else { 250 | toIn = inSave; 251 | return; 252 | } 253 | } 254 | } 255 | 256 | // --------------------------------------------------------------------- 257 | int load(char *base) { 258 | char fn[32]; 259 | sprintf(fn, "%s.src", base_fn); 260 | FILE *fp = fopen(fn, "rt"); 261 | if (fp) { 262 | doCompile(fp); 263 | fclose(fp); 264 | } else { 265 | printf("ERROR: unable to open '%s'\n", fn); 266 | return 1; 267 | } 268 | } 269 | 270 | // --------------------------------------------------------------------- 271 | void doDisassemble(bool toFile) { 272 | FILE *fp = NULL; 273 | if (toFile) { 274 | char fn[32]; 275 | sprintf(fn, "%s.lst", base_fn); 276 | fp = fopen(fn, "wt"); 277 | if (!fp) { 278 | printf("\nUnable to create listing file '%s'.", fn); 279 | return; 280 | } 281 | fprintf(fp, "; HERE: 0x%04X (%d)\n", HERE, HERE); 282 | } 283 | 284 | char buf[256]; 285 | for (int i = 0; i < numWords; i++) { 286 | DICT_T *p = &words[i]; 287 | sprintf(buf, "; %2d: XT: %04X, Len: %2d, Flags: %02X, MacroVal: %02X, Name: %s\n", i, 288 | p->xt, p->len, p->flags, p->macroVal, p->name); 289 | (fp) ? fprintf(fp, "%s", buf) : printf("%s", buf); 290 | } 291 | 292 | for (int i = 0; i < HERE; i++) { 293 | WORD ir = the_memory[i]; 294 | disIR(ir, buf); 295 | if (fp) { 296 | fprintf(fp, "\n%04X: %04X ", i, ir); 297 | fprintf(fp, "%s", buf); 298 | } else { 299 | printf("\n%04X: %04X ", i, ir); 300 | printf("%s", buf); 301 | } 302 | } 303 | if (fp) { fclose(fp); } 304 | } 305 | 306 | // --------------------------------------------------------------------- 307 | void saveImage() { 308 | char fn[32]; 309 | sprintf(fn, "%s.bin", base_fn); 310 | FILE *fp = fopen(fn, "wb"); 311 | if (fp) { 312 | fwrite(the_memory, 2, MEM_SZ, fp); 313 | fclose(fp); 314 | } else { 315 | printf(" ERROR: unable to open file '%s'", fn); 316 | } 317 | } 318 | 319 | // --------------------------------------------------------------------- 320 | // --------------------------------------------------------------------- 321 | // --------------------------------------------------------------------- 322 | int main (int argc, char **argv) 323 | { 324 | strcpy(base_fn, "j1"); 325 | 326 | j1_init(); 327 | COMMA(MAKE_JMP(0)); 328 | 329 | load(base_fn); 330 | 331 | if (numWords) { the_memory[0] = MAKE_JMP(words[numWords-1].xt); } 332 | if (save_output) { 333 | doDisassemble(true); 334 | saveImage(); 335 | } 336 | return exitStatus; 337 | } 338 | -------------------------------------------------------------------------------- /j1.lst: -------------------------------------------------------------------------------- 1 | ; HERE: 0x009A (154) 2 | ; 0: XT: 0000, Len: 1, Flags: 08, MacroVal: 6000, Name: noop 3 | ; 1: XT: 0000, Len: 1, Flags: 08, MacroVal: 6208, Name: + 4 | ; 2: XT: 0000, Len: 1, Flags: 08, MacroVal: 6508, Name: xor 5 | ; 3: XT: 0000, Len: 1, Flags: 08, MacroVal: 6308, Name: and 6 | ; 4: XT: 0000, Len: 1, Flags: 08, MacroVal: 6408, Name: or 7 | ; 5: XT: 0000, Len: 1, Flags: 08, MacroVal: 6600, Name: invert 8 | ; 6: XT: 0000, Len: 1, Flags: 08, MacroVal: 6708, Name: = 9 | ; 7: XT: 0000, Len: 1, Flags: 08, MacroVal: 6808, Name: < 10 | ; 8: XT: 0000, Len: 1, Flags: 08, MacroVal: 6F08, Name: u< 11 | ; 9: XT: 0000, Len: 1, Flags: 08, MacroVal: 6180, Name: swap 12 | ; 10: XT: 0000, Len: 1, Flags: 08, MacroVal: 6084, Name: dup 13 | ; 11: XT: 0000, Len: 1, Flags: 08, MacroVal: 6108, Name: drop 14 | ; 12: XT: 0000, Len: 1, Flags: 08, MacroVal: 6184, Name: over 15 | ; 13: XT: 0000, Len: 1, Flags: 08, MacroVal: 6008, Name: nip 16 | ; 14: XT: 0000, Len: 1, Flags: 08, MacroVal: 6C00, Name: @ 17 | ; 15: XT: 0001, Len: 2, Flags: 00, MacroVal: 00, Name: ! 18 | ; 16: XT: 0000, Len: 1, Flags: 08, MacroVal: 6E84, Name: depth 19 | ; 17: XT: 0000, Len: 1, Flags: 08, MacroVal: 6D08, Name: lshift 20 | ; 18: XT: 0000, Len: 1, Flags: 08, MacroVal: 6908, Name: rshift 21 | ; 19: XT: 0000, Len: 1, Flags: 08, MacroVal: 6A00, Name: 1- 22 | ; 20: XT: 0003, Len: 3, Flags: 00, MacroVal: 00, Name: 2r> 23 | ; 21: XT: 0006, Len: 4, Flags: 00, MacroVal: 00, Name: 2>r 24 | ; 22: XT: 000A, Len: 7, Flags: 00, MacroVal: 00, Name: 2r@ 25 | ; 23: XT: 0011, Len: 3, Flags: 00, MacroVal: 00, Name: unloop 26 | ; 24: XT: 0000, Len: 1, Flags: 08, MacroVal: 6C84, Name: dup@ 27 | ; 25: XT: 0014, Len: 2, Flags: 00, MacroVal: 00, Name: dup>r 28 | ; 26: XT: 0000, Len: 1, Flags: 08, MacroVal: 6584, Name: 2dupxor 29 | ; 27: XT: 0000, Len: 1, Flags: 08, MacroVal: 6784, Name: 2dup= 30 | ; 28: XT: 0000, Len: 1, Flags: 08, MacroVal: 6028, Name: !nip 31 | ; 29: XT: 0000, Len: 1, Flags: 08, MacroVal: 6020, Name: 2dup! 32 | ; 30: XT: 0000, Len: 1, Flags: 08, MacroVal: 6004, Name: up1 33 | ; 31: XT: 0000, Len: 1, Flags: 08, MacroVal: 6008, Name: down1 34 | ; 32: XT: 0000, Len: 1, Flags: 08, MacroVal: 6100, Name: copy 35 | ; 33: XT: 0016, Len: 2, Flags: 00, MacroVal: 00, Name: emit 36 | ; 34: XT: 0018, Len: 2, Flags: 00, MacroVal: 00, Name: . 37 | ; 35: XT: 001A, Len: 4, Flags: 00, MacroVal: 00, Name: cr 38 | ; 36: XT: 001E, Len: 2, Flags: 00, MacroVal: 00, Name: bl 39 | ; 37: XT: 0020, Len: 3, Flags: 00, MacroVal: 00, Name: t 40 | ; 38: XT: 0023, Len: 6, Flags: 00, MacroVal: 00, Name: test-dup 41 | ; 39: XT: 0029, Len: 8, Flags: 00, MacroVal: 00, Name: test-nip 42 | ; 40: XT: 0031, Len: 7, Flags: 00, MacroVal: 00, Name: test-swap 43 | ; 41: XT: 0038, Len: 8, Flags: 00, MacroVal: 00, Name: test-drop 44 | ; 42: XT: 0040, Len: 8, Flags: 00, MacroVal: 00, Name: test-over 45 | ; 43: XT: 0048, Len: 4, Flags: 00, MacroVal: 00, Name: test-0000 46 | ; 44: XT: 004C, Len: 4, Flags: 00, MacroVal: 00, Name: test-dot 47 | ; 45: XT: 0050, Len: 10, Flags: 00, MacroVal: 00, Name: test->r 48 | ; 46: XT: 005A, Len: 10, Flags: 00, MacroVal: 00, Name: test-r@ 49 | ; 47: XT: 0064, Len: 10, Flags: 00, MacroVal: 00, Name: test-add 50 | ; 48: XT: 006E, Len: 10, Flags: 00, MacroVal: 00, Name: test-depth 51 | ; 49: XT: 0078, Len: 5, Flags: 00, MacroVal: 00, Name: test-1- 52 | ; 50: XT: 007D, Len: 4, Flags: 00, MacroVal: 00, Name: OK 53 | ; 51: XT: 0081, Len: 1, Flags: 00, MacroVal: 00, Name: bench 54 | ; 52: XT: 0082, Len: 1, Flags: 00, MacroVal: 00, Name: mbench 55 | ; 53: XT: 0083, Len: 2, Flags: 00, MacroVal: 00, Name: do-bench 56 | ; 54: XT: 0085, Len: 21, Flags: 00, MacroVal: 00, Name: main 57 | 58 | 0000: 0085 JMP 133 # (0x0085) 59 | 0001: 6028 ALU 40 # (0x0028) 60 | T N->[T] d-1 61 | 0002: 710A ALU 4362 # (0x110A) 62 | N R->PC r-1 d-1 63 | 0003: 6B86 ALU 2950 # (0x0B86) 64 | R r-1 T->N d+1 65 | 0004: 6B86 ALU 2950 # (0x0B86) 66 | R r-1 T->N d+1 67 | 0005: 7182 ALU 4482 # (0x1182) 68 | N R->PC r-1 T->N 69 | 0006: 6180 ALU 384 # (0x0180) 70 | N T->N 71 | 0007: 6149 ALU 329 # (0x0149) 72 | N r+1 T->R d-1 73 | 0008: 6149 ALU 329 # (0x0149) 74 | N r+1 T->R d-1 75 | 0009: 7002 ALU 4098 # (0x1002) 76 | T R->PC r-1 77 | 000A: 6B86 ALU 2950 # (0x0B86) 78 | R r-1 T->N d+1 79 | 000B: 6B86 ALU 2950 # (0x0B86) 80 | R r-1 T->N d+1 81 | 000C: 6184 ALU 388 # (0x0184) 82 | N T->N d+1 83 | 000D: 6184 ALU 388 # (0x0184) 84 | N T->N d+1 85 | 000E: 6149 ALU 329 # (0x0149) 86 | N r+1 T->R d-1 87 | 000F: 6149 ALU 329 # (0x0149) 88 | N r+1 T->R d-1 89 | 0010: 7182 ALU 4482 # (0x1182) 90 | N R->PC r-1 T->N 91 | 0011: 6002 ALU 2 # (0x0002) 92 | T r-1 93 | 0012: 6002 ALU 2 # (0x0002) 94 | T r-1 95 | 0013: 7002 ALU 4098 # (0x1002) 96 | T R->PC r-1 97 | 0014: 6041 ALU 65 # (0x0041) 98 | T r+1 T->R 99 | 0015: 7002 ALU 4098 # (0x1002) 100 | T R->PC r-1 101 | 0016: C001 LIT 16385 # (0x4001) 102 | 0017: 0001 JMP 1 # (0x0001) 103 | 0018: C002 LIT 16386 # (0x4002) 104 | 0019: 0001 JMP 1 # (0x0001) 105 | 001A: 800D LIT 13 # (0x000D) 106 | 001B: 4016 CALL 22 # (0x0016) 107 | 001C: 800A LIT 10 # (0x000A) 108 | 001D: 0016 JMP 22 # (0x0016) 109 | 001E: 8020 LIT 32 # (0x0020) 110 | 001F: 0016 JMP 22 # (0x0016) 111 | 0020: 401A CALL 26 # (0x001A) 112 | 0021: 4018 CALL 24 # (0x0018) 113 | 0022: 001E JMP 30 # (0x001E) 114 | 0023: 8001 LIT 1 # (0x0001) 115 | 0024: 4020 CALL 32 # (0x0020) 116 | 0025: 8024 LIT 36 # (0x0024) 117 | 0026: 6084 ALU 132 # (0x0084) 118 | T T->N d+1 119 | 0027: 4018 CALL 24 # (0x0018) 120 | 0028: 0018 JMP 24 # (0x0018) 121 | 0029: 8002 LIT 2 # (0x0002) 122 | 002A: 4020 CALL 32 # (0x0020) 123 | 002B: 800B LIT 11 # (0x000B) 124 | 002C: 8016 LIT 22 # (0x0016) 125 | 002D: 8022 LIT 34 # (0x0022) 126 | 002E: 6008 ALU 8 # (0x0008) 127 | T d-1 128 | 002F: 4018 CALL 24 # (0x0018) 129 | 0030: 0018 JMP 24 # (0x0018) 130 | 0031: 8003 LIT 3 # (0x0003) 131 | 0032: 4020 CALL 32 # (0x0020) 132 | 0033: 800B LIT 11 # (0x000B) 133 | 0034: 8016 LIT 22 # (0x0016) 134 | 0035: 6180 ALU 384 # (0x0180) 135 | N T->N 136 | 0036: 4018 CALL 24 # (0x0018) 137 | 0037: 0018 JMP 24 # (0x0018) 138 | 0038: 8004 LIT 4 # (0x0004) 139 | 0039: 4020 CALL 32 # (0x0020) 140 | 003A: 800B LIT 11 # (0x000B) 141 | 003B: 8016 LIT 22 # (0x0016) 142 | 003C: 8023 LIT 35 # (0x0023) 143 | 003D: 6108 ALU 264 # (0x0108) 144 | N d-1 145 | 003E: 4018 CALL 24 # (0x0018) 146 | 003F: 0018 JMP 24 # (0x0018) 147 | 0040: 8005 LIT 5 # (0x0005) 148 | 0041: 4020 CALL 32 # (0x0020) 149 | 0042: 8053 LIT 83 # (0x0053) 150 | 0043: 8013 LIT 19 # (0x0013) 151 | 0044: 6184 ALU 388 # (0x0184) 152 | N T->N d+1 153 | 0045: 4018 CALL 24 # (0x0018) 154 | 0046: 4018 CALL 24 # (0x0018) 155 | 0047: 0018 JMP 24 # (0x0018) 156 | 0048: 8006 LIT 6 # (0x0006) 157 | 0049: 4020 CALL 32 # (0x0020) 158 | 004A: 8000 LIT 0 # (0x0000) 159 | 004B: 0018 JMP 24 # (0x0018) 160 | 004C: 8007 LIT 7 # (0x0007) 161 | 004D: 4020 CALL 32 # (0x0020) 162 | 004E: B039 LIT 12345 # (0x3039) 163 | 004F: 0018 JMP 24 # (0x0018) 164 | 0050: 8008 LIT 8 # (0x0008) 165 | 0051: 4020 CALL 32 # (0x0020) 166 | 0052: 8047 LIT 71 # (0x0047) 167 | 0053: 807B LIT 123 # (0x007B) 168 | 0054: 6149 ALU 329 # (0x0149) 169 | N r+1 T->R d-1 170 | 0055: 4018 CALL 24 # (0x0018) 171 | 0056: 828E LIT 654 # (0x028E) 172 | 0057: 4018 CALL 24 # (0x0018) 173 | 0058: 6B06 ALU 2822 # (0x0B06) 174 | R r-1 d+1 175 | 0059: 0018 JMP 24 # (0x0018) 176 | 005A: 8009 LIT 9 # (0x0009) 177 | 005B: 4020 CALL 32 # (0x0020) 178 | 005C: 8051 LIT 81 # (0x0051) 179 | 005D: 6149 ALU 329 # (0x0149) 180 | N r+1 T->R d-1 181 | 005E: 80EA LIT 234 # (0x00EA) 182 | 005F: 4018 CALL 24 # (0x0018) 183 | 0060: 6B04 ALU 2820 # (0x0B04) 184 | R d+1 185 | 0061: 4018 CALL 24 # (0x0018) 186 | 0062: 6B06 ALU 2822 # (0x0B06) 187 | R r-1 d+1 188 | 0063: 0018 JMP 24 # (0x0018) 189 | 0064: 800A LIT 10 # (0x000A) 190 | 0065: 4020 CALL 32 # (0x0020) 191 | 0066: 8001 LIT 1 # (0x0001) 192 | 0067: 8002 LIT 2 # (0x0002) 193 | 0068: 8003 LIT 3 # (0x0003) 194 | 0069: 8004 LIT 4 # (0x0004) 195 | 006A: 6208 ALU 520 # (0x0208) 196 | T+N d-1 197 | 006B: 6208 ALU 520 # (0x0208) 198 | T+N d-1 199 | 006C: 6208 ALU 520 # (0x0208) 200 | T+N d-1 201 | 006D: 0018 JMP 24 # (0x0018) 202 | 006E: 800B LIT 11 # (0x000B) 203 | 006F: 4020 CALL 32 # (0x0020) 204 | 0070: 8007 LIT 7 # (0x0007) 205 | 0071: 8008 LIT 8 # (0x0008) 206 | 0072: 8009 LIT 9 # (0x0009) 207 | 0073: 6E84 ALU 3716 # (0x0E84) 208 | dsp T->N d+1 209 | 0074: 4018 CALL 24 # (0x0018) 210 | 0075: 4018 CALL 24 # (0x0018) 211 | 0076: 4018 CALL 24 # (0x0018) 212 | 0077: 0018 JMP 24 # (0x0018) 213 | 0078: 800C LIT 12 # (0x000C) 214 | 0079: 4020 CALL 32 # (0x0020) 215 | 007A: 8D11 LIT 3345 # (0x0D11) 216 | 007B: 6A00 ALU 2560 # (0x0A00) 217 | T-1 218 | 007C: 0018 JMP 24 # (0x0018) 219 | 007D: 804F LIT 79 # (0x004F) 220 | 007E: 4016 CALL 22 # (0x0016) 221 | 007F: 804B LIT 75 # (0x004B) 222 | 0080: 0016 JMP 22 # (0x0016) 223 | 0081: 710A ALU 4362 # (0x110A) 224 | N R->PC r-1 d-1 225 | 0082: 710A ALU 4362 # (0x110A) 226 | N R->PC r-1 d-1 227 | 0083: D759 LIT 22361 # (0x5759) 228 | 0084: 0082 JMP 130 # (0x0082) 229 | 0085: 4023 CALL 35 # (0x0023) 230 | 0086: 4029 CALL 41 # (0x0029) 231 | 0087: 4031 CALL 49 # (0x0031) 232 | 0088: 4038 CALL 56 # (0x0038) 233 | 0089: 4040 CALL 64 # (0x0040) 234 | 008A: 4048 CALL 72 # (0x0048) 235 | 008B: 404C CALL 76 # (0x004C) 236 | 008C: 4050 CALL 80 # (0x0050) 237 | 008D: 405A CALL 90 # (0x005A) 238 | 008E: 4064 CALL 100 # (0x0064) 239 | 008F: 406E CALL 110 # (0x006E) 240 | 0090: 4078 CALL 120 # (0x0078) 241 | 0091: 401A CALL 26 # (0x001A) 242 | 0092: 8073 LIT 115 # (0x0073) 243 | 0093: 4016 CALL 22 # (0x0016) 244 | 0094: 4083 CALL 131 # (0x0083) 245 | 0095: 8065 LIT 101 # (0x0065) 246 | 0096: 4016 CALL 22 # (0x0016) 247 | 0097: 401A CALL 26 # (0x001A) 248 | 0098: 407D CALL 125 # (0x007D) 249 | 0099: 001A JMP 26 # (0x001A) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------