├── .gitignore ├── .mark ├── DOC.txt ├── Makefile ├── Makefile.depend ├── Makefile_6502 ├── Makefile_68000 ├── README.md ├── actions.h ├── actions_6502.c ├── actions_68000.c ├── buildStuff.h ├── buildStuff1.c ├── buildStuff2.c ├── buildStuff3.c ├── builtInFunctions.c ├── builtInFunctions.h ├── builtInFunsSD_6502.c ├── builtInFunsSD_68000.c ├── conditionDefs_6502.h ├── conditionDefs_68000.h ├── debugPrint.c ├── debugPrint.h ├── debugPrintSD_6502.c ├── debugPrintSD_68000.c ├── doc ├── genmacros.itr ├── handyHelpfulHints.t ├── linkerReleaseNotes ├── macros.itr ├── macross.1 ├── slinky.1 ├── writeup_6502.itr ├── writeup_6502.pdf ├── writeup_6502.ps └── writeup_68000.itr ├── driver.c ├── emitBranch.h ├── emitBranch_6502.c ├── emitBranch_68000.c ├── emitStuff.c ├── emitStuff.h ├── encode.c ├── encode.h ├── errorStuff.c ├── errorStuff.h ├── errorfyle ├── expressionSemantics.c ├── expressionSemantics.h ├── fixups.c ├── fixups.h ├── garbage.c ├── garbage.h ├── globals.c ├── initialize.c ├── initialize.h ├── lexer.c ├── lexer.h ├── lexerTables.h ├── listing.c ├── listing.h ├── lookups.c ├── lookups.h ├── macrossGlobals.h ├── macrossTables_6502.c ├── macrossTables_68000.c ├── macrossTypes.h ├── macross_6502.y ├── macross_68000.y ├── main.c ├── malloc.c ├── notes68 ├── 1.am ├── 2.amg ├── 3.os └── 4.ic ├── object.c ├── object.h ├── operandBody_6502.h ├── operandBody_68000.h ├── operandDefs_6502.h ├── operandDefs_68000.h ├── operandStuff.h ├── operandStuffSD_6502.c ├── operandStuffSD_68000.c ├── opt ├── .mark ├── Makefile ├── Makefile_6502 └── Makefile_68000 ├── parserMisc.c ├── parserMisc.h ├── semanticMisc.c ├── semanticMisc.h ├── slinky ├── .mark ├── DOC ├── Makefile ├── Makefile.depend ├── builtins.c ├── builtins.h ├── debugPrint.c ├── debugPrint.h ├── errorStuff.c ├── errorStuff.h ├── errorfyle ├── expr.c ├── expr.h ├── globals.c ├── initialize.c ├── initialize.h ├── instantiate.c ├── instantiate.h ├── link.c ├── link.h ├── main.c ├── main.h ├── map.c ├── map.h ├── opt │ ├── .mark │ └── Makefile ├── poke.c ├── poke.h ├── read.c ├── read.h ├── relocate.c ├── relocate.h ├── slinkyExpressions.h ├── slinkyGlobals.h ├── slinkyTables.c ├── slinkyTables.h ├── slinkyTypes.h ├── write.c └── write.h ├── slinkyExpressions.h ├── statementSemantics.c ├── statementSemantics.h ├── structSemantics.c ├── structSemantics.h ├── tokenStrings.h ├── tokenStrings_6502.c └── tokenStrings_68000.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *~ 3 | y.tab.c 4 | y.tab.h 5 | macross 6 | slinky/slinky 7 | -------------------------------------------------------------------------------- /.mark: -------------------------------------------------------------------------------- 1 | Mon Feb 2 23:18:33 PST 1987 2 | -------------------------------------------------------------------------------- /DOC.txt: -------------------------------------------------------------------------------- 1 | /u0/chip/macross: 2 | This directory contains the source to Macross. Here's what's here: 3 | 4 | DOC - this file 5 | 6 | Makefile - current makefile 7 | Makefile_6502 - makefile for 6502 version 8 | Makefile_68000 - makefile for 68000 9 | 10 | There are both 6502 and 68000 versions of Macross, though the 68000 11 | version has not been very well tested. Source for both is here. Source files 12 | which come in different flavors for the different versions are marked 6502 or 13 | 68000 in their names as appropriate. There are two different Makefiles also. 14 | At any given time, either the 6502 version or the 68000 version is the 15 | 'working' version. The 'working' version is what the default makefile 16 | 'Makefile' will produce. Typing 'make foobar' will change the working version 17 | by swapping the makefiles. 18 | 19 | *.c, *.h, *.y - source for the program 20 | 21 | doc/ - the manual and other user documentation are here 22 | notes68/ - notes on 68000 syntax and operand structure 23 | opt/ - working directory for 'optimized' version. When I 24 | was developing the program, I needed to keep two separate copies of 25 | the source and object code. This is because the C compiler can 26 | compile with debugging or with optimization, but not both. The 27 | version that folks use needs to be compiled with optimization, but I 28 | need a version with debugging to fix any problems that crop up. Since 29 | the time to recompile the whole thing is so enormous, it was easiest 30 | to keep two copies. In the interest of saving file space, all that is 31 | in this directory now, however, are the Makefiles for compiling with 32 | optimization. 33 | 34 | slinky/ - Slinky lives here 35 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # to make for another target CPU, redefine PROC to the name of the target 2 | # processor, e.g., 68000 3 | PROC =6502 4 | 5 | MACROSS_OBJECTS = actions_$(PROC).o buildStuff1.o buildStuff2.o \ 6 | buildStuff3.o builtInFunctions.o \ 7 | builtInFunsSD_$(PROC).o debugPrint.o \ 8 | debugPrintSD_$(PROC).o emitBranch_$(PROC).o \ 9 | emitStuff.o encode.o errorStuff.o \ 10 | expressionSemantics.o fixups.o garbage.o globals.o \ 11 | initialize.o lexer.o listing.o lookups.o \ 12 | macrossTables_$(PROC).o main.o object.o \ 13 | operandStuffSD_$(PROC).o parserMisc.o \ 14 | semanticMisc.o statementSemantics.o \ 15 | structSemantics.o tokenStrings_$(PROC).o y.tab.o 16 | 17 | # Macross is not 64-bit clean and it does a lot of silent downcasting 18 | # to simulate subclasses and uses int and void * interchangably a 19 | # bunch. gcc calls these the int-conversion and 20 | # incompatible-pointer-types warnings. 21 | CFLAGS=-m32 -O2 -ansi -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) 22 | LDFLAGS=-m32 23 | 24 | # If yacc is notionally present on a system, it's usually actually 25 | # bison in a compatibility mode. bison is available by name more often 26 | # than yacc itself is. 27 | YACC=bison -y 28 | #YACC=yacc 29 | 30 | # Pick a compiler if you have one in particular you want. 31 | CC=cc 32 | #CC=gcc 33 | #CC=clang 34 | 35 | macross: $(MACROSS_OBJECTS) 36 | $(CC) $(LDFLAGS) -o macross $(MACROSS_OBJECTS) 37 | 38 | # This is a switcher program between multiple versions of Macross, not 39 | # really a build product 40 | # driver: driver.c 41 | # cc $(CFLAGS) -o driver driver.c 42 | 43 | y.tab.c y.tab.h: macross_$(PROC).y 44 | $(YACC) -d macross_$(PROC).y 45 | 46 | clean: 47 | rm -f *.o y.tab.c y.tab.h macross 48 | 49 | love: 50 | @echo "Not war?" 51 | 52 | .c.o: 53 | $(CC) $(CFLAGS) -c $< 54 | 55 | Makefile.depend: 56 | makedepend -Y -DTARGET_CPU=CPU_$(PROC) -f - *.c > Makefile.depend 57 | 58 | depend: Makefile.depend 59 | 60 | include Makefile.depend 61 | -------------------------------------------------------------------------------- /Makefile.depend: -------------------------------------------------------------------------------- 1 | # DO NOT DELETE 2 | 3 | actions_6502.o: macrossTypes.h operandDefs_6502.h conditionDefs_6502.h 4 | actions_6502.o: macrossGlobals.h actions.h macrossTypes.h emitStuff.h 5 | actions_6502.o: errorStuff.h semanticMisc.h 6 | actions_68000.o: macrossTypes.h macrossGlobals.h 7 | buildStuff1.o: macrossTypes.h macrossGlobals.h errorStuff.h lookups.h 8 | buildStuff1.o: parserMisc.h 9 | buildStuff2.o: macrossTypes.h macrossGlobals.h lookups.h parserMisc.h 10 | buildStuff3.o: macrossTypes.h macrossGlobals.h lookups.h 11 | builtInFunctions.o: macrossTypes.h macrossGlobals.h buildStuff.h errorStuff.h 12 | builtInFunctions.o: expressionSemantics.h garbage.h lexer.h lookups.h 13 | builtInFunctions.o: operandStuff.h semanticMisc.h statementSemantics.h 14 | builtInFunsSD_6502.o: macrossTypes.h macrossGlobals.h builtInFunctions.h 15 | builtInFunsSD_6502.o: operandStuff.h 16 | builtInFunsSD_68000.o: macrossTypes.h macrossGlobals.h 17 | debugPrint.o: macrossTypes.h macrossGlobals.h debugPrint.h y.tab.h 18 | debugPrintSD_6502.o: macrossTypes.h macrossGlobals.h debugPrint.h y.tab.h 19 | debugPrintSD_68000.o: macrossTypes.h macrossGlobals.h y.tab.h 20 | emitBranch_6502.o: macrossTypes.h macrossGlobals.h buildStuff.h emitStuff.h 21 | emitBranch_6502.o: parserMisc.h semanticMisc.h 22 | emitBranch_68000.o: macrossTypes.h macrossGlobals.h 23 | emitStuff.o: macrossTypes.h macrossGlobals.h actions.h debugPrint.h 24 | emitStuff.o: errorStuff.h semanticMisc.h 25 | encode.o: macrossTypes.h macrossGlobals.h y.tab.h encode.h debugPrint.h 26 | encode.o: errorStuff.h parserMisc.h semanticMisc.h slinkyExpressions.h 27 | errorStuff.o: macrossTypes.h macrossGlobals.h errorStuff.h initialize.h 28 | expressionSemantics.o: macrossTypes.h macrossGlobals.h y.tab.h 29 | expressionSemantics.o: builtInFunctions.h errorStuff.h expressionSemantics.h 30 | expressionSemantics.o: fixups.h listing.h lookups.h operandStuff.h 31 | expressionSemantics.o: parserMisc.h semanticMisc.h statementSemantics.h 32 | expressionSemantics.o: tokenStrings.h 33 | fixups.o: macrossTypes.h macrossGlobals.h errorStuff.h expressionSemantics.h 34 | fixups.o: fixups.h listing.h operandStuff.h parserMisc.h semanticMisc.h 35 | fixups.o: tokenStrings.h 36 | garbage.o: macrossTypes.h macrossGlobals.h garbage.h operandStuff.h 37 | garbage.o: parserMisc.h y.tab.h 38 | globals.o: macrossTypes.h macrossGlobals.h 39 | initialize.o: macrossTypes.h macrossGlobals.h initialize.h errorStuff.h 40 | initialize.o: lexer.h lookups.h semanticMisc.h 41 | lexer.o: macrossTypes.h macrossGlobals.h y.tab.h debugPrint.h errorStuff.h 42 | lexer.o: lexer.h lexerTables.h listing.h lookups.h parserMisc.h 43 | listing.o: macrossTypes.h macrossGlobals.h emitStuff.h lexer.h listing.h 44 | listing.o: semanticMisc.h 45 | lookups.o: macrossTypes.h macrossGlobals.h buildStuff.h errorStuff.h 46 | lookups.o: garbage.h listing.h lookups.h operandStuff.h parserMisc.h 47 | lookups.o: semanticMisc.h 48 | macrossTables_6502.o: macrossTypes.h actions.h builtInFunctions.h y.tab.h 49 | macrossTables_68000.o: macrossTypes.h y.tab.h 50 | main.o: macrossTypes.h macrossGlobals.h initialize.h semanticMisc.h y.tab.h 51 | object.o: macrossTypes.h macrossGlobals.h debugPrint.h encode.h 52 | object.o: expressionSemantics.h fixups.h garbage.h lookups.h object.h 53 | object.o: semanticMisc.h 54 | operandStuffSD_6502.o: macrossTypes.h macrossGlobals.h errorStuff.h 55 | operandStuffSD_6502.o: expressionSemantics.h fixups.h garbage.h listing.h 56 | operandStuffSD_6502.o: operandStuff.h parserMisc.h semanticMisc.h 57 | operandStuffSD_6502.o: statementSemantics.h 58 | operandStuffSD_68000.o: macrossTypes.h macrossGlobals.h 59 | parserMisc.o: macrossTypes.h macrossGlobals.h y.tab.h buildStuff.h fixups.h 60 | parserMisc.o: initialize.h errorStuff.h parserMisc.h 61 | semanticMisc.o: macrossTypes.h macrossGlobals.h y.tab.h semanticMisc.h 62 | semanticMisc.o: buildStuff.h debugPrint.h emitStuff.h errorStuff.h 63 | semanticMisc.o: expressionSemantics.h fixups.h listing.h lookups.h object.h 64 | semanticMisc.o: operandStuff.h parserMisc.h 65 | statementSemantics.o: macrossTypes.h macrossGlobals.h actions.h debugPrint.h 66 | statementSemantics.o: emitBranch.h emitStuff.h errorStuff.h 67 | statementSemantics.o: expressionSemantics.h fixups.h garbage.h lexer.h 68 | statementSemantics.o: listing.h lookups.h operandStuff.h parserMisc.h 69 | statementSemantics.o: semanticMisc.h statementSemantics.h structSemantics.h 70 | statementSemantics.o: tokenStrings.h 71 | structSemantics.o: macrossTypes.h macrossGlobals.h emitStuff.h errorStuff.h 72 | structSemantics.o: listing.h parserMisc.h semanticMisc.h statementSemantics.h 73 | structSemantics.o: structSemantics.h 74 | tokenStrings_6502.o: macrossTypes.h macrossGlobals.h 75 | tokenStrings_68000.o: macrossTypes.h macrossGlobals.h 76 | y.tab.o: macrossTypes.h macrossGlobals.h buildStuff.h errorStuff.h lexer.h 77 | y.tab.o: lookups.h operandStuff.h parserMisc.h semanticMisc.h 78 | y.tab.o: statementSemantics.h 79 | -------------------------------------------------------------------------------- /Makefile_6502: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .o .c .h .run 2 | 3 | # to make for another target CPU, redefine PROC to the name of the target 4 | # processor, e.g., 68000 5 | PROC =6502 6 | 7 | OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\ 8 | buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\ 9 | emitBranch.o emitStuff.o errorStuff.o expressionSemantics.o fixups.o\ 10 | garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ 11 | malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.o\ 12 | statementSemantics.o structSemantics.o tokenStrings.o 13 | 14 | SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\ 15 | buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\ 16 | debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c errorStuff.c\ 17 | expressionSemantics.c fixups.c garbage.c initialize.c lexer.c listing.c\ 18 | lookups.c macrossTables_$(PROC).c main.c malloc.c object.c\ 19 | operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ 20 | structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ 21 | macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 22 | conditionDefs_$(PROC).h driver.c 23 | 24 | HEADERS = macrossTypes.h macrossGlobals.h 25 | 26 | .c.o: 27 | cc -c -g -DTARGET_CPU=CPU_$(PROC) $*.c 28 | 29 | .c.run: 30 | cc -o $* $*.c 31 | 32 | macross: $(OBJECTS) 33 | cc -g -o macross $(OBJECTS) 34 | 35 | driver: driver.c 36 | cc -o driver driver.c 37 | 38 | update: .mark 39 | kessel "(cd /u0/chip/macross; make macross >&errorfyle)" & 40 | 41 | install: macross 42 | cp macross /u1/gg/bin/macross_tmp 43 | strip /u1/gg/bin/macross_tmp 44 | mv /u1/gg/bin/macross_$(PROC) /u1/gg/bin/macross_$(PROC).old 45 | mv /u1/gg/bin/macross_tmp /u1/gg/bin/macross_$(PROC) 46 | cp /u1/gg/bin/macross_$(PROC) /net/mycroft/u1/gg/bin 47 | cp /u1/gg/bin/macross_$(PROC) /net/shem/u1/gg/bin 48 | cp /u1/gg/bin/macross_$(PROC) /net/weyr/u1/gg/bin 49 | 50 | dinstall: driver 51 | cp driver /u1/gg/bin/driver_tmp 52 | strip /u1/gg/bin/driver_tmp 53 | mv /u1/gg/bin/driver_tmp /u1/gg/bin/driver/macross 54 | cp /u1/gg/bin/driver /net/mycroft/u1/gg/bin/macross 55 | cp /u1/gg/bin/driver /net/shem/u1/gg/bin/macross 56 | cp /u1/gg/bin/driver /net/weyr/u1/gg/bin/macross 57 | 58 | change: 59 | rm *.o 60 | rm *.tab.* 61 | cp Makefile_68000 Makefile 62 | 63 | move: .mark 64 | 65 | .mark: $(SOURCES) 66 | cp $? /net/kessel/u0/chip/macross 67 | cp $? /net/kessel/u0/chip/macross/prof 68 | cp $? opt 69 | date >.mark 70 | date >/net/kessel/u0/chip/macross/.mark 71 | date >/net/kessel/u0/chip/macross/prof/.mark 72 | date >opt/.mark 73 | 74 | macrossTypes.h: macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 75 | conditionDefs_$(PROC).h 76 | 77 | actions.o: actions_$(PROC).c $(HEADERS) 78 | cc -c -g -DTARGET_CPU=CPU_$(PROC) actions_$(PROC).c 79 | mv actions_$(PROC).o actions.o 80 | 81 | buildStuff1.o: buildStuff1.c $(HEADERS) 82 | 83 | buildStuff2.o: buildStuff2.c $(HEADERS) 84 | 85 | buildStuff3.o: buildStuff3.c $(HEADERS) 86 | 87 | builtInFunctions.o: builtInFunctions.c $(HEADERS) 88 | 89 | builtInFunsSD.o: builtInFunsSD_$(PROC).c $(HEADERS) 90 | cc -c -g -DTARGET_CPU=CPU_$(PROC) builtInFunsSD_$(PROC).c 91 | mv builtInFunsSD_$(PROC).o builtInFunsSD.o 92 | 93 | debugPrint.o: debugPrint.c y.tab.h $(HEADERS) 94 | 95 | debugPrintSD.o: debugPrintSD_$(PROC).c y.tab.h $(HEADERS) 96 | cc -c -g -DTARGET_CPU=CPU_$(PROC) debugPrintSD_$(PROC).c 97 | mv debugPrintSD_$(PROC).o debugPrintSD.o 98 | 99 | emitBranch.o: emitBranch_$(PROC).c $(HEADERS) 100 | cc -c -g -DTARGET_CPU=CPU_$(PROC) emitBranch_$(PROC).c 101 | mv emitBranch_$(PROC).o emitBranch.o 102 | 103 | emitStuff.o: emitStuff.c $(HEADERS) 104 | cc -c -g -DTARGET_CPU=CPU_$(PROC) emitStuff.c 105 | 106 | errorStuff.o: errorStuff.c $(HEADERS) 107 | 108 | expressionSemantics.o: expressionSemantics.c y.tab.h $(HEADERS) 109 | 110 | fixups.o: fixups.c $(HEADERS) 111 | 112 | garbage.o: garbage.c y.tab.h $(HEADERS) 113 | 114 | initialize.o: initialize.c $(HEADERS) 115 | 116 | lexer.o: lexer.c lexerTables.h y.tab.h $(HEADERS) 117 | 118 | listing.o: listing.c $(HEADERS) 119 | 120 | lookups.o: lookups.c $(HEADERS) 121 | 122 | macrossTables.o: macrossTables_$(PROC).c y.tab.h macrossTypes.h 123 | cc -c -g -DTARGET_CPU=CPU_$(PROC) macrossTables_$(PROC).c 124 | mv macrossTables_$(PROC).o macrossTables.o 125 | 126 | malloc.o: malloc.c 127 | 128 | main.o: main.c $(HEADERS) 129 | 130 | object.o: object.c $(HEADERS) 131 | 132 | operandStuffSD.o: operandStuffSD_$(PROC).c $(HEADERS) 133 | cc -c -g -DTARGET_CPU=CPU_$(PROC) operandStuffSD_$(PROC).c 134 | mv operandStuffSD_$(PROC).o operandStuffSD.o 135 | 136 | parserMisc.o: parserMisc.c y.tab.h $(HEADERS) 137 | 138 | semanticMisc.o: semanticMisc.c $(HEADERS) 139 | 140 | statementSemantics.o: statementSemantics.c $(HEADERS) 141 | 142 | structSemantics.o: structSemantics.c $(HEADERS) 143 | 144 | tokenStrings.o: tokenStrings_$(PROC).c $(HEADERS) 145 | cc -c -g -DTARGET_CPU=CPU_$(PROC) tokenStrings_$(PROC).c 146 | mv tokenStrings_$(PROC).o tokenStrings.o 147 | 148 | y.tab.o: y.tab.c $(HEADERS) 149 | cc -c -g -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) y.tab.c 150 | 151 | y.tab.c y.tab.h: macross_$(PROC).y 152 | yacc -d macross_$(PROC).y 153 | 154 | y.output: macross_$(PROC).y 155 | yacc -vd macross_$(PROC).y 156 | 157 | cleanup: 158 | /bin/rm -f *.o y.output y.tab.c y.tab.h macross 159 | 160 | love: 161 | @echo "Not war?" 162 | 163 | -------------------------------------------------------------------------------- /Makefile_68000: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .o .c .h .run 2 | 3 | # to make for another target CPU, redefine PROC to the name of the target 4 | # processor, e.g., 68000 5 | PROC =68000 6 | 7 | OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\ 8 | buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\ 9 | emitBranch.o emitStuff.o errorStuff.o expressionSemantics.o fixups.o\ 10 | garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ 11 | malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.o\ 12 | statementSemantics.o structSemantics.o tokenStrings.o 13 | 14 | SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\ 15 | buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\ 16 | debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c errorStuff.c\ 17 | expressionSemantics.c fixups.c garbage.c initialize.c lexer.c listing.c\ 18 | lookups.c macrossTables_$(PROC).c main.c malloc.c object.c\ 19 | operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ 20 | structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ 21 | macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 22 | conditionDefs_$(PROC).h driver.c 23 | 24 | HEADERS = macrossTypes.h macrossGlobals.h 25 | 26 | .c.o: 27 | cc -c -g -DTARGET_CPU=CPU_$(PROC) $*.c 28 | 29 | .c.run: 30 | cc -o $* $*.c 31 | 32 | macross: $(OBJECTS) 33 | cc -g -o macross $(OBJECTS) 34 | 35 | driver: driver.c 36 | cc -o driver driver.c 37 | 38 | update: .mark 39 | kessel "(cd /u0/chip/macross; make macross >&errorfyle)" & 40 | 41 | install: macross 42 | cp macross /u1/gg/bin/macross_tmp 43 | strip /u1/gg/bin/macross_tmp 44 | mv /u1/gg/bin/macross_$(PROC) /u1/gg/bin/macross_$(PROC).old 45 | mv /u1/gg/bin/macross_tmp /u1/gg/bin/macross_$(PROC) 46 | cp /u1/gg/bin/macross_$(PROC) /net/mycroft/u1/gg/bin 47 | cp /u1/gg/bin/macross_$(PROC) /net/shem/u1/gg/bin 48 | cp /u1/gg/bin/macross_$(PROC) /net/weyr/u1/gg/bin 49 | 50 | dinstall: driver 51 | cp driver /u1/gg/bin/driver_tmp 52 | strip /u1/gg/bin/driver_tmp 53 | mv /u1/gg/bin/driver_tmp /u1/gg/bin/driver/macross 54 | cp /u1/gg/bin/driver /net/mycroft/u1/gg/bin/macross 55 | cp /u1/gg/bin/driver /net/shem/u1/gg/bin/macross 56 | cp /u1/gg/bin/driver /net/weyr/u1/gg/bin/macross 57 | 58 | change: 59 | rm *.o 60 | rm *.tab.* 61 | cp Makefile_6502 Makefile 62 | 63 | move: .mark 64 | 65 | .mark: $(SOURCES) 66 | cp $? /net/kessel/u0/chip/macross 67 | cp $? /net/kessel/u0/chip/macross/prof 68 | cp $? opt 69 | date >.mark 70 | date >/net/kessel/u0/chip/macross/.mark 71 | date >/net/kessel/u0/chip/macross/prof/.mark 72 | date >opt/.mark 73 | 74 | macrossTypes.h: macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 75 | conditionDefs_$(PROC).h 76 | 77 | actions.o: actions_$(PROC).c $(HEADERS) 78 | cc -c -g -DTARGET_CPU=CPU_$(PROC) actions_$(PROC).c 79 | mv actions_$(PROC).o actions.o 80 | 81 | buildStuff1.o: buildStuff1.c $(HEADERS) 82 | 83 | buildStuff2.o: buildStuff2.c $(HEADERS) 84 | 85 | buildStuff3.o: buildStuff3.c $(HEADERS) 86 | 87 | builtInFunctions.o: builtInFunctions.c $(HEADERS) 88 | 89 | builtInFunsSD.o: builtInFunsSD_$(PROC).c $(HEADERS) 90 | cc -c -g -DTARGET_CPU=CPU_$(PROC) builtInFunsSD_$(PROC).c 91 | mv builtInFunsSD_$(PROC).o builtInFunsSD.o 92 | 93 | debugPrint.o: debugPrint.c y.tab.h $(HEADERS) 94 | 95 | debugPrintSD.o: debugPrintSD_$(PROC).c y.tab.h $(HEADERS) 96 | cc -c -g -DTARGET_CPU=CPU_$(PROC) debugPrintSD_$(PROC).c 97 | mv debugPrintSD_$(PROC).o debugPrintSD.o 98 | 99 | emitBranch.o: emitBranch_$(PROC).c $(HEADERS) 100 | cc -c -g -DTARGET_CPU=CPU_$(PROC) emitBranch_$(PROC).c 101 | mv emitBranch_$(PROC).o emitBranch.o 102 | 103 | emitStuff.o: emitStuff.c $(HEADERS) 104 | cc -c -g -DTARGET_CPU=CPU_$(PROC) emitStuff.c 105 | 106 | errorStuff.o: errorStuff.c $(HEADERS) 107 | 108 | expressionSemantics.o: expressionSemantics.c y.tab.h $(HEADERS) 109 | 110 | fixups.o: fixups.c $(HEADERS) 111 | 112 | garbage.o: garbage.c y.tab.h $(HEADERS) 113 | 114 | initialize.o: initialize.c $(HEADERS) 115 | 116 | lexer.o: lexer.c lexerTables.h y.tab.h $(HEADERS) 117 | 118 | listing.o: listing.c $(HEADERS) 119 | 120 | lookups.o: lookups.c $(HEADERS) 121 | 122 | macrossTables.o: macrossTables_$(PROC).c y.tab.h macrossTypes.h 123 | cc -c -g -DTARGET_CPU=CPU_$(PROC) macrossTables_$(PROC).c 124 | mv macrossTables_$(PROC).o macrossTables.o 125 | 126 | malloc.o: malloc.c 127 | 128 | main.o: main.c $(HEADERS) 129 | 130 | object.o: object.c $(HEADERS) 131 | 132 | operandStuffSD.o: operandStuffSD_$(PROC).c $(HEADERS) 133 | cc -c -g -DTARGET_CPU=CPU_$(PROC) operandStuffSD_$(PROC).c 134 | mv operandStuffSD_$(PROC).o operandStuffSD.o 135 | 136 | parserMisc.o: parserMisc.c y.tab.h $(HEADERS) 137 | 138 | semanticMisc.o: semanticMisc.c $(HEADERS) 139 | 140 | statementSemantics.o: statementSemantics.c $(HEADERS) 141 | 142 | structSemantics.o: structSemantics.c $(HEADERS) 143 | 144 | tokenStrings.o: tokenStrings_$(PROC).c $(HEADERS) 145 | cc -c -g -DTARGET_CPU=CPU_$(PROC) tokenStrings_$(PROC).c 146 | mv tokenStrings_$(PROC).o tokenStrings.o 147 | 148 | y.tab.o: y.tab.c $(HEADERS) 149 | cc -c -g -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) y.tab.c 150 | 151 | y.tab.c y.tab.h: macross_$(PROC).y 152 | yacc -d macross_$(PROC).y 153 | 154 | y.output: macross_$(PROC).y 155 | yacc -vd macross_$(PROC).y 156 | 157 | cleanup: 158 | /bin/rm -f *.o y.output y.tab.c y.tab.h macross 159 | 160 | love: 161 | @echo "Not war?" 162 | 163 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # macross 6502, an assembler for people who hate assembly language 2 | 3 | *Macross* is a fancy macro cross assembler for the 6502. Macross assembles the given files in the order specified on the command line. Macross source file names must end with ``.m''. 4 | 5 | *Slinky* is a multi-file relocating object linker designed to be used in conjunction with the Macross assembler. Slinky links the given Macross object files in the order specified on the command line together into one executable object file. 6 | 7 | 8 | ## History 9 | 10 | Macross and Slinky were developed 1984-1987 by Chip Morningstar at Lucasfilm Ltd. for use in the game [Habitat](https://github.com/Museum-of-Art-and-Digital-Entertainment/habitat). 11 | 12 | The source has been resurrected in the context of preserving and restoring Habitat at [The Museum of Art and Digital Entertainment](http://www.themade.org/). 13 | 14 | 15 | ## Status 16 | 17 | The original archive contents are checked in as the first commit. Subsequent commits provide clean ups and compile fixes for modern machines. 18 | 19 | Currently, Macross and Slinky compile and work on OS X (32 bit). 20 | 21 | 22 | ## Documentation 23 | 24 | See the directory [doc](doc). 25 | 26 | 27 | ## License 28 | 29 | MIT -------------------------------------------------------------------------------- /actions.h: -------------------------------------------------------------------------------- 1 | #ifndef ACTIONS_H_ 2 | #define ACTIONS_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | void actionsDir1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 7 | void actionsDir2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 8 | void actionsDirIndir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 9 | void actionsDirX1(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 10 | void actionsDirX2(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 11 | void actionsDirX3(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 12 | void actionsDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 13 | void actionsImmDir(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 14 | void actionsImmDirX(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 15 | void actionsImmDirY(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 16 | void actionsImmIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 17 | void actionsIndex(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 18 | void actionsNone(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 19 | void actionsRelative(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 20 | bool isByte(int value); 21 | bool isByteOffset(int value); 22 | bool isWordOffset(int value); 23 | bool isByteAddress(valueType *value); 24 | bool isWord(int value); 25 | bool byteCheck(int value); 26 | bool wordCheck(int value); 27 | bool isDefined(valueType *value); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /buildStuff.h: -------------------------------------------------------------------------------- 1 | #ifndef BUILD_STUFF_H_ 2 | #define BUILD_STUFF_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | /* buildStuff1.c */ 7 | statementType *newStatement (statementKindType kind, statementBodyType body); 8 | statementType *buildAlignStatement (expressionType *expression); 9 | statementType *buildAssertStatement (expressionType *condition, expressionType *message); 10 | statementType *buildBlockStatement (expressionListType *expressionList); 11 | statementType *buildByteStatement (expressionListType *expressionList); 12 | statementType *buildConstrainStatement (expressionType *expression, blockType *block); 13 | statementType *buildDbyteStatement (expressionListType *expressionList); 14 | statementType *buildDefineStatement (stringType *name, expressionType *value); 15 | statementType *buildDoUntilStatement (blockType *body, conditionType condition); 16 | statementType *buildDoWhileStatement (blockType *body, conditionType condition); 17 | statementType *buildDoStatement (blockType *body, doEndType *end); 18 | statementType *buildExternStatement (identifierListType *identifierList); 19 | statementType *buildFreturnStatement (expressionType *expression); 20 | statementType *buildFunctionStatement (stringType *name, argumentDefinitionListType *arguments, blockType *body); 21 | statementType *buildGroupStatement (blockType *block); 22 | statementType *buildIfStatement (ifHeadType *head, ifContinuationType continuation, ifContinuationKindType continuationKind); 23 | statementType *buildIncludeStatement (expressionType *filename); 24 | statementType *buildInstructionStatement (opcodeTableEntryType *opcode, operandListType *operands); 25 | statementType *buildLongStatement (expressionListType *expressionList); 26 | statementType *buildMacroStatement (macroTableEntryType *macro, argumentDefinitionListType *arguments, blockType *body); 27 | statementType *buildMacroInstructionStatement (macroTableEntryType *macro, operandListType *operands); 28 | statementType *buildMdefineStatement (stringType *name, expressionType *value); 29 | statementType *buildMdoUntilStatement (blockType *body, struct expressionTermStruct *condition); 30 | statementType *buildMdoWhileStatement (blockType *body, expressionType *condition); 31 | statementType *buildMdoStatement (blockType *body, mdoEndType *end); 32 | statementType *buildMforStatement (forExpressionsType *forExpressions, blockType *body); 33 | statementType *buildMifStatement (mifHeadType *head, mifContinuationType continuation, ifContinuationKindType continuationKind); 34 | statementType *buildMswitchStatement (expressionType *switchExpression, caseListType *cases); 35 | statementType *buildMvariableStatement (stringType *name, expressionListType *value, expressionType *dimension); 36 | statementType *buildMwhileStatement (expressionType *condition, blockType *body); 37 | statementType *buildNullStatement (void); 38 | statementType *buildOrgStatement (expressionType *expression); 39 | statementType *buildPerformStatement (expressionType *expression); 40 | statementType *buildRelStatement (void); 41 | statementType *buildStartStatement (expressionType *expression); 42 | statementType *buildStringStatement (expressionListType *expressionList); 43 | statementType *buildStructStatement (symbolTableEntryType *name, blockType *body); 44 | statementType *buildTargetStatement (expressionType *expression); 45 | statementType *buildUndefineStatement (identifierListType *identifierList); 46 | statementType *buildVariableStatement (stringType *name, expressionListType *value, expressionType *dimension); 47 | statementType *buildWhileStatement (conditionType condition, blockType *body); 48 | statementType *buildWordStatement (expressionListType *expressionList); 49 | 50 | /* buildStuff2.c */ 51 | caseType *buildCase (expressionListType *caseTags, blockType *caseBody); 52 | doEndType *buildDoEnd (conditionType condition, doEndKindType kindOfDoEnd); 53 | forExpressionsType *buildForExpressions (expressionType *initExpression, expressionType *testExpression, expressionType *incrExpression); 54 | ifHeadType *buildIfHead (conditionType condition, blockType *block); 55 | mdoEndType *buildMdoEnd (expressionType *condition, doEndKindType kindOfMdoEnd); 56 | mifHeadType *buildMifHead (expressionType *condition, blockType *block); 57 | arrayTermType *buildArrayTerm (expressionType *array, expressionType *index); 58 | binopTermType *buildBinopTerm (binopKindType binop, expressionType *leftArgument, expressionType *rightArgument); 59 | functionCallTermType *buildFunctionCall (stringType *functionName, operandListType *arguments); 60 | postOpTermType *buildPostOpTerm (postOpKindType postOp, expressionType *postOpArgument); 61 | preOpTermType *buildPreOpTerm (preOpKindType preOp, expressionType *preOpArgument); 62 | unopTermType *buildUnopTerm (unopKindType unop, expressionType *unopArgument); 63 | expressionTermType *buildExpressionTerm (expressionTermKindType kindOfExpressionTerm, anyOldThing *arg1, anyOldThing *arg2, anyOldThing *arg3); 64 | macroTableEntryType *buildMacroTableEntry (stringType *name); 65 | symbolTableEntryType *buildSymbolTableEntry (stringType *name, symbolUsageKindType usage); 66 | codeBreakType *buildCodeBreak (codeBreakKindType kind, addressType address, int data); 67 | reservationListType *buildReservation (addressType startAddress, int blockSize, reservationListType *nextReservation); 68 | simpleFixupListType *buildSimpleFixupList (valueType locationToFixup, simpleFixupListType *previousList); 69 | 70 | /* buildStuff3.c */ 71 | argumentListHeadType *buildArgumentList (stringType *new, argumentListHeadType *rest, bool arrayTag); 72 | caseListHeadType *buildCaseList (caseType *new, caseListHeadType *rest); 73 | expressionListHeadType *buildExpressionList (expressionType *new, expressionListHeadType *rest); 74 | identifierListHeadType *buildIdentifierList (stringType *new, identifierListHeadType *rest, symbolUsageKindType usage); 75 | labelListHeadType *buildLabelList (symbolTableEntryType *new, labelListHeadType *rest); 76 | operandListHeadType *buildOperandList (operandType *new, operandListHeadType *rest); 77 | selectionListHeadType *buildSelectionList (selectionListType *new, selectionListHeadType *rest); 78 | statementListHeadType *buildStatementList (statementType *new, statementListHeadType *rest); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /builtInFunctions.h: -------------------------------------------------------------------------------- 1 | #ifndef BUILT_IN_FUNCTIONS_H_ 2 | #define BUILT_IN_FUNCTIONS_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | /* Platform-independent */ 7 | valueType *makeBooleanValue(int test); 8 | valueType *makeFailureValue(void); 9 | valueType *makeIntegerValue(int integer); 10 | valueType *makeOperandValue(operandType *operand); 11 | valueType *makeStringValue(stringType *string); 12 | valueType *makeUndefinedValue(void); 13 | valueType *addressModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 14 | valueType *applyBIF(operandListType *parameterList, fixupKindType kindOfFixup); 15 | valueType *arrayLengthBIF(operandListType *parameterList, fixupKindType kindOfFixup); 16 | valueType *atasciiBIF(operandListType *parameterList, fixupKindType kindOfFixup); 17 | valueType *atasciiColorBIF(operandListType *parameterList, fixupKindType kindOfFixup); 18 | valueType *debugModeOffBIF(operandListType *parameterList, fixupKindType kindOfFixup); 19 | valueType *debugModeOnBIF(operandListType *parameterList, fixupKindType kindOfFixup); 20 | valueType *emitModeOffBIF(operandListType *parameterList, fixupKindType kindOfFixup); 21 | valueType *emitModeOnBIF(operandListType *parameterList, fixupKindType kindOfFixup); 22 | valueType *isAbsoluteValueBIF(operandListType *parameterList, fixupKindType kindOfFixup); 23 | valueType *isBlockBIF(operandListType *parameterList, fixupKindType kindOfFixup); 24 | valueType *isBuiltInFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup); 25 | valueType *isConditionCodeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 26 | valueType *isDefinedBIF(operandListType *parameterList, fixupKindType kindOfFixup); 27 | valueType *isExternalBIF(operandListType *parameterList, fixupKindType kindOfFixup); 28 | valueType *isFieldBIF(operandListType *parameterList, fixupKindType kindOfFixup); 29 | valueType *isFunctionBIF(operandListType *parameterList, fixupKindType kindOfFixup); 30 | valueType *isRelocatableValueBIF(operandListType *parameterList, fixupKindType kindOfFixup); 31 | valueType *isStringBIF(operandListType *parameterList, fixupKindType kindOfFixup); 32 | valueType *isStructBIF(operandListType *parameterList, fixupKindType kindOfFixup); 33 | valueType *isSymbolBIF(operandListType *parameterList, fixupKindType kindOfFixup); 34 | valueType *listingOffBIF(operandListType *parameterList, fixupKindType kindOfFixup); 35 | valueType *listingOnBIF(operandListType *parameterList, fixupKindType kindOfFixup); 36 | valueType *makeArrayBIF(operandListType *parameterList, fixupKindType kindOfFixup); 37 | valueType *nthCharBIF(operandListType *parameterList, fixupKindType kindOfFixup); 38 | valueType *printfBIF(operandListType *parameterList, fixupKindType kindOfFixup); 39 | valueType *strcatBIF(operandListType *parameterList, fixupKindType kindOfFixup); 40 | valueType *strcmpBIF(operandListType *parameterList, fixupKindType kindOfFixup); 41 | valueType *strcmplcBIF(operandListType *parameterList, fixupKindType kindOfFixup); 42 | valueType *strlenBIF(operandListType *parameterList, fixupKindType kindOfFixup); 43 | valueType *substrBIF(operandListType *parameterList, fixupKindType kindOfFixup); 44 | valueType *symbolLookupBIF(operandListType *parameterList, fixupKindType kindOfFixup); 45 | valueType *symbolDefineBIF(operandListType *parameterList, fixupKindType kindOfFixup); 46 | valueType *symbolNameBIF(operandListType *parameterList, fixupKindType kindOfFixup); 47 | valueType *symbolUsageBIF(operandListType *parameterList, fixupKindType kindOfFixup); 48 | valueType *valueTypeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 49 | 50 | /* 6502-specific */ 51 | valueType *isARegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); 52 | valueType *isDirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 53 | valueType *isImmediateModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 54 | valueType *isIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 55 | valueType *isIndirectModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 56 | valueType *isPostIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 57 | valueType *isPreIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 58 | valueType *isXIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 59 | valueType *isXRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); 60 | valueType *isYIndexedModeBIF(operandListType *parameterList, fixupKindType kindOfFixup); 61 | valueType *isYRegisterBIF(operandListType *parameterList, fixupKindType kindOfFixup); 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /conditionDefs_6502.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | conditionDefs_6502.h -- Define types for 6502 branch condition codes. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 18-April-1985 28 | */ 29 | 30 | typedef enum { 31 | CARRY_COND, ZERO_COND, NEGATIVE_COND, OVERFLOW_COND, LT_COND, 32 | LEQ_COND, SLT_COND, SLEQ_COND, 33 | ALWAYS_COND, 34 | NOT_CARRY_COND, NOT_ZERO_COND, NOT_NEGATIVE_COND, 35 | NOT_OVERFLOW_COND, GEQ_COND, GT_COND, SGEQ_COND, SGT_COND, 36 | NEVER_COND, 37 | NOT_FOUND_COND, 38 | } conditionType; 39 | 40 | #define COMPOUND_BRANCH_MAX 3 41 | -------------------------------------------------------------------------------- /conditionDefs_68000.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | conditionDefs_68000.h -- Define types for 68000 condition codes. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 25-April-1985 28 | */ 29 | 30 | typedef enum { 31 | CARRY_COND, EQUAL_COND, OVERFLOW_COND, MINUS_COND, LT_COND, 32 | LEQ_COND, LOW_OR_SAME_COND, 33 | ALWAYS_COND, 34 | NOT_CARRY_COND, NOT_EQUAL_COND, NOT_OVERFLOW_COND, PLUS_COND, 35 | GEQ_COND, GT_COND, HIGH_COND, 36 | NEVER_COND, 37 | NOT_FOUND_COND, 38 | } conditionType; 39 | 40 | #define COMPOUND_BRANCH_MAX 1 41 | 42 | -------------------------------------------------------------------------------- /debugPrint.h: -------------------------------------------------------------------------------- 1 | #ifndef DEBUG_PRINT_H_ 2 | #define DEBUG_PRINT_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | /* Platform-independent */ 7 | void tab(void); 8 | void printAssignmentKind(assignmentKindType assignmentKind); 9 | void printExpressionKind(expressionTermKindType kind); 10 | stringType *statementKindString(statementKindType kind); 11 | void printStatementKind(statementKindType kind); 12 | void printValue(valueType *value); 13 | void printSymbol(symbolTableEntryType *symbol); 14 | void printArgumentDefinitionList(argumentDefinitionListType *list); 15 | void printBlock(blockType *block); 16 | void printArrayTerm(arrayTermType *arrayTerm); 17 | void printAssignmentTerm(binopTermType *assignmentTerm); 18 | void printBinopTerm(binopTermType *binopTerm); 19 | void printFunctionCall(functionCallTermType *functionCall); 20 | void printHere(void); 21 | void printIdentifier(symbolTableEntryType *identifier); 22 | void printNumber(numberTermType number); 23 | void printPostopTerm(postOpTermType *postopTerm); 24 | void printPreopTerm(preOpTermType *preopTerm); 25 | void printUnopTerm(unopTermType *unopTerm); 26 | void printExpression(expressionType *expression); 27 | void printExpressionList(expressionListType *expressionList); 28 | void printIdentifierList(identifierListType *identifierList); 29 | void printCase(caseType *aCase); 30 | void printCaseList(caseListType *caseList); 31 | void printMacro(macroTableEntryType *macroInstruction); 32 | void printOpcode(opcodeTableEntryType *opcode); 33 | void printOperandList(operandListType *operandList); 34 | void printAlignStatement(alignStatementBodyType *alignStatement); 35 | void printAssertStatement(assertStatementBodyType *assertStatement); 36 | void printBlockStatement(blockStatementBodyType *blockStatement); 37 | void printByteStatement(byteStatementBodyType *byteStatement); 38 | void printConstrainStatement(constrainStatementBodyType *constrainStatement); 39 | void printDbyteStatement(dbyteStatementBodyType *dbyteStatement); 40 | void printDefineStatement(defineStatementBodyType *defineStatement); 41 | void printDoUntilStatement(doUntilStatementBodyType *doUntilStatement); 42 | void printDoWhileStatement(doWhileStatementBodyType *doWhileStatement); 43 | void printExternStatement(externStatementBodyType *externStatement); 44 | void printFreturnStatement(freturnStatementBodyType *freturnStatement); 45 | void printFunctionStatement(functionStatementBodyType *functionStatement); 46 | void printIfStatement(ifStatementBodyType *ifStatement); 47 | void printIncludeStatement(includeStatementBodyType *includeStatement); 48 | void printInstructionStatement(instructionStatementBodyType *instructionStatement); 49 | void printLongStatement(longStatementBodyType *longStatement); 50 | void printMacroStatement(macroStatementBodyType *macroStatement); 51 | void printMdefineStatement(defineStatementBodyType *mdefineStatement); 52 | void printMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement); 53 | void printMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement); 54 | void printMforStatement(mforStatementBodyType *mforStatement); 55 | void printMifStatement(mifStatementBodyType *mifStatement); 56 | void printMswitchStatement(mswitchStatementBodyType *mswitchStatement); 57 | void printMvariableStatement(mvariableStatementBodyType *mvariableStatement); 58 | void printMwhileStatement(mwhileStatementBodyType *mwhileStatement); 59 | void printOrgStatement(orgStatementBodyType *orgStatement); 60 | void printPerformStatement(performStatementBodyType *performStatement); 61 | void printRelStatement(relStatementBodyType *relStatement); 62 | void printStartStatement(startStatementBodyType *startStatement); 63 | void printStringStatement(stringStatementBodyType *stringStatement); 64 | void printStructStatement(structStatementBodyType *structStatement); 65 | void printTargetStatement(targetStatementBodyType *targetStatement); 66 | void printUndefineStatement(undefineStatementBodyType *undefineStatement); 67 | void printVariableStatement(variableStatementBodyType *variableStatement); 68 | void printWhileStatement(whileStatementBodyType *whileStatement); 69 | void printWordStatement(wordStatementBodyType *wordStatement); 70 | void printLabelList(labelListType *labelList); 71 | void printStatementBody(statementKindType kind, statementBodyType body); 72 | void printStatement(statementType *statement); 73 | void printPendingFixupList(fixupListType *fixupList); 74 | void printCreateFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup); 75 | void printExpressionBuffer(void); 76 | void printOneCodeBuffer(codeSegmentType *codeSegment, int bufferNum); 77 | void printCodeBufferSection(codeRegionType *codeBufferSection); 78 | void printCodeBuffers(void); 79 | 80 | /* Platform-specific */ 81 | void printCondition(conditionType condition); 82 | void printOperandKind(operandKindType kind); 83 | void printToken(int token); 84 | void printOperand(operandType *operand); 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /doc/handyHelpfulHints.t: -------------------------------------------------------------------------------- 1 | Handy Helpful Hints for using make/macross/slinky 2 | 3 | 1. You need two header files: a header and a sub-header. The sub-header 4 | declares 'define' symbols, zero page labels (as local labels), macros, 5 | functions, and so on. The header includes the sub-header and then 6 | additionally contains 'extern' declarations for all program-space labels and 7 | non-zero page variable-space labels plus 'define' declarations which refer to 8 | externals. 9 | 10 | Non-zero page variable-space should be laid out in one file that includes just 11 | the sub-header. The rest of the program should be spread among files each of 12 | which includes the header. 13 | 14 | 2. In any given Macross assembly (usually one source file plus all of the 15 | other files that it 'include's), you can classify each symbol in two different 16 | orthogonal ways: whether it is global or local on the one hand and whether it 17 | is defined in this assembly or defined in some other assembly. 18 | 19 | Being defined means that the symbol has a value which is known and can 20 | therefore be used to generate code. If a symbol has a value when it is 21 | encountered during assembly, then that value can be used immediately. 22 | If not, then we must wait until linking when (presumably) the value will be 23 | known. 24 | 25 | Being global means that the symbol's value is known outside of the assembly in 26 | which the symbol is defined (i.e., that the value is "published" in the object 27 | file for use by the linker). Conversely, being local means that the value is 28 | known only in the one assembly. 29 | 30 | Let's look at the four possible cases when a symbol is encountered during 31 | assembly: 32 | 33 | LOCAL, DEFINED: this is the usual case. The value is used at assembly time. 34 | Multiple independent assemblies can define local symbols with the same names 35 | without conflicting with each other when they are linked. 36 | 37 | LOCAL, UNDEFINED: this shouldn't happen. You will get a complaint from the 38 | assembler. 39 | 40 | GLOBAL, DEFINED: during assembly, the symbol is treated just like a defined 41 | local symbol. However, the value is "published" in the object file for use by 42 | the linker. The symbol value can be made global either or both of two 43 | different ways: with an 'extern' declaration 44 | extern foo ; makes the symbol 'foo' global 45 | or, if the symbol is a label, by using two colons instead of one 46 | foo:: word 123 ; 'foo' is global 47 | bar: word 456 ; 'bar' is local 48 | If a global symbol is defined in more than one object file, the linker will 49 | complain. 50 | 51 | GLOBAL, UNDEFINED: this means that the assembler assumes that the value of the 52 | symbol will be defined at link time. You still have to tell the assembler 53 | that the symbol is global with an 'extern' statement. 54 | 55 | Note that all macro, function and variable (Macross variables, not 6502 56 | storage locations used as variables) names MUST be local, as must be struct 57 | names and struct fields. The assembler will complain if you try to declare 58 | one of these 'extern'. 59 | 60 | A 'define' symbol must be local if it refers to any global symbols in its 61 | definition. 62 | 63 | 3. The fewer global symbols there are, the faster the link will run. 64 | 65 | 4. When juggling a program that consists of multiple source and object files, 66 | only a very foolish person would not use 'make'. 67 | 68 | 5. Emacs has a very nice feature whereby you can run 'make' under emacs and 69 | then get taken automagically to the errors: 70 | 71 | The emacs function 'compile' (or 'new-compile' on some systems), which is 72 | usually bound to ^X^C (also to the shift-F5 key on my Concept terminal; I 73 | don't know about others), will run make and put the output from make (error 74 | messages and so on) in a buffer with a new window. 75 | 76 | After compiling with make, the emacs function 'next-error', which is usually 77 | bound to ^X^N (also to the the F5 key on my Concept) will search in the error 78 | message buffer for the first C-compiler-style error message (which is what 79 | Macross outputs), read the file name and line number from the error message 80 | and then (in another window) position the cursor at that line of that file. 81 | Entering this command again takes you to the next error message, and then the 82 | next, and so on. The wonderful thing about this is that if you edit your 83 | source file, emacs keeps track of how you have shifted things around so that 84 | it will always take you to the location of the next error, even if your 85 | editing has invalidated the line numbers in the error messages! 86 | -------------------------------------------------------------------------------- /doc/macross.1: -------------------------------------------------------------------------------- 1 | .TH MACROSS 1 "27 November 1985" 2 | .UC 4 3 | .SH NAME 4 | macross \- Macross assembler 5 | .SH SYNOPSIS 6 | .B macross 7 | [ option ] ... file ... 8 | .SH DESCRIPTION 9 | .I Macross 10 | is a fancy macro cross assembler for the 6502. 11 | .I Macross 12 | assembles the given files in the order specified on the command line. Macross 13 | source file names must end with ``\fB.m\fR''. 14 | .PP 15 | The following options are interpreted by 16 | .IR macross . 17 | .TP 18 | .BI \-l " listfile" 19 | Produce an assembler listing in the file 20 | .IR listfile 21 | showing the object code generated. If 22 | .IR listfile 23 | is ``\fB-\fR'' the listing will be printed on the standard output. 24 | .TP 25 | .B \-m 26 | When listing is enabled, causes the assembler to include in the listing 27 | synthesized lines showing the code generated by macros. 28 | .TP 29 | .B \-g 30 | Suppress assembly-time garbage collection of unused dynamic storage space 31 | (may speed up small assemblies). 32 | .TP 33 | .B \-d 34 | Print esoteric debug information showing parse trees generated by the parser. 35 | (Generally not of interest to the casual user). 36 | .TP 37 | .B \-D 38 | Print even more esoteric debug information showing parser states. (Almost 39 | certainly not of interest to the casual user). 40 | .TP 41 | .B \-e 42 | Print esoteric debug information showing emitted binary as it is generated. 43 | (Even duller than parser states). 44 | .TP 45 | .BI \-s " dumpfile" 46 | Place a symbol table dump in the file 47 | .IR dumpfile 48 | at the end of assembly. If 49 | .IR dumpfile 50 | is ``\fB-\fR'', the symbol table dump will go to the standard output. 51 | .TP 52 | .BI \-S " dumpfile" 53 | As \fB-s\fR, except also dump internal symbols normally not of interest. 54 | .TP 55 | .BI \-h " dumpfile" 56 | As \fB-s\fR, except that the symbols are dumped in the form of Macross 57 | \fBdefine\fR statements. 58 | .TP 59 | .BI \-H " dumpfile" 60 | As \fB-h\fR, except that it only dumps defined external symbols. 61 | .TP 62 | .B \-a 63 | If a symbol dump has been specified, have it include unreferenced \fBdefine\fR 64 | symbols (these are not normally displayed in a symbol table dump listing). 65 | .TP 66 | .BI \-o " output" 67 | Name the final output file 68 | .IR output . 69 | If this option is not used the output will be placed in the file `m.out'. 70 | .TP 71 | .BI \-P " processor" 72 | Assemble for the target processor 73 | .IR processor . 74 | The allowed values are \fB6502\fR and \fB68000\fR. If this option is not 75 | used \fB6502\fR will be assumed. 76 | .TP 77 | .B \-c 78 | Make the object file produced be a linkable object suitable for use with the 79 | \fIslinky\fR linker. 80 | .TP 81 | .B \-p 82 | Produce position independent code for the \fBelse\fP clause of 83 | \fBif-then-else\fP statements. This is accomplished by emitting a 84 | \fBbcc/bcs\fP branch pair instead of a \fBjmp\fP instruction. 85 | .TP 86 | .B \-t 87 | Be terse about error messages. Output no more than one error message for a 88 | given line. 89 | .TP 90 | .B \-u 91 | Don't discard the temporary intermediate files generated during the listing 92 | process when the assemble exits (used for debugging the listing facility). 93 | .TP 94 | .B \-v 95 | Print the \fImacross\fP version number on the standard output before beginning 96 | assembly. 97 | .TP 98 | .B \-B 99 | When generating branches for nested \fBif-then-else\fR constructs, generate 100 | code like that generated by \fBa65\fR. This code will be slightly less 101 | efficient but will be completely backwards compatible. 102 | .SH "SEE ALSO" 103 | slinky(1), the Macross manual 104 | .SH DIAGNOSTICS 105 | The diagnostics produced by Macross are \fIintended\fR to be self-explanatory. 106 | .SH BUGS 107 | Errors in the input may sometimes produce bizarre and unexpected results. 108 | There are probably lots of bugs that are as yet undetected. 109 | -------------------------------------------------------------------------------- /doc/slinky.1: -------------------------------------------------------------------------------- 1 | .TH SLINKY 1 "28 February 1986" 2 | .UC 4 3 | .SH NAME 4 | slinky \- slinky linker 5 | .SH SYNOPSIS 6 | .B slinky 7 | [ option ] ... file ... 8 | .SH DESCRIPTION 9 | .I Slinky 10 | is a multi-file relocating object linker designed to be used in conjunction 11 | with the 12 | .I Macross 13 | assembler. 14 | .I Slinky 15 | links the given 16 | .I Macross 17 | object files in the order specified on the command line together into one 18 | executable object file. 19 | .PP 20 | The following options are interpreted by 21 | .IR slinky . 22 | .TP 23 | .B \-d 24 | Print esoteric debug information (you don't want to use this). 25 | .TP 26 | .B \-e 27 | Print different esoteric debug information (you don't want to use this 28 | either). 29 | .TP 30 | .B \-v 31 | Print the \fIslinky\fP version number on the standard output before linking. 32 | .TP 33 | .BI \-l " hexaddress" 34 | By default, \fIslinky\fP starts putting relocatable modules at location 0x100. 35 | The \fB-l\fR option lets you tell it to put things anywhere. This option can 36 | be used more than once in a single link command and can be interspersed with 37 | the names of the object files being linked. Thus 38 | .br 39 | \fBslinky foo.obj -l 0x3800 bar.obj baz.obj -l 0x5000 snood.obj\fP 40 | .br 41 | loads `foo.obj' starting at location 0x100, `bar.obj' and `baz.obj' 42 | consecutively starting at location 0x3800 and `snood.obj' starting at location 43 | 0x5000. 44 | .TP 45 | .BI \-o " output" 46 | Name the final output file 47 | .IR output . 48 | If this option is not used the output will be placed in the file `s.out'. 49 | .TP 50 | .BI \-m " mapfile" 51 | Generate a load map listing, showing the values of all symbols after linking 52 | and put it in the file 53 | .IR mapfile . 54 | If 55 | .IR mapfile 56 | is ``\fB-\fR'', the load map will go to the standard output. 57 | .TP 58 | .B \-n 59 | If generating a load map, suppress the printing of the names of the files that 60 | reference each symbol. 61 | .SH "SEE ALSO" 62 | macross(1), the Macross manual 63 | .SH DIAGNOSTICS 64 | The diagnostics produced by Slinky are \fIintended\fR to be self-explanatory. 65 | .SH BUGS 66 | Who knows what bugs lurk there? Nobody's used it yet! 67 | -------------------------------------------------------------------------------- /doc/writeup_6502.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Museum-of-Art-and-Digital-Entertainment/macross/992179723541e5405c15bb8f7b3dd257e00328eb/doc/writeup_6502.pdf -------------------------------------------------------------------------------- /driver.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | driver.c -- Top level driver program for all versions of Macross 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 3-May-1985 28 | 29 | */ 30 | 31 | #include 32 | 33 | #define MACROSS_6502 "/u1/gg/bin/macross_6502" 34 | #define MACROSS_68000 "/u1/gg/bin/macross_68000" 35 | 36 | char *m6502 = "6502"; 37 | char *m68000 = "68000"; 38 | 39 | char **mlist; 40 | 41 | main(int argc, char **argv) 42 | { 43 | char *processor = m6502; 44 | int i; 45 | int j; 46 | 47 | mlist = (char **)calloc(argc + 1, sizeof (char **)); 48 | for (i=1, j=1; ikindOfValue != ABSOLUTE_VALUE) 169 | noteAnonymousReference(); 170 | emitWordValue(target); 171 | } 172 | } 173 | return(result); 174 | } 175 | 176 | -------------------------------------------------------------------------------- /emitBranch_68000.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | emitBranch_68000.c -- Routines to deal with code generation for 24 | branches and jumps in the Macross assembler (68000 25 | version). 26 | 27 | Chip Morningstar -- Lucasfilm Ltd. 28 | 29 | 29-April-1985 30 | 31 | */ 32 | 33 | #include "macrossTypes.h" 34 | #include "macrossGlobals.h" 35 | 36 | /* emitRelativeBranch emits a relative branch instruction for the 68000, 37 | branching from the current location given a condition to branch upon and a 38 | target address. */ 39 | 40 | void 41 | emitRelativeBranch(condition, target, fixupLocation) 42 | conditionType condition; 43 | valueType *target; 44 | valueType *fixupLocation; 45 | { 46 | int i; 47 | 48 | #define BCS_OPCODE 0x65 49 | #define BCC_OPCODE 0x64 50 | #define BEQ_OPCODE 0x67 51 | #define BGE_OPCODE 0x6C 52 | #define BGT_OPCODE 0x6E 53 | #define BHI_OPCODE 0x62 54 | #define BLE_OPCODE 0x6F 55 | #define BLS_OPCODE 0x63 56 | #define BLT_OPCODE 0x6D 57 | #define BMI_OPCODE 0x6B 58 | #define BNE_OPCODE 0x66 59 | #define BPL_OPCODE 0x6A 60 | #define BVC_OPCODE 0x68 61 | #define BVS_OPCODE 0x69 62 | #define BRA_OPCODE 0x60 63 | 64 | static byte conditionalBranchOpcodes[] = { 65 | /* CARRY_COND */ BCS_OPCODE, 66 | /* EQUAL_COND */ BEQ_OPCODE, 67 | /* OVERFLOW_COND */ BVS_OPCODE, 68 | /* MINUS_COND */ BMI_OPCODE, 69 | /* LT_COND */ BLT_OPCODE, 70 | /* LEQ_COND */ BLE_OPCODE, 71 | /* LOW_OR_SAME */ BLS_OPCODE, 72 | /* ALWAYS_COND */ BRA_OPCODE, 73 | /* NOT_CARRY_COND */ BCC_OPCODE, 74 | /* NOT_EQUAL_COND */ BNE_OPCODE, 75 | /* NOT_OVERFLOW_COND */ BVC_OPCODE, 76 | /* PLUS_COND */ BPL_OPCODE, 77 | /* GEQ_COND */ BGE_OPCODE, 78 | /* GT_COND */ BGT_OPCODE, 79 | /* HIGH_COND */ BHI_OPCODE, 80 | /* NEVER_COND */ 0, 81 | }; 82 | 83 | if (fixupLocation != NULL) 84 | fixupLocation->value = -1; 85 | if (condition == NEVER_COND) 86 | return; 87 | emitByte(conditionalBranchOpcodes[(int)condition]); 88 | if (isByteOffset(target - (currentLocationCounter.value + 1))) { 89 | if (fixupLocation != NULL) 90 | *fixupLocation = currentLocationCounter; 91 | emitRelativeByteOffset(target); 92 | } else { 93 | emitByte(0); 94 | if (fixupLocation != NULL) 95 | *fixupLocation = currentLocationCounter; 96 | emitRelativeWordOffset(target); 97 | } 98 | } 99 | 100 | 101 | /* emitJump emits a 68000 jump instruction given the target address */ 102 | 103 | simpleFixupListType * 104 | emitJump(target, previousFixups) 105 | valueType *target; 106 | simpleFixupListType *previousFixups; 107 | { 108 | simpleFixupListType *result; 109 | 110 | simpleFixupListType *buildSimpleFixupList(); 111 | 112 | #define JUMP_OPCODE_WORD 0x4EF8 113 | #define JUMP_OPCODE_LONG 0x4EF9 114 | #define JUMP_OPCODE_PC_REL 0x4EFA 115 | 116 | result = previousFixups; 117 | if (target == NULL) { 118 | emitWord(JUMP_OPCODE_LONG); 119 | result = buildSimpleFixupList(currentLocationCounter, result); 120 | emitWord(0); 121 | } else if (target->kindOfValue != ABSOLUTE_VALUE) { 122 | emitWord(JUMP_OPCODE_LONG); 123 | noteAnonymousReference(); 124 | emitLongValue(target); 125 | } else if (isWordOffset(target->value-currentLocationCounter.value)) { 126 | emitWord(JUMP_OPCODE_PC_REL); 127 | emitWord(target->value - currentLocationCounter.value); 128 | } else if (isWord(target)) { 129 | emitWord(JUMP_OPCODE_WORD); 130 | emitWord(target); 131 | } else { 132 | emitWord(JUMP_OPCODE_LONG); 133 | emitLong(target); 134 | } 135 | return(result); 136 | } 137 | 138 | -------------------------------------------------------------------------------- /emitStuff.h: -------------------------------------------------------------------------------- 1 | #ifndef EMIT_STUFF_H_ 2 | #define EMIT_STUFF_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | void incarnateCodeBuffer(int bufferNum, codeBufferKindType bufferKind); 7 | void putByte(addressType address, byte byteValue); 8 | void mapByte(int address, byte byteValue); 9 | void emitByte(byte byteValue); 10 | void emitWord(wordType wordValue); 11 | void emitLong(longType longValue); 12 | void emitByteValue(valueType *byteValue); 13 | void emitString(stringType *string); 14 | void emitWordValue(valueType *wordValue); 15 | void emitLongValue(valueType *longValue); 16 | void pokeByteValue(addressType location, valueType *value); 17 | void pokeWordValue(addressType location, valueType *value); 18 | void pokeLongValue(addressType location, valueType *value); 19 | void pokeRelativeByteValue(addressType location, valueType *value); 20 | void pokeRelativeWordValue(addressType location, valueType *value); 21 | byte getByte(addressType address); 22 | void emitRelativeByteOffset(valueType *target); 23 | void emitRelativeWordOffset(valueType *target); 24 | void fixupBranch(valueType *location, valueType target); 25 | void fixupJump(simpleFixupListType *locations, valueType target); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /encode.h: -------------------------------------------------------------------------------- 1 | #ifndef ENCODE_H_ 2 | #define ENCODE_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | bool encodeByte(byte aByte); 7 | bool encodeBigword(int bigword); 8 | bool encodeAssignmentTerm(binopTermType *assignmentTerm); 9 | bool encodeBinopTerm(binopTermType *binopTerm); 10 | bool encodeCondition(conditionType condition); 11 | int functionNumber(functionDefinitionType *function); 12 | bool encodeFunctionCall(functionCallTermType *functionCall); 13 | bool encodeHere(void); 14 | bool encodeIdentifier(symbolTableEntryType *identifier); 15 | bool encodeNumber(numberTermType number); 16 | bool encodeRelocatableNumber(numberTermType number); 17 | bool encodeOperand(operandType *operand); 18 | bool encodePostopTerm(postOpTermType *postopTerm); 19 | bool encodePreopTerm(preOpTermType *preopTerm); 20 | bool encodeString(stringType *string); 21 | bool encodeUnopTerm(unopTermType *unopTerm); 22 | bool encodeValue(valueType *value); 23 | bool encodeExpression(expressionType *expression); 24 | bool encodeAssertStatement(assertStatementBodyType *assertStatement); 25 | bool encodeFreturnStatement(freturnStatementBodyType *freturnStatement); 26 | bool encodeMdefineStatement(defineStatementBodyType *mdefineStatement); 27 | bool encodeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement); 28 | bool encodeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement); 29 | bool encodeMforStatement(mforStatementBodyType *mforStatement); 30 | bool encodeMifStatement(mifStatementBodyType *mifStatement); 31 | bool encodeMswitchStatement(mswitchStatementBodyType *mswitchStatement); 32 | bool encodeMvariableStatement(mvariableStatementBodyType *mvariableStatement); 33 | bool encodeMwhileStatement(mwhileStatementBodyType *mwhileStatement); 34 | bool encodeStatement(statementType *statement); 35 | bool encodeBlock(blockType *block); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /errorStuff.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_STUFF_H_ 2 | #define ERROR_STUFF_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | #include 7 | 8 | void puntOnError(errorType theError, ...); 9 | void printErrorMessage(errorType theError, va_list ap); 10 | void error(errorType theError, ...); 11 | void verror(errorType theError, va_list ap); 12 | void warning(errorType theError, ...); 13 | void fatalError(errorType theError, ...); 14 | void fatalSystemError(errorType theError, ...); 15 | void yyerror(char *s); 16 | char *usageString(symbolUsageKindType usageKind); 17 | char *valueKindString(valueKindType valueKind); 18 | char *assignmentString(assignmentKindType assignment); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /errorfyle: -------------------------------------------------------------------------------- 1 | make: Warning: Infinite loop: Target `macrossTypes.h' depends on itself 2 | cc -c -g -DYYDEBUG -DTARGET_CPU=CPU_6502 y.tab.c 3 | cc -c -g -DTARGET_CPU=CPU_6502 actions_6502.c 4 | mv actions_6502.o actions.o 5 | cc -c -g -DTARGET_CPU=CPU_6502 buildStuff1.c 6 | cc -c -g -DTARGET_CPU=CPU_6502 buildStuff2.c 7 | cc -c -g -DTARGET_CPU=CPU_6502 buildStuff3.c 8 | cc -c -g -DTARGET_CPU=CPU_6502 builtInFunctions.c 9 | cc -c -g -DTARGET_CPU=CPU_6502 builtInFunsSD_6502.c 10 | mv builtInFunsSD_6502.o builtInFunsSD.o 11 | cc -c -g -DTARGET_CPU=CPU_6502 debugPrint.c 12 | cc -c -g -DTARGET_CPU=CPU_6502 debugPrintSD_6502.c 13 | mv debugPrintSD_6502.o debugPrintSD.o 14 | cc -c -g -DTARGET_CPU=CPU_6502 emitBranch_6502.c 15 | mv emitBranch_6502.o emitBranch.o 16 | cc -c -g -DBYTESWAPPED -DTARGET_CPU=CPU_6502 emitStuff.c 17 | cc -c -g -DTARGET_CPU=CPU_6502 encode.c 18 | cc -c -g -DTARGET_CPU=CPU_6502 errorStuff.c 19 | cc -c -g -DTARGET_CPU=CPU_6502 expressionSemantics.c 20 | cc -c -g -DTARGET_CPU=CPU_6502 fixups.c 21 | cc -c -g -DTARGET_CPU=CPU_6502 garbage.c 22 | cc -c -g -DTARGET_CPU=CPU_6502 initialize.c 23 | cc -c -g -DTARGET_CPU=CPU_6502 lexer.c 24 | cc -c -g -DTARGET_CPU=CPU_6502 listing.c 25 | cc -c -g -DTARGET_CPU=CPU_6502 lookups.c 26 | cc -c -g -DTARGET_CPU=CPU_6502 macrossTables_6502.c 27 | mv macrossTables_6502.o macrossTables.o 28 | cc -c -g -DTARGET_CPU=CPU_6502 main.c 29 | cc -c -g -DTARGET_CPU=CPU_6502 malloc.c 30 | cc -c -g -DTARGET_CPU=CPU_6502 object.c 31 | cc -c -g -DTARGET_CPU=CPU_6502 operandStuffSD_6502.c 32 | mv operandStuffSD_6502.o operandStuffSD.o 33 | cc -c -g -DTARGET_CPU=CPU_6502 parserMisc.c 34 | cc -c -g -DTARGET_CPU=CPU_6502 semanticMisc.c 35 | cc -c -g -DTARGET_CPU=CPU_6502 statementSemantics.c 36 | cc -c -g -DTARGET_CPU=CPU_6502 structSemantics.c 37 | cc -c -g -DTARGET_CPU=CPU_6502 tokenStrings_6502.c 38 | mv tokenStrings_6502.o tokenStrings.o 39 | cc -g -o macross y.tab.o actions.o buildStuff1.o buildStuff2.o buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o emitBranch.o emitStuff.o encode.o errorStuff.o expressionSemantics.o fixups.o garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.o statementSemantics.o structSemantics.o tokenStrings.o 40 | -------------------------------------------------------------------------------- /expressionSemantics.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPRESSION_SEMANTICS_H_ 2 | #define EXPRESSION_SEMANTICS_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | anyOldThing *arrayLookup(arrayTermType *arrayTerm, valueKindType *kindOfThing); 7 | valueType *evaluateArrayTerm(arrayTermType *arrayTerm); 8 | valueType *evaluateAssignmentTerm(binopTermType *assignmentTerm, fixupKindType kindOfFixup); 9 | valueType *evaluateBinopTerm(binopTermType *binopTerm, bool isTopLevel, fixupKindType kindOfFixup); 10 | valueType *evaluateCondition(conditionType condition); 11 | valueType *evaluateBuiltInFunctionCall(symbolInContextType *workingContext, operandListType *parameters, fixupKindType kindOfFixup); 12 | valueType *evaluateFunctionCall(functionCallTermType *functionCall, fixupKindType kindOfFixup, bool isStandalone); 13 | valueType *evaluateHere(void); 14 | valueType *evaluateIdentifier(symbolTableEntryType *identifier, bool isTopLevel, fixupKindType kindOfFixup); 15 | valueType *evaluateNumber(numberTermType number); 16 | valueType *evaluatePostopTerm(postOpTermType *postopTerm); 17 | valueType *evaluatePreopTerm(preOpTermType *preopTerm); 18 | valueType *evaluateString(stringType *string); 19 | valueType *evaluateUnopTerm(unopTermType *unopTerm, fixupKindType kindOfFixup); 20 | valueType *evaluateExpressionInternally(expressionType *expression, bool isTopLevel, fixupKindType kindOfFixup, bool isStandalone); 21 | valueType *evaluateExpression(expressionType *expression, fixupKindType kindOfFixup); 22 | void evaluateExpressionStandalone(expressionType *expression); 23 | valueType *evaluateDefineExpression(expressionType *expression); 24 | valueType *evaluateSelectionList(selectionListType *selectionList); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /fixups.h: -------------------------------------------------------------------------------- 1 | #ifndef FIXUPS_H_ 2 | #define FIXUPS_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | expressionType *generateFixupExpression(expressionType *expression); 7 | expressionType *duplicateExpressionForFixup(expressionType *expression, bool isTopLevel, bool isSpecialFunctionOperand); 8 | functionCallTermType *duplicateFunctionCall(functionCallTermType *functionCall); 9 | expressionType *duplicateArrayReference(arrayTermType *arrayTerm); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /garbage.h: -------------------------------------------------------------------------------- 1 | #ifndef GARBAGE_H_ 2 | #define GARBAGE_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | void freeArrayTerm(arrayTermType *arrayTerm); 7 | void freeAssignmentTerm(binopTermType *assignmentTerm); 8 | void freeBinopTerm(binopTermType *binopTerm); 9 | void freeFunctionCall(functionCallTermType *functionCall); 10 | void freePostopTerm(postOpTermType *postopTerm); 11 | void freePreopTerm(preOpTermType *preopTerm); 12 | void freeString(stringType *string); 13 | void freeUnopTerm(unopTermType *unopTerm); 14 | void freeExpression(expressionType *expression); 15 | void freeExpressionList(expressionListType *expressionList); 16 | void freeIdentifierList(identifierListType *identifierList); 17 | void freeSelectionList(selectionListType *selectionList); 18 | void freeBlock(blockType *block); 19 | void freeCase(caseType *aCase); 20 | void freeCaseList(caseListType *caseList); 21 | void freeOperandList(operandListType *operandList); 22 | void freeMacro(operandListType *operands); 23 | void freeMachineInstruction(operandListType *operands); 24 | void freeAlignStatement(alignStatementBodyType *alignStatement); 25 | void freeAssertStatement(assertStatementBodyType *assertStatement); 26 | void freeBlockStatement(blockStatementBodyType *blockStatement); 27 | void freeByteStatement(byteStatementBodyType *byteStatement); 28 | void freeConstrainStatement(constrainStatementBodyType *constrainStatement); 29 | void freeDbyteStatement(dbyteStatementBodyType *dbyteStatement); 30 | void freeDefineStatement(defineStatementBodyType *defineStatement); 31 | void freeDoUntilStatement(doUntilStatementBodyType *doUntilStatement); 32 | void freeDoWhileStatement(doWhileStatementBodyType *doWhileStatement); 33 | void freeExternStatement(externStatementBodyType *externStatement); 34 | void freeFreturnStatement(freturnStatementBodyType *freturnStatement); 35 | void freeFunctionStatement(functionStatementBodyType *functionStatement); 36 | void freeIfStatement(ifStatementBodyType *ifStatement); 37 | void freeIncludeStatement(includeStatementBodyType *includeStatement); 38 | void freeInstructionStatement(instructionStatementBodyType *instructionStatement); 39 | void freeLongStatement(longStatementBodyType *longStatement); 40 | void freeMacroStatement(macroStatementBodyType *macroStatement); 41 | void freeMdefineStatement(defineStatementBodyType *mdefineStatement); 42 | void freeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement); 43 | void freeMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement); 44 | void freeMifStatement(mifStatementBodyType *mifStatement); 45 | void freeMswitchStatement(mswitchStatementBodyType *mswitchStatement); 46 | void freeMforStatement(mforStatementBodyType *mforStatement); 47 | void freeMvariableStatement(mvariableStatementBodyType *mvariableStatement); 48 | void freeMwhileStatement(mwhileStatementBodyType *mwhileStatement); 49 | void freeOrgStatement(orgStatementBodyType *orgStatement); 50 | void freePerformStatement(performStatementBodyType *performStatement); 51 | void freeRelStatement(relStatementBodyType *relStatement); 52 | void freeStartStatement(startStatementBodyType *startStatement); 53 | void freeStringStatement(stringStatementBodyType *stringStatement); 54 | void freeStructStatement(structStatementBodyType *structStatement); 55 | void freeTargetStatement(targetStatementBodyType *targetStatement); 56 | void freeUndefineStatement(undefineStatementBodyType *undefineStatement); 57 | void freeVariableStatement(variableStatementBodyType *variableStatement); 58 | void freeWhileStatement(whileStatementBodyType *whileStatement); 59 | void freeWordStatement(wordStatementBodyType *wordStatement); 60 | void freeStatementBody(statementKindType kind, statementBodyType body); 61 | void freeLabelList(labelListType *labelList); 62 | void freeStatement(statementType *statement); 63 | void freeArray(arrayType *array); 64 | void freeValue(valueType *value); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /globals.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | macrossGlobals.h -- Global variable definitions for the Macross 24 | assembler. 25 | 26 | Chip Morningstar -- Lucasfilm Ltd. 27 | 28 | 1-November-1984 29 | 30 | */ 31 | 32 | #include "macrossTypes.h" 33 | #include "macrossGlobals.h" 34 | 35 | bool backwardsCompatibleIfFlag; 36 | bool beneathFunction; 37 | commandLineDefineType *commandLineDefines; 38 | int cumulativeLineNumber; 39 | environmentType *currentEnvironment; 40 | int currentFieldOffset; 41 | char *currentFileName; 42 | char *lastErrorFile; 43 | stringType *currentFunctionName; 44 | int currentLabelTagNumber; 45 | int currentLineNumber; 46 | int lastErrorLine; 47 | identifierListType *currentLocalVariableList; 48 | valueType currentLocationCounter; 49 | int currentOperandNumber; 50 | int currentReferenceDepth; 51 | bool debug; 52 | bool emitPrint; 53 | bool expandMacros; 54 | bool errorFlag; 55 | bool expressionFailed; 56 | bool finishOperand; 57 | operandKindType fixupAddressMode[MAX_NUMBER_OF_OPERANDS]; 58 | operandKindType newFixupAddressMode; 59 | fixupListType *fixupList; 60 | bool freeFlag; 61 | bool freturnExit; 62 | bool generatingFixup; 63 | environmentType globalEnvironment; 64 | int hackFlag; 65 | bool haveUserStartAddress; 66 | bool fixupStartAddress; 67 | int includeNestingDepth; 68 | FILE *indexFileForPass2; 69 | FILE *input; 70 | fileNameListType *inputFileStack; 71 | FILE *listFileOutput; 72 | int listingControlCounter; 73 | bool listingOn; 74 | int macroCallDepth; 75 | FILE *macroFileForPass2; 76 | int macroOrFunctionNestingDepth; 77 | structInstanceType *newStruct; 78 | int nextEnvironmentNumber; 79 | int nextLabelTagNumber; 80 | FILE *objectFileOutput; 81 | char operandBuffer[MAX_NUMBER_OF_OPERANDS][LINE_BUFFER_SIZE]; 82 | expressionType *pendingFixup[MAX_NUMBER_OF_OPERANDS]; 83 | bool performingFixups; 84 | bool positionIndependentCodeMode; 85 | bool produceLinkableObject; 86 | addressType relocatableHighWaterMark; 87 | reservationListType *reservationList; 88 | valueType *resultOfLastFunctionCall; 89 | valueType savedRelocatableCurrentLocationCounter; 90 | FILE *saveFileForPass2; 91 | bool showAllSymbolsFlag; 92 | bool sideEffectFlag; 93 | bool standaloneExpansionFlag; 94 | valueType *startAddress; 95 | int statementEvaluationDepth; 96 | int statementListNestingDepth; 97 | int structNestingDepth; 98 | FILE *symbolDumpFileOutput; 99 | bool symbolTableDumpOn; 100 | int tabCount; 101 | addressType targetOffset; 102 | bool terseErrorMessages; 103 | valueType *UndefinedValue; 104 | symbolUsageKindType unknownSymbolTag; 105 | 106 | int (*lexDispatchTable[128])(); 107 | 108 | macroTableEntryType *macroTable[HASH_TABLE_SIZE]; 109 | 110 | opcodeTableEntryType *opcodeTable[HASH_TABLE_SIZE]; 111 | 112 | keywordTableEntryType *keywordTable[HASH_TABLE_SIZE]; 113 | 114 | conditionTableEntryType *conditionTable[HASH_TABLE_SIZE]; 115 | 116 | symbolTableEntryType *symbolTable[HASH_TABLE_SIZE]; 117 | 118 | int validSymbolValues[NUM_OF_SYM_USAGES]; 119 | 120 | byte structScratchBuffer[MAXIMUM_ALLOWED_STRUCT_SIZE]; 121 | 122 | codeRegionType absoluteCodeRegion; 123 | codeRegionType relocatableCodeRegion; 124 | codeRegionType *codeRegions[2]; 125 | codeBufferKindType currentCodeMode; 126 | codeBufferType *emptyBuffer; /* ??? */ 127 | codeBreakType *codeBreakList; 128 | codeBreakType *lastCodeBreak; 129 | 130 | expressionReferenceListType *expressionReferenceList[3]; 131 | expressionReferenceListType *referencesToNote[MAX_NUMBER_OF_OPERANDS]; 132 | int numberOfReferencesInList[3]; 133 | functionDefinitionType *externalFunctionList; 134 | functionDefinitionType *endOfExternalFunctionList; 135 | int externalFunctionCount; 136 | 137 | char alphabeticCharacterTable[128]; 138 | char alphaNumericCharacterTable[128]; 139 | char lowerCaseCharacterTable[128]; 140 | char numericCharacterTable[128]; 141 | 142 | int expressionBufferSize; 143 | byte expressionBuffer[EXPRESSION_BUFFER_LIMIT]; 144 | -------------------------------------------------------------------------------- /initialize.h: -------------------------------------------------------------------------------- 1 | #ifndef INITIALIZE_H_ 2 | #define INITIALIZE_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | void chokePukeAndDie(void); 7 | void initializeStuff(int argc, char **argv); 8 | void installBuiltInFunctions(void); 9 | void installPredefinedSymbols(void); 10 | void installCommandLineDefineSymbols(void); 11 | void createHashTables(void); 12 | void queueInputFile(char *name); 13 | void openFirstInputFile(void); 14 | bool isDotMName(stringType *fileName); 15 | bool parseCommandLineDefine(char *arg, char **name, int *value); 16 | void noteCommandLineDefine(char *arg); 17 | 18 | /* Actually defined in main.c */ 19 | void printVersion(void); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /lexer.h: -------------------------------------------------------------------------------- 1 | #ifndef LEXER_H_ 2 | #define LEXER_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | int yylex(void); 7 | int lexer(void); 8 | void initializeLexDispatchTable(void); 9 | bool isMacrossLiteralCharacter(char c); 10 | void snarfAlphanumericString(char c, char *buffer); 11 | int lexIdentifier(char c); 12 | int lexNumber(char c); 13 | int fancyAtoI(char *buffer, int base); 14 | int digitValue(char c); 15 | int lexLiteral(char c); 16 | int lexCharacterConstant(void); 17 | int getStringCharacter(FILE *input); 18 | int lexStringConstant(void); 19 | int lexOperator(char firstC); 20 | char controlCharacter(char c); 21 | char skipWhitespaceAndComments(void); 22 | int popInputFileStack(void); 23 | void pushInputFileStack(stringType *fileName); 24 | void resynchronizeInput(void); 25 | void saveLineForListing(stringType *line); 26 | void saveEOLForListing(void); 27 | void saveIndexForListing(statementKindType kindOfStatement, int cumulativeLineNumber); 28 | void saveEndMifForListing(int cumulativeLineNumber); 29 | void saveListingOff(void); 30 | void saveListingOn(void); 31 | char *myfgets(char *buffer, int length, FILE *stream); 32 | int readAnotherLine(void); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lexerTables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | lexerTables.h -- Tables describing stuff the lexer needs to know. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 3-November-1984 28 | */ 29 | 30 | struct { 31 | char first; 32 | char second; 33 | int token; 34 | assignmentKindType value; 35 | } operatorTable[] = { 36 | '!', '=', NOT_EQUAL_TO, NO_ASSIGN, 37 | '!', '\0', LOGICAL_NOT, NO_ASSIGN, 38 | '%', '=', ASSIGN, MOD_ASSIGN, 39 | '%', '\0', MOD, NO_ASSIGN, 40 | '&', '&', LOGICAL_AND, NO_ASSIGN, 41 | '&', '=', ASSIGN, AND_ASSIGN, 42 | '&', '\0', BITWISE_AND, NO_ASSIGN, 43 | '*', '=', ASSIGN, MUL_ASSIGN, 44 | '*', '\0', MUL, NO_ASSIGN, 45 | '+', '+', INCREMENT, NO_ASSIGN, 46 | '+', '=', ASSIGN, ADD_ASSIGN, 47 | '+', '\0', ADD, NO_ASSIGN, 48 | '-', '-', DECREMENT, NO_ASSIGN, 49 | '-', '=', ASSIGN, SUB_ASSIGN, 50 | '-', '\0', SUB, NO_ASSIGN, 51 | '.', '\0', SELECT, NO_ASSIGN, 52 | '/', '=', ASSIGN, DIV_ASSIGN, 53 | '/', '\0', DIV, NO_ASSIGN, 54 | '<', '<', LEFT_SHIFT, NO_ASSIGN, 55 | '<', '=', LESS_THAN_OR_EQUAL_TO, NO_ASSIGN, 56 | '<', '\0', LESS_THAN, NO_ASSIGN, 57 | '=', '=', EQUAL_TO, NO_ASSIGN, 58 | '=', '\0', ASSIGN, ASSIGN_ASSIGN, 59 | '>', '=', GREATER_THAN_OR_EQUAL_TO, NO_ASSIGN, 60 | '>', '>', RIGHT_SHIFT, NO_ASSIGN, 61 | '>', '\0', GREATER_THAN, NO_ASSIGN, 62 | '^', '=', ASSIGN, XOR_ASSIGN, 63 | '^', '^', LOGICAL_XOR, NO_ASSIGN, 64 | '^', '\0', BITWISE_XOR, NO_ASSIGN, 65 | '|', '=', ASSIGN, OR_ASSIGN, 66 | '|', '|', LOGICAL_OR, NO_ASSIGN, 67 | '|', '\0', BITWISE_OR, NO_ASSIGN, 68 | '~', '\0', BITWISE_NOT, NO_ASSIGN, 69 | '?', '\0', HI_BYTE, NO_ASSIGN, 70 | '\0', '\0', 0, NO_ASSIGN, 71 | }; 72 | 73 | char escapeCodes[256] = { 74 | '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', 75 | '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', 76 | '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', 77 | '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', 78 | ' ', '!', '"', '#', '$', '%', '&', '\'', 79 | '(', ')', '*', '+', ',', '-', '.', '/', 80 | '0', '1', '2', '3', '4', '5', '6', '7', 81 | '8', '9', ':', ';', '<', '=', '>', '?', 82 | '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 83 | 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 84 | 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 85 | 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', 86 | '`', 'a', '\b', 'c', 'd', '\33', '\f', 'g', 87 | 'h', 'i', 'j', 'k', 'l', 'm', '\n', 'o', 88 | 'p', 'q', '\r', 's', '\t', 'u', 'v', 'w', 89 | 'x', 'y', 'z', '{', '|', '}', '~', '\177', 90 | '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', 91 | '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', 92 | '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', 93 | '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', 94 | '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', 95 | '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', 96 | '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', 97 | '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', 98 | '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307', 99 | '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317', 100 | '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327', 101 | '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337', 102 | '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', 103 | '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', 104 | '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', 105 | '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', 106 | }; 107 | -------------------------------------------------------------------------------- /listing.h: -------------------------------------------------------------------------------- 1 | #ifndef LISTING_H_ 2 | #define LISTING_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | #include 7 | 8 | void outputListing(void); 9 | void terminateListingFiles(void); 10 | void generateListing(void); 11 | int printMacroLine(int numberOfBytes, int byteAddress, statementKindType kind); 12 | void readSourceFileLine(int *sourceAddressPtr, int *sourceDepthPtr, char *lineBuffer, FILE *file); 13 | void readIndexFileLine(statementKindType *statementKindPtr, int *indexAddressPtr, int *indexLineNumberPtr); 14 | int printListingLine(int numberOfBytes, int byteAddress, char *text, statementKindType kind); 15 | bool isBlockOpener(statementKindType statementKind); 16 | bool isBlankStatement(statementKindType statementKind); 17 | void tabPrint(stringType *text); 18 | void printNTimes(char aChar, int times); 19 | void tabIndent(void); 20 | bool labeledLine(void); 21 | void vaddText(char *buffer, char **bufferPtr, char *format, va_list ap); 22 | void addText(char *buffer, char **bufferPtr, char *format, ...); 23 | void moreTextOptional(char *buffer, char **bufferPtr, char *format, ...); 24 | void moreText(char *format, ...); 25 | void moreLabel(char *format, int arg1); 26 | void startLine(void); 27 | void endLine(void); 28 | void flushExpressionString(void); 29 | void expandExpression(char *toBuffer, char **toBufferPtr); 30 | void expandNum(char *buffer, char **bufferPtr, int n); 31 | void flushOperand(int n); 32 | void expandOperands(int op); 33 | void expandLabel(void); 34 | void moreExpression(char *format, ...); 35 | void startLineMarked(void); 36 | bool notListable(statementKindType statementKind); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lookups.h: -------------------------------------------------------------------------------- 1 | #ifndef LOOKUPS_H_ 2 | #define LOOKUPS_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | conditionType lookupConditionCode(char *s, int hashValue); 7 | int lookupKeyword(char *s, int hashValue); 8 | macroTableEntryType *lookupMacroName(char *s, int hashValue); 9 | opcodeTableEntryType *lookupOpcode(char *s, int hashValue); 10 | symbolTableEntryType *lookupOrEnterSymbol(stringType *s, symbolUsageKindType kind); 11 | void pushSymbol(symbolTableEntryType *symbol); 12 | void popSymbol(symbolTableEntryType *symbol); 13 | macroTableEntryType *createMacro(stringType *macroName); 14 | genericTableEntryType *prehashedStringLookup(char *s, genericTableEntryType **table, int hashValue); 15 | genericTableEntryType *hashStringLookup(char *s, genericTableEntryType **table); 16 | genericTableEntryType *hashStringEnter(genericTableEntryType *entry, genericTableEntryType **table); 17 | int hashString(char *s); 18 | bool strcmplc(char *s1, char *s2); 19 | bool strcmplct(char *s1, char *s2); 20 | void purgeSymbol(symbolTableEntryType *symbol); 21 | void reincarnateSymbol(symbolInContextType *context, symbolUsageKindType newUsage); 22 | void pushBinding(symbolTableEntryType *symbol, valueType *newBinding, symbolUsageKindType newUsage); 23 | void popBinding(symbolTableEntryType *symbol); 24 | int bindMacroArguments(argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *macroName); 25 | int bindFunctionArguments(argumentDefinitionListType *argumentList, operandListType *parameterList, stringType *functionName); 26 | void unbindArguments(argumentDefinitionListType *argumentList, int numberToUnbind); 27 | void unbindLocalVariables(identifierListType *identifierList); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | main.c -- Top level of the Macross assembler. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 5-December-1984 28 | */ 29 | 30 | #include "macrossTypes.h" 31 | #include "macrossGlobals.h" 32 | #include "initialize.h" 33 | #include "semanticMisc.h" 34 | #include "y.tab.h" 35 | 36 | #include 37 | 38 | int 39 | main(int argc, char **argv) 40 | { 41 | #ifdef __APPLE__ 42 | char end = get_end(); 43 | #else 44 | extern char end; 45 | #endif 46 | 47 | fflush(stdout); 48 | initializeStuff(argc, argv); 49 | yyparse(); 50 | finishUp(); 51 | /* sbrk() ends up having different signatures depending on compiler 52 | * flags and system. We cast here out of an abundance of caution. 53 | * This, and the "end" variable above, are both just for this one 54 | * diagnostic, so if they're causing your build trouble, they can 55 | * be safely deleted. --mcm */ 56 | if (emitPrint) 57 | printf("storage high water mark 0x%x == %d\n", (void *)sbrk(0) - (void *)(&end), 58 | (void *)sbrk(0) - (void *)(&end)); 59 | if (errorFlag) 60 | chokePukeAndDie(); 61 | return 0; 62 | } 63 | 64 | void 65 | printVersion(void) 66 | { 67 | printf("Macross %s version 4.20.\n", TARGET_CPU_STRING); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /notes68/1.am: -------------------------------------------------------------------------------- 1 | Address Modes 2 | ------------- 3 | Notation 4 | Number Motorola Name Motorola Sun Sun Name 5 | ------ ------------- -------- --- -------- 6 | 1 Data Register Direct Dn Dn Register 7 | 8 | 2 Address Register Direct An An Register 9 | 10 | 3 Address Register Indirect (An) An@ Register 11 | Deferred 12 | 13 | 4 Address Register Indirect w/ (An)+ An@+ Postincrement 14 | Postincrement 15 | 16 | 5 Address Register Indirect w/ -(An) An@- Predecrement 17 | Predecrement 18 | 19 | 6 Address Register Indirect w/ d(An) An@(d) Displacement 20 | Displacement 21 | 22 | 7 Address Register Indirect w/ d(An,Rx.W) An@(d,Rx:W) Word Index 23 | Index d(An,Rx.L) An@(d,Rx:L) Long Index 24 | 25 | 8 Program Counter w/ Displacement d(PC) PC@(d) PC Displacement 26 | 27 | 9 Program Counter w/ Index d(PC,Rx.W) PC@(d,Rx:W) PC Word 28 | Index 29 | d(PC,Rx.L) PC@(d,Rx:L) PC Long 30 | Index 31 | 32 | 10 Immediate #xxx #xxx Immediate 33 | 34 | 11 Absolute Short xxx.W xxx:W Absolute Short 35 | 36 | 12 Absolute Long xxx.L xxx:L Absolute Long 37 | 38 | 13 -- -- xxx Normal 39 | 40 | 14 (condition code register) CCR CC -- 41 | 42 | 15 (status register) SR SR -- 43 | 44 | 16 Implied 45 | 46 | 17 (user stack pointer) USP USP -- 47 | 48 | 18 (control register) SFC SFC -- 49 | DFC DFC 50 | VBR VBR 51 | 52 | -------------------------------------------------------------------------------- /notes68/2.amg: -------------------------------------------------------------------------------- 1 | Address Mode Groups 2 | ------------------- 3 | ID Mode set Mnemonic 4 | -- -------- -------- 5 | A 1 DATA_REGISTER 6 | 7 | B 2 ADDRESS_REGISTER 8 | 9 | C 4 POSTINCREMENT 10 | 11 | D 5 PREDECREMENT 12 | 13 | E 6 DISPLACEMENT 14 | 15 | F 10 IMMEDIATE 16 | 17 | G 13 NORMAL 18 | 19 | H 14 CONDITION_CODE_REGISTER 20 | 21 | I 15 STATUS_REGISTER 22 | 23 | J 16 (no operand at all!) 24 | 25 | K 17 USER_STACK_POINTER 26 | 27 | L { 17-18 } CONTROL_REGISTER 28 | 29 | M { 1-2 } REGISTER 30 | 31 | N { 1-7, 11-13 } STORABLE 32 | 33 | O { 1-13 } FULL_EA 34 | 35 | P { 1, 3-7, 11-13 } STORABLE_NO_A_REGISTER 36 | 37 | Q { 1, 3-13 } FULL_EA_NO_A_REG 38 | 39 | R { 3-4, 6-9, 11-13 } MISC_1 40 | 41 | S { 3-7, 11-13 } STORABLE_NO_REGISTER 42 | 43 | T { 3, 5-7, 11-13 } MISC_2 44 | 45 | U { 3, 6-9, 11-13 } MISC_3 46 | -------------------------------------------------------------------------------- /notes68/3.os: -------------------------------------------------------------------------------- 1 | Operand Sets 2 | ------------ 3 | 1 A 4 | 2 AA 5 | 3 AE 6 | 4 AG 7 | 5 AP 8 | 6 AS 9 | 10 | 7 B 11 | 8 BF 12 | 9 BK 13 | 14 | 10 CC 15 | 16 | 11 DD 17 | 18 | 12 EA 19 | 20 | 13 F 21 | 14 FA 22 | 15 FH 23 | 16 FI 24 | 17 FN 25 | 18 FP 26 | 27 | 19 G 28 | 29 | 20 HP 30 | 31 | 21 IP 32 | 33 | 22 J 34 | 35 | 23 KB 36 | 37 | 24 LM 38 | 39 | 25 ML 40 | 26 MM 41 | 27 MP 42 | 28 MS 43 | 29 M*T 44 | 45 | 30 OA 46 | 31 OB 47 | 48 | 32 P 49 | 50 | 33 QA 51 | 34 QH 52 | 35 QI 53 | 54 | 36 RM* 55 | 56 | 37 S 57 | 38 SM 58 | 59 | 39 U 60 | 40 UB 61 | -------------------------------------------------------------------------------- /notes68/4.ic: -------------------------------------------------------------------------------- 1 | Instruction Classes 2 | ------------------- 3 | i ABCD - | AA 4 | ADDX bwl | DD 5 | SBCD - | 6 | SUBX bwl | 7 | 8 | ii ADD bwl | AS 9 | SUB bwl | FP __I 10 | | OA 11 | | OB __A 12 | 13 | iii ADDQ bwl | FN 14 | SUBQ bwl | 15 | 16 | iv AND bwl | AS 17 | OR bwl | FH __CCR 18 | | FI __SR 19 | | FN __I 20 | | GA 21 | 22 | v ASL bwl | AA 23 | ASR bwl | FA 24 | LSL bwl | S 25 | LSR bwl | 26 | ROL bwl | 27 | ROR bwl | 28 | ROXL bwl | 29 | ROXR bwl | 30 | 31 | vi Bcc - | G 32 | BRA - | 33 | BSR - | 34 | 35 | vii BCHG - | AP 36 | BCLR - | FP 37 | BSET - | 38 | BTST - | 39 | 40 | viii CHK - | QA 41 | DIVS - | 42 | DIVU - | 43 | MULS - | 44 | MULU - | 45 | 46 | ix CLR bwl | P 47 | NBCD - | 48 | NEG bwl | 49 | NEGX bwl | 50 | NOT bwl | 51 | Scc - | 52 | TAS - | 53 | TST bwl | 54 | 55 | x CMP bwl | FP __I 56 | | OA 57 | | OB __A 58 | 59 | xi CMPM bwl | CC 60 | 61 | xii DBcc - | AG 62 | 63 | xiii EOR bwl | AP 64 | | FH __CCR 65 | | FI __SR 66 | | FP __I 67 | 68 | xiv EXG - | MM 69 | 70 | xv EXT bwl | A 71 | SWAP - | 72 | 73 | xvi ILLEGAL - | J 74 | NOP - | 75 | RESET - | 76 | RTE - | 77 | RTR - | 78 | RTS - | 79 | TRAPV - | 80 | 81 | xvii JMP - | U 82 | JSR - | 83 | PEA - | 84 | 85 | xviii LEA - | UB 86 | 87 | xix LINK - | BF 88 | 89 | xx MOV bwl | BK __USP 90 | | HP CCR__ 91 | | IP SR__ 92 | | KB __USP 93 | | LM __C 94 | | ML __C 95 | | OB __I 96 | | OP 97 | | QH __CCR 98 | | QI __SR 99 | 100 | xxi MOVEM wl | M*T 101 | | RM* 102 | 103 | xxii MOVEP wl | AE 104 | | EA 105 | 106 | xxiii MOVEQ - | FA 107 | 108 | xxiv MOVS bwl | MS 109 | | SM 110 | 111 | xxv RTD - | F 112 | STOP - | 113 | TRAP - | 114 | 115 | xxvi UNLK - | B 116 | -------------------------------------------------------------------------------- /object.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_H_ 2 | #define OBJECT_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | void outputObjectFile(void); 7 | void outputWord(int aWord); 8 | void outputPartition(void); 9 | void outputBigword(long unsigned int bigword); 10 | void outputByte(byte aByte); 11 | void outputString(stringType *string); 12 | void outputStartAddress(addressType startAddress); 13 | void outputRelocatableCode(void); 14 | void outputBreak(codeBreakType *codeBreak); 15 | void outputAbsoluteCode(void); 16 | void outputOneCodeBuffer(codeSegmentType *segment); 17 | void outputPseudoSegment(addressType codeStartAddress, addressType codeEndAddress); 18 | bool isObjectSymbol(symbolTableEntryType *symbol); 19 | void enumerateAndCountSymbols(void); 20 | int enumerateAndCountReferences(void); 21 | void outputReference(expressionReferenceType *reference); 22 | void outputReferenceInfo(void); 23 | void outputOneSymbol(symbolTableEntryType *symbol); 24 | void outputSymbolTableInfo(void); 25 | int symbolCompare(symbolTableEntryType **symbol1, symbolTableEntryType **symbol2); 26 | bool shouldDumpSymbol(symbolTableEntryType *symbol); 27 | void dumpSymbolTable(void); 28 | bool hackableSymbol(symbolTableEntryType *symbol); 29 | void printValueTersely(valueType *value); 30 | void outputReservations(void); 31 | void outputExpressionBuffer(void); 32 | void outputOneExpression(expressionType *expression); 33 | void outputExpressions(void); 34 | void outputOneFunction(functionDefinitionType *function); 35 | void outputFunctions(void); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /operandBody_6502.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | operandBody_6502.h -- Define parser tree types for 6502 operands. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 18-April-1985 28 | */ 29 | 30 | typedef stringType stringOperandBodyType; 31 | 32 | typedef expressionType xIndexedOperandBodyType; 33 | 34 | typedef expressionType yIndexedOperandBodyType; 35 | 36 | typedef expressionType preIndexedXOperandBodyType; 37 | 38 | typedef expressionType postIndexedYOperandBodyType; 39 | 40 | typedef nullType yRegisterOperandBodyType; 41 | 42 | typedef nullType xRegisterOperandBodyType; 43 | 44 | typedef nullType aRegisterOperandBodyType; 45 | 46 | typedef expressionType immediateOperandBodyType; 47 | 48 | typedef expressionType indirectOperandBodyType; 49 | 50 | typedef expressionType expressionOperandBodyType; 51 | 52 | typedef BlockType blockOperandBodyType; 53 | 54 | typedef selectionListType xSelectedOperandBodyType; 55 | 56 | typedef selectionListType ySelectedOperandBodyType; 57 | 58 | typedef selectionListType preSelectedOperandBodyType; 59 | 60 | typedef union { 61 | expressionOperandBodyType *expressionUnion; 62 | immediateOperandBodyType *immediateUnion; 63 | indirectOperandBodyType *indirectUnion; 64 | aRegisterOperandBodyType *aRegisterUnion; 65 | xRegisterOperandBodyType *xRegisterUnion; 66 | yRegisterOperandBodyType *yRegisterUnion; 67 | postIndexedYOperandBodyType *postIndexedYUnion; 68 | preIndexedXOperandBodyType *preIndexedXUnion; 69 | xIndexedOperandBodyType *xIndexedUnion; 70 | yIndexedOperandBodyType *yIndexedUnion; 71 | xSelectedOperandBodyType *xSelectedUnion; 72 | ySelectedOperandBodyType *ySelectedUnion; 73 | preSelectedOperandBodyType *preSelectedUnion; 74 | stringOperandBodyType *stringUnion; 75 | blockOperandBodyType *blockUnion; 76 | } operandBodyType; 77 | -------------------------------------------------------------------------------- /operandBody_68000.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | operandBody_68000.h -- Define parser tree types for 68000 operands. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 25-April-1985 28 | */ 29 | 30 | typedef expressionType expressionOperandBodyType; 31 | 32 | typedef stringType stringOperandBodyType; 33 | 34 | typedef BlockType blockOperandBodyType; 35 | 36 | typedef nullType dRegisterOperandBodyType; 37 | 38 | typedef nullType aRegisterOperandBodyType; 39 | 40 | typedef nullType aRegisterIndirectOperandBodyType; 41 | 42 | typedef nullType postincrementOperandBodyType; 43 | 44 | typedef nullType predecrementOperandBodyType; 45 | 46 | typedef expressionType displacementOperandBodyType; 47 | 48 | typedef selectionListType selectedOperandBodyType; 49 | 50 | typedef expressionType indexedOperandBodyType; 51 | 52 | typedef selectionListType indexSelectedOperandBodyType; 53 | 54 | typedef expressionType pcDisplacementOperandBodyType; 55 | 56 | typedef expressionType pcIndexedOperandBodyType; 57 | 58 | typedef expressionType immediateOperandBodyType; 59 | 60 | typedef expressionType absoluteShortOperandBodyType; 61 | 62 | typedef expressionType absoluteLongOperandBodyType; 63 | 64 | typedef nullType ccRegisterOperandBodyType; 65 | 66 | typedef nullType statusRegisterOperandBodyType; 67 | 68 | typedef nullType uspRegisterOperandBodyType; 69 | 70 | typedef nullType controlRegisterOperandBodyType; 71 | 72 | typedef union { 73 | expressionOperandBodyType *expressionUnion; 74 | stringOperandBodyType *stringUnion; 75 | blockOperandBodyType *blockUnion; 76 | dRegisterOperandBodyType *dRegisterUnion; 77 | aRegisterOperandBodyType *aRegisterUnion; 78 | aRegisterIndirectOperandBodyType *aRegisterIndirectUnion; 79 | postincrementOperandBodyType *postincrementUnion; 80 | predecrementOperandBodyType *predecrementUnion; 81 | displacementOperandBodyType *displacementUnion; 82 | selectedOperandBodyType *selectionUnion; 83 | indexedOperandBodyType *indexedUnion; 84 | indexSelectedOperandBodyType *indexSelectedUnion; 85 | pcDisplacementOperandBodyType *pcDisplacementUnion; 86 | pcIndexedOperandBodyType *pcIndexedUnion; 87 | immediateOperandBodyType *immediateUnion; 88 | absoluteShortOperandBodyType *absoluteShortUnion; 89 | absoluteLongOperandBodyType *absoluteLongUnion; 90 | ccRegisterOperandBodyType *ccRegisterUnion; 91 | statusRegisterOperandBodyType *statusRegisterUnion; 92 | uspRegisterOperandBodyType *uspRegisterUnion; 93 | controlRegisterOperandBodyType *controlRegisterUnion; 94 | } operandBodyType; 95 | 96 | #define SFC_REGISTER 0 97 | #define DFC_REGISTER 1 98 | #define VBR_REGISTER 2 99 | -------------------------------------------------------------------------------- /operandDefs_6502.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | operandDefs_6502.h -- Define operand types and flag bits for 6502. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 18-April-1985 28 | */ 29 | 30 | typedef enum { 31 | EXPRESSION_OPND, IMMEDIATE_OPND, INDIRECT_OPND, 32 | A_REGISTER_OPND, X_REGISTER_OPND, Y_REGISTER_OPND, 33 | POST_INDEXED_Y_OPND, PRE_INDEXED_X_OPND, X_INDEXED_OPND, 34 | Y_INDEXED_OPND, X_SELECTED_OPND, Y_SELECTED_OPND, 35 | PRE_SELECTED_X_OPND, STRING_OPND, BLOCK_OPND 36 | } operandKindType; 37 | 38 | #define operandKindField(op) op 39 | 40 | /* Opcodes: */ 41 | /* In the opcode table we want to have information that tells which possible 42 | address modes the corresponding instruction can utilize. The 43 | instruction set of the 6502 breaks up into classes of instructions, such 44 | that all of the instructions in a class accept the same address modes. 45 | We encode the instructions by class and the classes by permissible address 46 | modes. This helps us reduce errors in construction of the opcode table, 47 | since getting one instruction of a given class right means getting all the 48 | others right too. */ 49 | typedef enum { 50 | RELATIVE, DIR_1, DIR_2, DIR_INDIR, DIR_X_1, DIR_X_2, DIR_X_3, 51 | DIR_Y, IMM_DIR, IMM_DIR_X, IMM_DIR_Y, NONE, INDEX, IMM_INDEX 52 | } addressClassType; 53 | 54 | #define NO_OPND_BIT 0x0000 55 | #define EXPRESSION_OPND_BIT 0x0001 56 | #define IMMEDIATE_OPND_BIT 0x0002 57 | #define INDIRECT_OPND_BIT 0x0004 58 | #define A_REGISTER_OPND_BIT 0x0008 59 | #define X_REGISTER_OPND_BIT 0x0010 60 | #define Y_REGISTER_OPND_BIT 0x0020 61 | #define POST_INDEXED_Y_OPND_BIT 0x0040 62 | #define PRE_INDEXED_X_OPND_BIT 0x0080 63 | #define X_INDEXED_OPND_BIT 0x0100 64 | #define Y_INDEXED_OPND_BIT 0x0200 65 | #define X_SELECTED_OPND_BIT 0x0400 66 | #define Y_SELECTED_OPND_BIT 0x0800 67 | #define PRE_SELECTED_X_OPND_BIT 0x1000 68 | #define STRING_OPND_BIT 0x2000 69 | #define BLOCK_OPND_BIT 0x4000 70 | #define ANY_OPND_BITS 0xFFFF 71 | 72 | #define REL_CLASS_BITS EXPRESSION_OPND_BIT 73 | #define DIR_1_CLASS_BITS EXPRESSION_OPND_BIT 74 | #define DIR_2_CLASS_BITS EXPRESSION_OPND_BIT 75 | #define DIR_INDIR_CLASS_BITS EXPRESSION_OPND_BIT | INDIRECT_OPND_BIT 76 | #define DIR_X_1_CLASS_BITS EXPRESSION_OPND_BIT | X_INDEXED_OPND_BIT | \ 77 | X_SELECTED_OPND_BIT | A_REGISTER_OPND_BIT 78 | #define DIR_X_2_CLASS_BITS EXPRESSION_OPND_BIT | X_INDEXED_OPND_BIT | \ 79 | X_SELECTED_OPND_BIT 80 | #define DIR_X_3_CLASS_BITS EXPRESSION_OPND_BIT | X_INDEXED_OPND_BIT | \ 81 | X_SELECTED_OPND_BIT 82 | #define DIR_Y_CLASS_BITS EXPRESSION_OPND_BIT | Y_INDEXED_OPND_BIT | \ 83 | Y_SELECTED_OPND_BIT 84 | #define IMM_DIR_CLASS_BITS EXPRESSION_OPND_BIT | IMMEDIATE_OPND_BIT 85 | #define IMM_DIR_X_CLASS_BITS EXPRESSION_OPND_BIT | IMMEDIATE_OPND_BIT | \ 86 | X_INDEXED_OPND_BIT | X_SELECTED_OPND_BIT 87 | #define IMM_DIR_Y_CLASS_BITS EXPRESSION_OPND_BIT | IMMEDIATE_OPND_BIT | \ 88 | Y_INDEXED_OPND_BIT | Y_SELECTED_OPND_BIT 89 | #define NONE_CLASS_BITS NO_OPND_BIT 90 | #define IMM_INDEX_CLASS_BITS X_INDEXED_OPND_BIT | Y_INDEXED_OPND_BIT | \ 91 | X_SELECTED_OPND_BIT | Y_SELECTED_OPND_BIT | \ 92 | IMMEDIATE_OPND_BIT | PRE_INDEXED_X_OPND_BIT |\ 93 | POST_INDEXED_Y_OPND_BIT | \ 94 | EXPRESSION_OPND_BIT | PRE_SELECTED_X_OPND_BIT 95 | #define INDEX_CLASS_BITS X_INDEXED_OPND_BIT | Y_INDEXED_OPND_BIT | \ 96 | X_SELECTED_OPND_BIT | Y_SELECTED_OPND_BIT | \ 97 | PRE_INDEXED_X_OPND_BIT | \ 98 | POST_INDEXED_Y_OPND_BIT | \ 99 | EXPRESSION_OPND_BIT | PRE_SELECTED_X_OPND_BIT 100 | 101 | #define MAX_NUMBER_OF_OPERANDS 1 102 | -------------------------------------------------------------------------------- /operandStuff.h: -------------------------------------------------------------------------------- 1 | #ifndef OPERAND_STUFF_H_ 2 | #define OPERAND_STUFF_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | #if TARGET_CPU == CPU_6502 7 | operandType *buildOperand(operandKindType kindOfOperand, anyOldThing *arg); 8 | #elif TARGET_CPU == CPU_68000 9 | operandType *buildOperand(operandKindType kindOfOperand, int arg1, int arg2, int arg3, int arg4); 10 | #else 11 | #error Unknown or undefined processor type 12 | #endif 13 | 14 | operandListType *duplicateOperandForFixup(operandListType *operand, bool isSpecialFunctionOperand); 15 | void freeOperand(operandType *operand); 16 | void expandOperand(operandKindType addressMode, char *buffer); 17 | valueType *evaluateOperand(operandType *operand); 18 | conditionType invertConditionCode(conditionType conditionCode); 19 | bool shouldParenthesize(operandType *operand); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /opt/.mark: -------------------------------------------------------------------------------- 1 | Mon Feb 2 23:18:37 PST 1987 2 | -------------------------------------------------------------------------------- /opt/Makefile: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .o .c .h .run 2 | 3 | # to make for another target CPU, redefine PROC to the name of the target 4 | # processor, e.g., 68000 5 | PROC =6502 6 | 7 | OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\ 8 | buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\ 9 | emitBranch.o emitStuff.o encode.o errorStuff.o expressionSemantics.o fixups.o\ 10 | garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ 11 | malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.o\ 12 | statementSemantics.o structSemantics.o tokenStrings.o 13 | 14 | SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\ 15 | buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\ 16 | debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c encode.c errorStuff.c\ 17 | expressionSemantics.c fixups.c garbage.c initialize.c lexer.c listing.c\ 18 | lookups.c macrossTables_$(PROC).c main.c malloc.c object.c\ 19 | operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ 20 | structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ 21 | macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 22 | conditionDefs_$(PROC).h driver.c 23 | 24 | HEADERS = macrossTypes.h macrossGlobals.h 25 | 26 | .c.o: 27 | cc -c -O -DTARGET_CPU=CPU_$(PROC) $*.c 28 | 29 | .c.run: 30 | cc -o $* $*.c 31 | 32 | macross: $(OBJECTS) 33 | cc -O -o macross $(OBJECTS) 34 | 35 | driver: driver.c 36 | cc -o driver driver.c 37 | 38 | update: .mark 39 | kessel "(cd /u0/chip/macross; make macross >&errorfyle)" & 40 | 41 | install: macross 42 | cp macross macross_tmp 43 | strip macross_tmp 44 | cp /u1/gg/bin/macross_$(PROC) /u1/gg/bin/macross_$(PROC).old 45 | cp macross_tmp /u1/gg/bin/macross_$(PROC) 46 | rm macross_tmp 47 | cp /u1/gg/bin/macross_$(PROC) /net/mycroft/u1/gg/bin 48 | cp /u1/gg/bin/macross_$(PROC) /net/shem/u1/gg/bin 49 | cp /u1/gg/bin/macross_$(PROC) /net/weyr/u1/gg/bin 50 | 51 | dinstall: driver 52 | cp driver /u1/gg/bin/driver_tmp 53 | strip /u1/gg/bin/driver_tmp 54 | mv /u1/gg/bin/driver_tmp /u1/gg/bin/driver/macross 55 | cp /u1/gg/bin/driver /net/mycroft/u1/gg/bin/macross 56 | cp /u1/gg/bin/driver /net/shem/u1/gg/bin/macross 57 | cp /u1/gg/bin/driver /net/weyr/u1/gg/bin/macross 58 | 59 | change: 60 | rm *.o 61 | rm *.tab.* 62 | cp Makefile_68000 Makefile 63 | 64 | move: .mark 65 | 66 | .mark: $(SOURCES) 67 | cp $? /net/kessel/u0/chip/macross 68 | cp $? /net/kessel/u0/chip/macross/prof 69 | cp $? .. 70 | date >.mark 71 | date >/net/kessel/u0/chip/macross/.mark 72 | date >/net/kessel/u0/chip/macross/prof/.mark 73 | date >../.mark 74 | 75 | macrossTypes.h: macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 76 | conditionDefs_$(PROC).h 77 | 78 | actions.o: actions_$(PROC).c $(HEADERS) 79 | cc -c -O -DTARGET_CPU=CPU_$(PROC) actions_$(PROC).c 80 | mv actions_$(PROC).o actions.o 81 | 82 | buildStuff1.o: buildStuff1.c $(HEADERS) 83 | 84 | buildStuff2.o: buildStuff2.c $(HEADERS) 85 | 86 | buildStuff3.o: buildStuff3.c $(HEADERS) 87 | 88 | builtInFunctions.o: builtInFunctions.c $(HEADERS) 89 | 90 | builtInFunsSD.o: builtInFunsSD_$(PROC).c $(HEADERS) 91 | cc -c -O -DTARGET_CPU=CPU_$(PROC) builtInFunsSD_$(PROC).c 92 | mv builtInFunsSD_$(PROC).o builtInFunsSD.o 93 | 94 | debugPrint.o: debugPrint.c y.tab.h $(HEADERS) 95 | 96 | debugPrintSD.o: debugPrintSD_$(PROC).c y.tab.h $(HEADERS) 97 | cc -c -O -DTARGET_CPU=CPU_$(PROC) debugPrintSD_$(PROC).c 98 | mv debugPrintSD_$(PROC).o debugPrintSD.o 99 | 100 | emitBranch.o: emitBranch_$(PROC).c $(HEADERS) 101 | cc -c -O -DTARGET_CPU=CPU_$(PROC) emitBranch_$(PROC).c 102 | mv emitBranch_$(PROC).o emitBranch.o 103 | 104 | emitStuff.o: emitStuff.c $(HEADERS) 105 | cc -c -O -DTARGET_CPU=CPU_$(PROC) emitStuff.c 106 | 107 | encode.o: encode.c $(HEADERS) 108 | 109 | errorStuff.o: errorStuff.c $(HEADERS) 110 | 111 | expressionSemantics.o: expressionSemantics.c y.tab.h $(HEADERS) 112 | 113 | fixups.o: fixups.c $(HEADERS) 114 | 115 | garbage.o: garbage.c y.tab.h $(HEADERS) 116 | 117 | initialize.o: initialize.c $(HEADERS) 118 | 119 | lexer.o: lexer.c lexerTables.h y.tab.h $(HEADERS) 120 | 121 | listing.o: listing.c $(HEADERS) 122 | 123 | lookups.o: lookups.c $(HEADERS) 124 | 125 | macrossTables.o: macrossTables_$(PROC).c y.tab.h macrossTypes.h 126 | cc -c -O -DTARGET_CPU=CPU_$(PROC) macrossTables_$(PROC).c 127 | mv macrossTables_$(PROC).o macrossTables.o 128 | 129 | malloc.o: malloc.c 130 | 131 | main.o: main.c $(HEADERS) 132 | 133 | object.o: object.c $(HEADERS) 134 | 135 | operandStuffSD.o: operandStuffSD_$(PROC).c $(HEADERS) 136 | cc -c -O -DTARGET_CPU=CPU_$(PROC) operandStuffSD_$(PROC).c 137 | mv operandStuffSD_$(PROC).o operandStuffSD.o 138 | 139 | parserMisc.o: parserMisc.c y.tab.h $(HEADERS) 140 | 141 | semanticMisc.o: semanticMisc.c $(HEADERS) 142 | 143 | statementSemantics.o: statementSemantics.c $(HEADERS) 144 | 145 | structSemantics.o: structSemantics.c $(HEADERS) 146 | 147 | tokenStrings.o: tokenStrings_$(PROC).c $(HEADERS) 148 | cc -c -O -DTARGET_CPU=CPU_$(PROC) tokenStrings_$(PROC).c 149 | mv tokenStrings_$(PROC).o tokenStrings.o 150 | 151 | y.tab.o: y.tab.c $(HEADERS) 152 | cc -c -O -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) y.tab.c 153 | 154 | y.tab.c y.tab.h: macross_$(PROC).y 155 | yacc -d macross_$(PROC).y 156 | 157 | y.output: macross_$(PROC).y 158 | yacc -vd macross_$(PROC).y 159 | 160 | cleanup: 161 | /bin/rm -f *.o y.output y.tab.c y.tab.h macross 162 | 163 | love: 164 | @echo "Not war?" 165 | 166 | -------------------------------------------------------------------------------- /opt/Makefile_6502: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .o .c .h .run 2 | 3 | # to make for another target CPU, redefine PROC to the name of the target 4 | # processor, e.g., 68000 5 | PROC =6502 6 | 7 | OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\ 8 | buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\ 9 | emitBranch.o emitStuff.o errorStuff.o expressionSemantics.o fixups.o\ 10 | garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ 11 | malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.o\ 12 | statementSemantics.o structSemantics.o tokenStrings.o 13 | 14 | SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\ 15 | buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\ 16 | debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c errorStuff.c\ 17 | expressionSemantics.c fixups.c garbage.c initialize.c lexer.c listing.c\ 18 | lookups.c macrossTables_$(PROC).c main.c malloc.c object.c\ 19 | operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ 20 | structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ 21 | macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 22 | conditionDefs_$(PROC).h driver.c 23 | 24 | HEADERS = macrossTypes.h macrossGlobals.h 25 | 26 | .c.o: 27 | cc -O -c -DTARGET_CPU=CPU_$(PROC) $*.c 28 | 29 | .c.run: 30 | cc -O -o $* $*.c 31 | 32 | macross: $(OBJECTS) 33 | cc -O -o macross $(OBJECTS) 34 | 35 | driver: driver.c 36 | cc -O -o driver driver.c 37 | 38 | update: .mark 39 | kessel "(cd /u0/chip/macross; make macross >&errorfyle)" & 40 | 41 | install: macross 42 | cp macross /u1/gg/bin/macross_tmp 43 | strip /u1/gg/bin/macross_tmp 44 | mv /u1/gg/bin/macross_$(PROC) /u1/gg/bin/macross_$(PROC).old 45 | mv /u1/gg/bin/macross_tmp /u1/gg/bin/macross_$(PROC) 46 | cp /u1/gg/bin/macross_$(PROC) /net/mycroft/u1/gg/bin 47 | cp /u1/gg/bin/macross_$(PROC) /net/shem/u1/gg/bin 48 | cp /u1/gg/bin/macross_$(PROC) /net/weyr/u1/gg/bin 49 | 50 | dinstall: driver 51 | cp driver /u1/gg/bin/driver_tmp 52 | strip /u1/gg/bin/driver_tmp 53 | mv /u1/gg/bin/driver_tmp /u1/gg/bin/macross 54 | cp /u1/gg/bin/macross /net/mycroft/u1/gg/bin/macross 55 | cp /u1/gg/bin/macross /net/shem/u1/gg/bin/macross 56 | cp /u1/gg/bin/macross /net/weyr/u1/gg/bin/macross 57 | 58 | change: 59 | rm *.o 60 | rm *.tab.* 61 | cp Makefile_68000 Makefile 62 | 63 | move: .mark 64 | 65 | .mark: $(SOURCES) 66 | cp $? /net/kessel/u0/chip/macross 67 | cp $? /net/kessel/u0/chip/macross/prof 68 | cp $? .. 69 | date >.mark 70 | date >/net/kessel/u0/chip/macross/.mark 71 | date >/net/kessel/u0/chip/macross/prof/.mark 72 | date >../.mark 73 | 74 | macrossTypes.h: macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 75 | conditionDefs_$(PROC).h 76 | 77 | actions.o: actions_$(PROC).c $(HEADERS) 78 | cc -O -c -DTARGET_CPU=CPU_$(PROC) actions_$(PROC).c 79 | mv actions_$(PROC).o actions.o 80 | 81 | buildStuff1.o: buildStuff1.c $(HEADERS) 82 | 83 | buildStuff2.o: buildStuff2.c $(HEADERS) 84 | 85 | buildStuff3.o: buildStuff3.c $(HEADERS) 86 | 87 | builtInFunctions.o: builtInFunctions.c $(HEADERS) 88 | 89 | builtInFunsSD.o: builtInFunsSD_$(PROC).c $(HEADERS) 90 | cc -O -c -DTARGET_CPU=CPU_$(PROC) builtInFunsSD_$(PROC).c 91 | mv builtInFunsSD_$(PROC).o builtInFunsSD.o 92 | 93 | debugPrint.o: debugPrint.c y.tab.h $(HEADERS) 94 | 95 | debugPrintSD.o: debugPrintSD_$(PROC).c y.tab.h $(HEADERS) 96 | cc -O -c -DTARGET_CPU=CPU_$(PROC) debugPrintSD_$(PROC).c 97 | mv debugPrintSD_$(PROC).o debugPrintSD.o 98 | 99 | emitBranch.o: emitBranch_$(PROC).c $(HEADERS) 100 | cc -O -c -DTARGET_CPU=CPU_$(PROC) emitBranch_$(PROC).c 101 | mv emitBranch_$(PROC).o emitBranch.o 102 | 103 | emitStuff.o: emitStuff.c $(HEADERS) 104 | cc -O -c -DTARGET_CPU=CPU_$(PROC) emitStuff.c 105 | 106 | errorStuff.o: errorStuff.c $(HEADERS) 107 | 108 | expressionSemantics.o: expressionSemantics.c y.tab.h $(HEADERS) 109 | 110 | fixups.o: fixups.c $(HEADERS) 111 | 112 | garbage.o: garbage.c y.tab.h $(HEADERS) 113 | 114 | initialize.o: initialize.c $(HEADERS) 115 | 116 | lexer.o: lexer.c lexerTables.h y.tab.h $(HEADERS) 117 | 118 | listing.o: listing.c $(HEADERS) 119 | 120 | lookups.o: lookups.c $(HEADERS) 121 | 122 | macrossTables.o: macrossTables_$(PROC).c y.tab.h macrossTypes.h 123 | cc -O -c -DTARGET_CPU=CPU_$(PROC) macrossTables_$(PROC).c 124 | mv macrossTables_$(PROC).o macrossTables.o 125 | 126 | malloc.o: malloc.c 127 | 128 | main.o: main.c $(HEADERS) 129 | 130 | object.o: object.c $(HEADERS) 131 | 132 | operandStuffSD.o: operandStuffSD_$(PROC).c $(HEADERS) 133 | cc -O -c -DTARGET_CPU=CPU_$(PROC) operandStuffSD_$(PROC).c 134 | mv operandStuffSD_$(PROC).o operandStuffSD.o 135 | 136 | parserMisc.o: parserMisc.c y.tab.h $(HEADERS) 137 | 138 | semanticMisc.o: semanticMisc.c $(HEADERS) 139 | 140 | statementSemantics.o: statementSemantics.c $(HEADERS) 141 | 142 | structSemantics.o: structSemantics.c $(HEADERS) 143 | 144 | tokenStrings.o: tokenStrings_$(PROC).c $(HEADERS) 145 | cc -O -c -DTARGET_CPU=CPU_$(PROC) tokenStrings_$(PROC).c 146 | mv tokenStrings_$(PROC).o tokenStrings.o 147 | 148 | y.tab.o: y.tab.c $(HEADERS) 149 | cc -O -c -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) y.tab.c 150 | 151 | y.tab.c y.tab.h: macross_$(PROC).y 152 | yacc -d macross_$(PROC).y 153 | 154 | y.output: macross_$(PROC).y 155 | yacc -vd macross_$(PROC).y 156 | 157 | cleanup: 158 | /bin/rm -f *.o y.output y.tab.c y.tab.h macross 159 | 160 | love: 161 | @echo "Not war?" 162 | 163 | -------------------------------------------------------------------------------- /opt/Makefile_68000: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .o .c .h .run 2 | 3 | # to make for another target CPU, redefine PROC to the name of the target 4 | # processor, e.g., 68000 5 | PROC =68000 6 | 7 | OBJECTS = y.tab.o actions.o buildStuff1.o buildStuff2.o\ 8 | buildStuff3.o builtInFunctions.o builtInFunsSD.o debugPrint.o debugPrintSD.o\ 9 | emitBranch.o emitStuff.o errorStuff.o expressionSemantics.o fixups.o\ 10 | garbage.o initialize.o lexer.o listing.o lookups.o macrossTables.o main.o\ 11 | malloc.o object.o operandStuffSD.o parserMisc.o semanticMisc.o\ 12 | statementSemantics.o structSemantics.o tokenStrings.o 13 | 14 | SOURCES = macross_$(PROC).y actions_$(PROC).c buildStuff1.c buildStuff2.c\ 15 | buildStuff3.c builtInFunctions.c builtInFunsSD_$(PROC).c debugPrint.c\ 16 | debugPrintSD_$(PROC).c emitBranch_$(PROC).c emitStuff.c errorStuff.c\ 17 | expressionSemantics.c fixups.c garbage.c initialize.c lexer.c listing.c\ 18 | lookups.c macrossTables_$(PROC).c main.c malloc.c object.c\ 19 | operandStuffSD_$(PROC).c parserMisc.c semanticMisc.c statementSemantics.c\ 20 | structSemantics.c tokenStrings_$(PROC).c lexerTables.h macrossGlobals.h\ 21 | macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 22 | conditionDefs_$(PROC).h driver.c 23 | 24 | HEADERS = macrossTypes.h macrossGlobals.h 25 | 26 | .c.o: 27 | cc -O -c -DTARGET_CPU=CPU_$(PROC) $*.c 28 | 29 | .c.run: 30 | cc -O -o $* $*.c 31 | 32 | macross: $(OBJECTS) 33 | cc -O -o macross $(OBJECTS) 34 | 35 | driver: driver.c 36 | cc -O -o driver driver.c 37 | 38 | update: .mark 39 | kessel "(cd /u0/chip/macross; make macross >&errorfyle)" & 40 | 41 | install: macross 42 | cp macross /u1/gg/bin/macross_tmp 43 | strip /u1/gg/bin/macross_tmp 44 | mv /u1/gg/bin/macross_$(PROC) /u1/gg/bin/macross_$(PROC).old 45 | mv /u1/gg/bin/macross_tmp /u1/gg/bin/macross_$(PROC) 46 | cp /u1/gg/bin/macross_$(PROC) /net/mycroft/u1/gg/bin 47 | cp /u1/gg/bin/macross_$(PROC) /net/shem/u1/gg/bin 48 | cp /u1/gg/bin/macross_$(PROC) /net/weyr/u1/gg/bin 49 | 50 | dinstall: driver 51 | cp driver /u1/gg/bin/driver_tmp 52 | strip /u1/gg/bin/driver_tmp 53 | mv /u1/gg/bin/driver_tmp /u1/gg/bin/macross 54 | cp /u1/gg/bin/macross /net/mycroft/u1/gg/bin/macross 55 | cp /u1/gg/bin/macross /net/shem/u1/gg/bin/macross 56 | cp /u1/gg/bin/macross /net/weyr/u1/gg/bin/macross 57 | 58 | change: 59 | rm *.o 60 | rm *.tab.* 61 | cp Makefile_6502 Makefile 62 | 63 | move: .mark 64 | 65 | .mark: $(SOURCES) 66 | cp $? /net/kessel/u0/chip/macross 67 | cp $? /net/kessel/u0/chip/macross/prof 68 | cp $? .. 69 | date >.mark 70 | date >/net/kessel/u0/chip/macross/.mark 71 | date >/net/kessel/u0/chip/macross/prof/.mark 72 | date >../.mark 73 | 74 | macrossTypes.h: macrossTypes.h operandDefs_$(PROC).h operandBody_$(PROC).h\ 75 | conditionDefs_$(PROC).h 76 | 77 | actions.o: actions_$(PROC).c $(HEADERS) 78 | cc -O -c -DTARGET_CPU=CPU_$(PROC) actions_$(PROC).c 79 | mv actions_$(PROC).o actions.o 80 | 81 | buildStuff1.o: buildStuff1.c $(HEADERS) 82 | 83 | buildStuff2.o: buildStuff2.c $(HEADERS) 84 | 85 | buildStuff3.o: buildStuff3.c $(HEADERS) 86 | 87 | builtInFunctions.o: builtInFunctions.c $(HEADERS) 88 | 89 | builtInFunsSD.o: builtInFunsSD_$(PROC).c $(HEADERS) 90 | cc -O -c -DTARGET_CPU=CPU_$(PROC) builtInFunsSD_$(PROC).c 91 | mv builtInFunsSD_$(PROC).o builtInFunsSD.o 92 | 93 | debugPrint.o: debugPrint.c y.tab.h $(HEADERS) 94 | 95 | debugPrintSD.o: debugPrintSD_$(PROC).c y.tab.h $(HEADERS) 96 | cc -O -c -DTARGET_CPU=CPU_$(PROC) debugPrintSD_$(PROC).c 97 | mv debugPrintSD_$(PROC).o debugPrintSD.o 98 | 99 | emitBranch.o: emitBranch_$(PROC).c $(HEADERS) 100 | cc -O -c -DTARGET_CPU=CPU_$(PROC) emitBranch_$(PROC).c 101 | mv emitBranch_$(PROC).o emitBranch.o 102 | 103 | emitStuff.o: emitStuff.c $(HEADERS) 104 | cc -O -c -DTARGET_CPU=CPU_$(PROC) emitStuff.c 105 | 106 | errorStuff.o: errorStuff.c $(HEADERS) 107 | 108 | expressionSemantics.o: expressionSemantics.c y.tab.h $(HEADERS) 109 | 110 | fixups.o: fixups.c $(HEADERS) 111 | 112 | garbage.o: garbage.c y.tab.h $(HEADERS) 113 | 114 | initialize.o: initialize.c $(HEADERS) 115 | 116 | lexer.o: lexer.c lexerTables.h y.tab.h $(HEADERS) 117 | 118 | listing.o: listing.c $(HEADERS) 119 | 120 | lookups.o: lookups.c $(HEADERS) 121 | 122 | macrossTables.o: macrossTables_$(PROC).c y.tab.h macrossTypes.h 123 | cc -O -c -DTARGET_CPU=CPU_$(PROC) macrossTables_$(PROC).c 124 | mv macrossTables_$(PROC).o macrossTables.o 125 | 126 | malloc.o: malloc.c 127 | 128 | main.o: main.c $(HEADERS) 129 | 130 | object.o: object.c $(HEADERS) 131 | 132 | operandStuffSD.o: operandStuffSD_$(PROC).c $(HEADERS) 133 | cc -O -c -DTARGET_CPU=CPU_$(PROC) operandStuffSD_$(PROC).c 134 | mv operandStuffSD_$(PROC).o operandStuffSD.o 135 | 136 | parserMisc.o: parserMisc.c y.tab.h $(HEADERS) 137 | 138 | semanticMisc.o: semanticMisc.c $(HEADERS) 139 | 140 | statementSemantics.o: statementSemantics.c $(HEADERS) 141 | 142 | structSemantics.o: structSemantics.c $(HEADERS) 143 | 144 | tokenStrings.o: tokenStrings_$(PROC).c $(HEADERS) 145 | cc -O -c -DTARGET_CPU=CPU_$(PROC) tokenStrings_$(PROC).c 146 | mv tokenStrings_$(PROC).o tokenStrings.o 147 | 148 | y.tab.o: y.tab.c $(HEADERS) 149 | cc -O -c -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) y.tab.c 150 | 151 | y.tab.c y.tab.h: macross_$(PROC).y 152 | yacc -d macross_$(PROC).y 153 | 154 | y.output: macross_$(PROC).y 155 | yacc -vd macross_$(PROC).y 156 | 157 | cleanup: 158 | /bin/rm -f *.o y.output y.tab.c y.tab.h macross 159 | 160 | love: 161 | @echo "Not war?" 162 | 163 | -------------------------------------------------------------------------------- /parserMisc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | parserMisc.c -- Miscellaneous parser support routines for the Macross 24 | assembler. 25 | 26 | Chip Morningstar -- Lucasfilm Ltd. 27 | 28 | 3-November-1984 29 | 30 | */ 31 | 32 | #include "macrossTypes.h" 33 | #include "macrossGlobals.h" 34 | #include "y.tab.h" 35 | #include "buildStuff.h" 36 | #include "fixups.h" 37 | #include "initialize.h" 38 | #include "errorStuff.h" 39 | #include "parserMisc.h" 40 | 41 | #include 42 | #include 43 | 44 | statementType * 45 | addLabelToStatement(labelListType *labelList, statementType *statement) 46 | { 47 | if (statement == NULL) 48 | statement = newStatement(NULL_STATEMENT, (statementBodyType){ NULL }); 49 | statement->labels = labelList; 50 | return(statement); 51 | } 52 | 53 | /* TODO: This should be a varargs function. In 1984 it probably wasn't 54 | * standardized, but here in Glorious Future Year 1989 the vprintf 55 | * function does almost exactly what we want. */ 56 | 57 | void 58 | botch(char *message, ...) 59 | { 60 | va_list ap; 61 | printf("Macross horrible terrible internal botch: "); 62 | va_start(ap, message); 63 | vprintf(message, ap); 64 | va_end(ap); 65 | chokePukeAndDie(); 66 | } 67 | 68 | void 69 | checkDefineAssignmentOperator(assignmentKindType assignmentOperator) 70 | { 71 | if (assignmentOperator != ASSIGN_ASSIGN) 72 | puntOnError(DEFINE_ASSIGNMENT_WRONG_ERROR); 73 | } 74 | 75 | statementType * 76 | convertDefineToMdefine(statementType *defineStatement) 77 | { 78 | if (defineStatement->kindOfStatement != DEFINE_STATEMENT) 79 | botch("convertDefineToMdefine got statement kind: %d\n", 80 | defineStatement->kindOfStatement, 0, 0); 81 | defineStatement->kindOfStatement = MDEFINE_STATEMENT; 82 | return(defineStatement); 83 | } 84 | 85 | ifStatementBodyType * 86 | extractIfBody(statementType *ifStatement) 87 | { 88 | ifStatementBodyType *result; 89 | 90 | result = ifStatement->statementBody.ifUnion; 91 | if (ifStatement->labels != NULL) 92 | botch("extract if body with non-null labels\n", 0, 0, 0); 93 | else if (ifStatement->nextStatement != NULL) 94 | botch("extract if body with non-null next\n", 0, 0, 0); 95 | else 96 | qfree(ifStatement); 97 | return(result); 98 | } 99 | 100 | mifStatementBodyType * 101 | extractMifBody(statementType *mifStatement) 102 | { 103 | mifStatementBodyType *result; 104 | 105 | result = mifStatement->statementBody.mifUnion; 106 | if (mifStatement->labels != NULL) 107 | botch("extract mif body with non-null labels\n", 0, 0, 0); 108 | else if (mifStatement->nextStatement != NULL) 109 | botch("extract mif body with non-null next\n", 0, 0, 0); 110 | else 111 | qfree(mifStatement); 112 | return(result); 113 | } 114 | 115 | stringType * 116 | extractString(operandType *textExpression) 117 | { 118 | stringType *result; 119 | 120 | if (textExpression->kindOfOperand != STRING_OPND) 121 | botch("extract string got handed an opnd kind: %d\n", 122 | textExpression->kindOfOperand, 0, 0); 123 | result = textExpression->theOperand.stringUnion; 124 | qfree(textExpression); 125 | return(result); 126 | } 127 | 128 | void 129 | popMacroOrFunctionNestingDepth(void) 130 | { 131 | if (--macroOrFunctionNestingDepth == 0) 132 | unknownSymbolTag = UNKNOWN_SYMBOL; 133 | } 134 | 135 | void 136 | pushMacroOrFunctionNestingDepth(void) 137 | { 138 | macroOrFunctionNestingDepth++; 139 | unknownSymbolTag = NESTED_UNKNOWN_SYMBOL; 140 | } 141 | 142 | char * 143 | saveString(char *s) 144 | { 145 | char *result; 146 | 147 | result = (char *)malloc(strlen(s)+1); 148 | strcpy(result, s); 149 | return(result); 150 | } 151 | -------------------------------------------------------------------------------- /parserMisc.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSER_MISC_H_ 2 | #define PARSER_MISC_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | statementType *addLabelToStatement(labelListType *labelList, statementType *statement); 7 | void botch(char *message, ...); 8 | void checkDefineAssignmentOperator(assignmentKindType assignmentOperator); 9 | statementType *convertDefineToMdefine(statementType *defineStatement); 10 | ifStatementBodyType *extractIfBody(statementType *ifStatement); 11 | mifStatementBodyType *extractMifBody(statementType *mifStatement); 12 | stringType *extractString(operandType *textExpression); 13 | void popMacroOrFunctionNestingDepth(void); 14 | void pushMacroOrFunctionNestingDepth(void); 15 | char *saveString(char *s); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /semanticMisc.h: -------------------------------------------------------------------------------- 1 | #ifndef SEMANTIC_MISC_H_ 2 | #define SEMANTIC_MISC_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | /* Miscellaneous */ 7 | bool absoluteValue(valueType *address); 8 | void addAttributeToSymbol(symbolTableEntryType *symbol, symbolAttributesType attribute); 9 | addressType addressValue(valueType *value); 10 | valueKindType addValueKind(valueType *leftOperand, valueType *rightOperand); 11 | bool alreadyDefined(symbolInContextType *context); 12 | bool booleanTest(expressionType *expression); 13 | int countArguments(functionDefinitionType *function); 14 | int countParameters(operandListType *parameterList); 15 | arrayType *allocArray(int size, valueType ***contentsPtr); 16 | valueType *createArray(expressionType *dimension, expressionListType *initializers); 17 | bool decrementable(valueType *value); 18 | int expressionListLength(expressionListType *expressionList); 19 | int fieldValue(symbolTableEntryType *symbol); 20 | bool incrementable(valueType *value); 21 | int intValue(valueType *value); 22 | bool isAssignable(symbolInContextType *context); 23 | bool isBuiltInFunction(symbolInContextType *context); 24 | bool isDefinable(symbolInContextType *context); 25 | bool isExternal(symbolTableEntryType *symbol); 26 | bool isFailure(valueType *value); 27 | bool isFunction(symbolInContextType *context); 28 | bool isLastStatementInBlock(statementType *statement); 29 | bool isLogicalOp(int op); 30 | bool isPotentialVariable(symbolInContextType *context); 31 | bool isUndefined(valueType *value); 32 | bool isUsable(valueType *value); 33 | bool logicalXOR(int int1, int int2); 34 | valueType *newValue(valueKindType kindOfValue, int value, operandKindType addressMode); 35 | valueKindType opValueKind(valueType *leftOperand, valueType *rightOperand); 36 | bool relocatableValue(valueType *address); 37 | valueKindType selectValueKind(valueType *leftOperand, valueType *rightOperand); 38 | valueKindType subValueKind(valueType *leftOperand, valueType *rightOperand); 39 | int swabInt(int i); 40 | valueType *swabValue(valueType *value); 41 | valueKindType unopValueKind(valueType *operand); 42 | void valueField(symbolTableEntryType *symbol, valueType *value); 43 | void valueLabel(symbolTableEntryType *symbol, valueType *value); 44 | 45 | /* Fixups and references */ 46 | void createFixup(expressionType *expression, addressType location, fixupKindType kindOfFixup, codeBufferKindType codeMode, int whichFixup); 47 | void finishUp(void); 48 | void noteAnonymousReference(void); 49 | void noteReference(expressionType *expression, fixupKindType kindOfFixup, addressType location, codeBufferKindType codeMode); 50 | void performFixups(fixupListType *fixups); 51 | void performStartAddressFixup(void); 52 | void putFixupsHere(fixupKindType kindOfFixupsToPut, int whichFixup); 53 | 54 | /* Contexts and dynamic symbol creation */ 55 | void addNewLocalVariable(symbolTableEntryType *symbol); 56 | symbolTableEntryType *effectiveSymbol(symbolTableEntryType *symbol, symbolInContextType **assignmentTargetContext); 57 | symbolTableEntryType *generateLocalLabel(symbolTableEntryType *symbol); 58 | symbolInContextType *getBaseContext(symbolTableEntryType *identifier); 59 | symbolInContextType *getWorkingContext(symbolTableEntryType *identifier); 60 | stringType *localLabelString(symbolTableEntryType *symbol); 61 | int localLabelTagValue(symbolTableEntryType *symbol); 62 | void addBreak(codeBreakKindType kind, int data); 63 | void reserveAbsolute(addressType startAddress, int blockSize); 64 | bool listableStatement(statementKindType kind); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /slinky/.mark: -------------------------------------------------------------------------------- 1 | Fri Jun 6 14:51:43 PDT 1986 2 | -------------------------------------------------------------------------------- /slinky/DOC: -------------------------------------------------------------------------------- 1 | /u0/chip/macross/slinky: 2 | This directory contains the source to Slinky. Here's what's here: 3 | 4 | DOC - This file 5 | Makefile - Makefile to compile it 6 | *.c, *.h - source files 7 | opt/ - directory for optimized version, as mentioned in 8 | documentation above for /u0/chip/macross/opt 9 | -------------------------------------------------------------------------------- /slinky/Makefile: -------------------------------------------------------------------------------- 1 | # to make for another target CPU, redefine PROC to the name of the target 2 | # processor, e.g., 68000 3 | PROC =6502 4 | 5 | SLINKY_OBJECTS = builtins.o debugPrint.o errorStuff.o expr.o \ 6 | globals.o initialize.o instantiate.o link.o main.o \ 7 | map.o poke.o read.o relocate.o slinkyTables.o \ 8 | write.o 9 | 10 | CFLAGS=-m32 -g -ansi -DYYDEBUG -DTARGET_CPU=CPU_$(PROC) 11 | LDFLAGS=-m32 12 | 13 | # If yacc is notionally present on a system, it's usually actually 14 | # bison in a compatibility mode. bison is available by name more often 15 | # than yacc itself is. 16 | YACC=bison -y 17 | #YACC=yacc 18 | 19 | # Pick a compiler if you have one in particular you want. 20 | CC=cc 21 | #CC=gcc 22 | #CC=clang 23 | 24 | slinky: $(SLINKY_OBJECTS) 25 | $(CC) $(LDFLAGS) -o slinky $(SLINKY_OBJECTS) 26 | 27 | clean: 28 | /bin/rm -f *.o slinky 29 | 30 | love: 31 | @echo "Not war?" 32 | 33 | # Slinky needs to use the parser headers created by Macross. If they 34 | # aren't available, we dip down and make them ourselves. 35 | ../y.tab.h: ../macross_$(PROC).y 36 | cd .. && $(YACC) -d macross_$(PROC).y && cd slinky 37 | 38 | .c.o: 39 | $(CC) $(CFLAGS) -c $< 40 | 41 | Makefile.depend: 42 | makedepend -Y -f - *.c > Makefile.depend 43 | 44 | depend: Makefile.depend 45 | 46 | include Makefile.depend 47 | -------------------------------------------------------------------------------- /slinky/Makefile.depend: -------------------------------------------------------------------------------- 1 | # DO NOT DELETE 2 | 3 | builtins.o: slinkyTypes.h slinkyGlobals.h slinkyExpressions.h builtins.h 4 | builtins.o: errorStuff.h expr.h link.h relocate.h 5 | debugPrint.o: slinkyTypes.h slinkyGlobals.h debugPrint.h 6 | errorStuff.o: slinkyTypes.h slinkyGlobals.h errorStuff.h 7 | expr.o: slinkyTypes.h slinkyGlobals.h slinkyExpressions.h expr.h errorStuff.h 8 | expr.o: initialize.h ../y.tab.h 9 | globals.o: slinkyTypes.h slinkyGlobals.h 10 | initialize.o: slinkyTypes.h slinkyGlobals.h initialize.h errorStuff.h main.h 11 | instantiate.o: slinkyTypes.h slinkyGlobals.h slinkyExpressions.h errorStuff.h 12 | instantiate.o: expr.h instantiate.h ../y.tab.h 13 | link.o: slinkyTypes.h slinkyGlobals.h link.h debugPrint.h errorStuff.h 14 | link.o: instantiate.h poke.h read.h relocate.h write.h 15 | main.o: slinkyTypes.h slinkyGlobals.h main.h initialize.h link.h 16 | map.o: slinkyTypes.h slinkyGlobals.h map.h debugPrint.h link.h 17 | poke.o: slinkyTypes.h slinkyGlobals.h poke.h debugPrint.h errorStuff.h expr.h 18 | read.o: slinkyTypes.h slinkyGlobals.h read.h debugPrint.h errorStuff.h 19 | read.o: initialize.h instantiate.h link.h 20 | relocate.o: slinkyTypes.h slinkyGlobals.h relocate.h debugPrint.h 21 | relocate.o: errorStuff.h link.h map.h 22 | slinkyTables.o: slinkyTypes.h builtins.h 23 | write.o: slinkyTypes.h slinkyGlobals.h write.h 24 | -------------------------------------------------------------------------------- /slinky/builtins.h: -------------------------------------------------------------------------------- 1 | #ifndef BUILTINS_H_ 2 | #define BUILTINS_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | void tooFewArgs(int argCount, stringType *name); 7 | void tooManyArgs(int argCount, stringType *name); 8 | stringType *atasciiBIF(int argCount); 9 | stringType *atasciiColorBIF(int argCount); 10 | bool isAbsoluteValueBIF(int argCount); 11 | bool isConditionCodeBIF(int argCount); 12 | bool isDefinedBIF(int argCount); 13 | bool isExternalBIF(int argCount); 14 | int nthCharBIF(int argCount); 15 | int printfBIF(int argCount); 16 | stringType *strcatBIF(int argCount); 17 | int strcmpBIF(int argCount); 18 | int strcmplcBIF(int argCount); 19 | int strlenBIF(int argCount); 20 | char *substrBIF(int argCount); 21 | addressType symbolLookupBIF(int argCount); 22 | stringType *symbolNameBIF(int argCount); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /slinky/debugPrint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | debugPrint.c -- Routines to dump stuff out in readable form for 24 | debugging the Slinky linker. 25 | 26 | Chip Morningstar -- Lucasfilm Ltd. 27 | 28 | 18-March-1985 29 | 30 | */ 31 | 32 | #include "slinkyTypes.h" 33 | #include "slinkyGlobals.h" 34 | #include "debugPrint.h" 35 | 36 | static char *modeStrings[2] = { 37 | "abs", 38 | "rel", 39 | }; 40 | 41 | static char *kindStrings[3] = { 42 | "byte", 43 | "word", 44 | "dbyt", 45 | }; 46 | 47 | static char *pcrelStrings[2] = { 48 | " ", 49 | "pcrel", 50 | }; 51 | 52 | static char *externalStrings[2] = { 53 | " ", 54 | "extern", 55 | }; 56 | 57 | static char *symbolStrings[6] = { 58 | "und ", /* 0x00 */ 59 | "und ext", /* 0x01 */ 60 | "abs ", /* 0x02 */ 61 | "abs ext", /* 0x03 */ 62 | "rel ", /* 0x04 */ 63 | "rel ext", /* 0x05 */ 64 | }; 65 | 66 | void 67 | printCode(int startAddress, int endAddress, int mode) 68 | { 69 | printf(" Code: 0x%04x:0x%04x %s\n", startAddress, endAddress, 70 | modeStrings[mode]); 71 | } 72 | 73 | void 74 | printReference(expressionReferenceType *reference) 75 | { 76 | printf(" Ref : 0x%04x (%s %s %s %s) expression #%d\n", reference-> 77 | referenceAddress, modeStrings[reference->referenceMode], 78 | pcrelStrings[reference->referenceRelative], externalStrings[ 79 | reference->referenceExternal], kindStrings[reference-> 80 | referenceKind], reference->referenceExpression.inFile); 81 | } 82 | 83 | void 84 | printReferenceFixup(expressionReferenceType *reference) 85 | { 86 | printf(" Ref : 0x%04x (%s %s %s %s) expression=0x%x\n", 87 | reference->referenceAddress, modeStrings[reference-> 88 | referenceMode],pcrelStrings[reference->referenceRelative], 89 | externalStrings[reference->referenceExternal], kindStrings[ 90 | reference->referenceKind], reference->referenceExpression. 91 | inCore); 92 | } 93 | 94 | void 95 | printSymbol(int symbolTag, symbolType *symbol) 96 | { 97 | printf(" Symb: %3d %s 0x%04x \"%s\"\n", symbolTag, symbolStrings[ 98 | symbol->symbolClass], symbol->symbolValue, 99 | symbol->symbolName); 100 | } 101 | 102 | void 103 | printLoadMapSymbol(symbolType *symbol) 104 | { 105 | fprintf(mapFileOutput, "%-20s 0x%04x %s ", symbol->symbolName, 106 | symbol->symbolValue, symbolStrings[symbol->symbolClass]); 107 | } 108 | 109 | void 110 | printGlobalSymbols(void) 111 | { 112 | int symbolCount; 113 | 114 | printf("Globals:\n"); 115 | printf(" %d global symbols\n", globalSymbolCount); 116 | for (symbolCount=0; symbolCountsymbolName); 119 | } 120 | } 121 | 122 | void 123 | printExpression(expressionPCType expression, int length) 124 | { 125 | int line; 126 | int i; 127 | 128 | printf("expression length = %d:\n", length); 129 | for (line=0; line 35 | 36 | static void 37 | verror(errorType theError, va_list ap) 38 | { 39 | /* This table MUST be maintained congruently with the definition of the 40 | enumerated type 'errorType'. */ 41 | 42 | static char *errorMessageStrings[] = { 43 | "no file name on command line after '-o'", 44 | "unknown command line flag '-%c'", 45 | "more than one output file name given on command line", 46 | "can't open load file '%s'", 47 | "can't open object file '%s'", 48 | "no input files given!", 49 | "file '%s' is not a valid Macross object file", 50 | "premature end of file on object file '%s'", 51 | "error reading object file '%s'", 52 | "absolute code in '%s' with addresses 0x%04x:0x%04x overlaps absolute code in '%s' with addresses 0x%04x:0x%04x", 53 | "can't find a place to relocate relocatable code segment starting at 0x%04x in file '%s'", 54 | "multiply defined symbol '%s'", 55 | "'%s' undefined", 56 | "relative offset %d too large to fit at byte (0x%04x) 0x%04x", 57 | "value 0x%x too large to fit at byte (0x%04x) 0x%04x", 58 | "value 0x%x too large to fit at word (0x%04x) 0x%04x", 59 | "no file name on command line after '-m'", 60 | "more than one load map file name given on command line", 61 | "can't open load map file '%s'", 62 | "bad load address ('%s') given on command line", 63 | "no load address on command line after '-l'", 64 | "array term found in expression in object file", 65 | "ASSERT failed: %s", 66 | "condition code term in expression in object file", 67 | "'mswitch' clause at top level -- boo boo", 68 | "too many arguments to function inside object", 69 | "too few arguments to built in function '%s'", 70 | "too many arguments to built in function '%s'", 71 | "bad position argument to 'nthChar'", 72 | "bad substring indices to 'substr'", 73 | "argument to 'symbolName' is not a symbol", 74 | "symbol '%s' undefined in 'symbolLookup()'", 75 | }; 76 | 77 | printf("\"%s\": ", currentFileName); 78 | vprintf(errorMessageStrings[(int)theError], ap); 79 | printf("\n"); 80 | errorFlag = TRUE; 81 | } 82 | 83 | void 84 | error(errorType theError, ...) 85 | { 86 | va_list ap; 87 | va_start(ap, theError); 88 | verror(theError, ap); 89 | va_end(ap); 90 | } 91 | -------------------------------------------------------------------------------- /slinky/errorStuff.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_STUFF_H_ 2 | #define ERROR_STUFF_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | void error(errorType theError, ...); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /slinky/errorfyle: -------------------------------------------------------------------------------- 1 | cc -c -g builtins.c 2 | cc -c -g debugPrint.c 3 | cc -c -g errorStuff.c 4 | cc -c -g expr.c 5 | cc -c -g initialize.c 6 | cc -c -g instantiate.c 7 | cc -c -g link.c 8 | cc -c -g main.c 9 | cc -c -g map.c 10 | cc -c -g poke.c 11 | cc -c -g read.c 12 | cc -c -g relocate.c 13 | cc -c -g slinkyTables.c 14 | cc -c -g write.c 15 | cc -g -o slinky builtins.o debugPrint.o errorStuff.o expr.o initialize.o instantiate.o link.o main.o map.o poke.o read.o relocate.o slinkyTables.o write.o 16 | -------------------------------------------------------------------------------- /slinky/expr.h: -------------------------------------------------------------------------------- 1 | #ifndef EXPR_H_ 2 | #define EXPR_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | int getNumber(void); 7 | addressType evaluateArray(void); 8 | addressType evaluateAssert(void); 9 | addressType evaluateBinop(void); 10 | addressType evaluateBlock(void); 11 | addressType evaluateConditionCode(void); 12 | void pushSymbol(symbolType *symbol, addressType value); 13 | void bindFunctionArguments(functionType *theFunction, int argCount); 14 | void undoBindings(void); 15 | addressType evaluateFreturn(void); 16 | addressType evaluateBuiltinFunctionCall(void); 17 | addressType evaluateFunctionCall(void); 18 | addressType evaluateHere(void); 19 | addressType evaluateMdefine(void); 20 | addressType evaluateMdoUntil(void); 21 | addressType evaluateMdoWhile(void); 22 | addressType evaluateMfor(void); 23 | addressType evaluateMif(void); 24 | bool evaluateClause(addressType pattern); 25 | addressType evaluateMswitch(void); 26 | addressType evaluateMwhile(void); 27 | addressType evaluateMvariable(void); 28 | addressType evaluateNumber(void); 29 | addressType evaluateRelocatableNumber(void); 30 | addressType evaluatePerform(void); 31 | addressType evaluatePostop(void); 32 | addressType evaluatePreop(void); 33 | addressType evaluateString(void); 34 | addressType evaluateSymbol(void); 35 | addressType evaluateUnop(void); 36 | addressType evaluateExpression(void); 37 | void skipArray(void); 38 | void skipAssert(void); 39 | void skipBinop(void); 40 | void skipBlock(void); 41 | void skipFunctionCall(void); 42 | void skipMdefine(void); 43 | void skipMdoUntil(void); 44 | void skipMdoWhile(void); 45 | void skipMfor(void); 46 | void skipMif(void); 47 | void skipClause(void); 48 | void skipMswitch(void); 49 | void skipMvariable(void); 50 | void skipMwhile(void); 51 | void skipPostop(void); 52 | void skipPreop(void); 53 | void skipString(void); 54 | void skipUnop(void); 55 | void skipExpression(void); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /slinky/globals.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | slinkyGlobals.h -- Global variables for the Slinky linker. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 9-March-1985 28 | */ 29 | 30 | #include "slinkyTypes.h" 31 | #include "slinkyGlobals.h" 32 | 33 | bool debug; /* TRUE iff we should print debug diagnostics */ 34 | bool errorFlag; /* TRUE iff an error occured during linking */ 35 | bool verbose; 36 | bool packFlag; 37 | FILE *loadFileOutput; /* where to put the results */ 38 | FILE *mapFileOutput; 39 | objectFileListType *objectFileList; 40 | objectFileListType *endOfObjectFileList; 41 | char *currentFileName; 42 | freeSegmentEntryType *freeSegmentList; 43 | freeSegmentEntryType *effectiveFreeSegmentList; 44 | addressType relocationOffset; 45 | addressType entryPointAddress; 46 | int entryPointMode; 47 | expressionPCType entryPointExpression; 48 | bool produceLoadMap; 49 | bool leaveOffLoadFiles; 50 | bool haveEntryPoint; 51 | bool haveExpressionEntryPoint; 52 | bool readExpressionEntryPoint; 53 | symbolType **globalSymbolTable; 54 | int globalSymbolCount; 55 | symbolType **currentSymbolTable; 56 | functionType *currentFunctionTable; 57 | reservationListType *reservationList; 58 | int totalSymbolCount; 59 | expressionPCType pc; 60 | addressType here; 61 | bindingListType *localBindings; 62 | 63 | segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE]; 64 | -------------------------------------------------------------------------------- /slinky/initialize.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | initialize.c -- Program initialization for the Slinky linker. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 9-March-1985 28 | */ 29 | 30 | #include "slinkyTypes.h" 31 | #include "slinkyGlobals.h" 32 | #include "initialize.h" 33 | #include "errorStuff.h" 34 | #include "main.h" 35 | 36 | #include 37 | #include 38 | 39 | static char *outputFileName; 40 | 41 | void 42 | chokePukeAndDie(void) 43 | { 44 | unlink(outputFileName); 45 | exit(1); 46 | } 47 | 48 | void 49 | initializeStuff(int argc, char **argv) 50 | { 51 | int i; 52 | int j; 53 | char **args; 54 | char *arg; 55 | int outputFilesFound; 56 | int mapFilesFound; 57 | char *mapFileName; 58 | 59 | currentFileName = ""; 60 | errorFlag = FALSE; 61 | packFlag = FALSE; 62 | debug = FALSE; 63 | verbose = FALSE; 64 | objectFileList = endOfObjectFileList = NULL; 65 | reservationList = NULL; 66 | haveEntryPoint = FALSE; 67 | readExpressionEntryPoint = FALSE; 68 | haveExpressionEntryPoint = FALSE; 69 | globalSymbolCount = 0; 70 | produceLoadMap = FALSE; 71 | leaveOffLoadFiles = FALSE; 72 | 73 | for (i=0; isegmentStartAddress = FIRST_AVAILABLE_LOCATION; 79 | freeSegmentList->segmentEndAddress = LAST_AVAILABLE_LOCATION; 80 | freeSegmentList->nextFreeSegment = NULL; 81 | 82 | outputFilesFound = 0; 83 | outputFileName = DEFAULT_LOAD_FILE_NAME; 84 | mapFilesFound = 0; 85 | mapFileName = NULL; 86 | 87 | args = argv + 1; 88 | for (i=1; i= argc) { 106 | error(NO_LOAD_ADDRESS_ERROR); 107 | chokePukeAndDie(); 108 | } else { 109 | queueLoadAddress(*args++); 110 | } 111 | continue; 112 | 113 | case 'm': 114 | if (++i >= argc) { 115 | error(NO_MAP_FILE_NAME_ERROR); 116 | chokePukeAndDie(); 117 | } else { 118 | mapFileName = *args++; 119 | mapFilesFound++; 120 | } 121 | produceLoadMap = TRUE; 122 | continue; 123 | 124 | case 'n': 125 | leaveOffLoadFiles = TRUE; 126 | continue; 127 | 128 | case 'o': 129 | if (++i >= argc) { 130 | error(NO_DASH_O_FILE_NAME_ERROR); 131 | chokePukeAndDie(); 132 | } else { 133 | outputFileName = *args++; 134 | outputFilesFound++; 135 | } 136 | continue; 137 | 138 | case 'p': 139 | packFlag = TRUE; 140 | continue; 141 | 142 | case 'v': 143 | printVersion(); 144 | continue; 145 | 146 | default: 147 | error(BAD_COMMAND_LINE_FLAG_ERROR, arg[j]); 148 | continue; 149 | } 150 | } 151 | 152 | if (outputFilesFound > 1) { 153 | error(MORE_THAN_ONE_OUTPUT_FILE_ERROR); 154 | chokePukeAndDie(); 155 | } else if ((loadFileOutput = fopen(outputFileName, "w"))==NULL) { 156 | error(CANT_OPEN_LOAD_FILE_ERROR, outputFileName); 157 | perror("Unix says"); 158 | chokePukeAndDie(); 159 | } 160 | 161 | if (mapFilesFound > 1) { 162 | error(MORE_THAN_ONE_MAP_FILE_ERROR); 163 | chokePukeAndDie(); 164 | } else if (mapFilesFound == 1) { 165 | if (strcmp(mapFileName, "-") == 0) { 166 | mapFileOutput = stdout; 167 | } else if ((mapFileOutput = fopen(mapFileName, "w")) == NULL){ 168 | error(CANT_OPEN_MAP_FILE_ERROR, mapFileName); 169 | perror("Unix says"); 170 | chokePukeAndDie(); 171 | } 172 | } 173 | currentFileName = outputFileName; 174 | } 175 | 176 | 177 | void 178 | queueInputFile(char *name) 179 | { 180 | objectFileListType *newObjectFile; 181 | 182 | newObjectFile = typeAlloc(objectFileListType); 183 | newObjectFile->name = name; 184 | newObjectFile->symbolTable = NULL; 185 | newObjectFile->codeSegments = NULL; 186 | newObjectFile->lastCodeSegment = NULL; 187 | newObjectFile->nextObjectFile = NULL; 188 | if (objectFileList == NULL) { 189 | objectFileList = endOfObjectFileList = newObjectFile; 190 | } else { 191 | endOfObjectFileList->nextObjectFile = newObjectFile; 192 | endOfObjectFileList = newObjectFile; 193 | } 194 | } 195 | 196 | void 197 | queueLoadAddress(char *addressString) 198 | { 199 | int loadAddress; 200 | objectFileListType *newObjectFile; 201 | 202 | if (sscanf(addressString, "0x%x", &loadAddress) != 1) { 203 | if (sscanf(addressString, "0X%x", &loadAddress) != 1) { 204 | if (sscanf(addressString, "%x", &loadAddress) != 1) { 205 | error(BAD_LOAD_ADDRESS_ERROR, addressString); 206 | chokePukeAndDie(); 207 | }}} 208 | newObjectFile = typeAlloc(objectFileListType); 209 | newObjectFile->name = NULL;/* NULL name encodes load address change */ 210 | newObjectFile->symbolCount = loadAddress; /* then address goes here */ 211 | newObjectFile->nextObjectFile = NULL; 212 | if (objectFileList == NULL) { 213 | objectFileList = endOfObjectFileList = newObjectFile; 214 | } else { 215 | endOfObjectFileList->nextObjectFile = newObjectFile; 216 | endOfObjectFileList = newObjectFile; 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /slinky/initialize.h: -------------------------------------------------------------------------------- 1 | #ifndef INITIALIZE_H_ 2 | #define INITIALIZE_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | void chokePukeAndDie(void); 7 | void initializeStuff(int argc, char **argv); 8 | void queueInputFile(char *name); 9 | void queueLoadAddress(char *addressString); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /slinky/instantiate.h: -------------------------------------------------------------------------------- 1 | #ifndef INSTANTIATE_H_ 2 | #define INSTANTIATE_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | void putNumber(int number); 7 | void instantiateSymbol(void); 8 | void instantiateFunction(void); 9 | void putSymbolPointersIntoArray(void); 10 | void putSymbolPointersIntoAssert(void); 11 | void putSymbolPointersIntoBinop(void); 12 | void putSymbolPointersIntoBlock(void); 13 | void putSymbolPointersIntoBuiltinFunctionCall(void); 14 | void putSymbolPointersIntoFunctionCall(void); 15 | void putSymbolPointersIntoMdefine(void); 16 | void putSymbolPointersIntoMdoUntil(void); 17 | void putSymbolPointersIntoMdoWhile(void); 18 | void putSymbolPointersIntoMfor(void); 19 | void putSymbolPointersIntoMif(void); 20 | void putSymbolPointersIntoClause(void); 21 | void putSymbolPointersIntoMswitch(void); 22 | void putSymbolPointersIntoMvariable(void); 23 | void putSymbolPointersIntoMwhile(void); 24 | void putSymbolPointersIntoPostop(void); 25 | void putSymbolPointersIntoPreop(void); 26 | void putSymbolPointersIntoUnop(void); 27 | void putSymbolPointersIntoExpression(void); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /slinky/link.h: -------------------------------------------------------------------------------- 1 | #ifndef LINK_H_ 2 | #define LINK_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | bool internalizeOneObjectFile(objectFileListType *objectFile); 7 | bool strcmplc(char *s1, char *s2); 8 | bool compareSymbols(symbolType **symbol1, symbolType **symbol2); 9 | void buildGlobalSymbolTable(objectFileListType *inputFileList); 10 | bool readem(void); 11 | codeSegmentHeaderType *locateConflictingSegment(codeSegmentHeaderType *codeSegment); 12 | void reserveSegment(addressType start, addressType end); 13 | codeSegmentHeaderType *allocateAbsolute(codeSegmentHeaderType *codeSegment); 14 | void reserveReservations(void); 15 | void installSegment(codeSegmentHeaderType *codeSegment); 16 | void installAbsoluteCodeSegment(codeSegmentHeaderType *codeSegment); 17 | void linkem(void); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /slinky/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | main.c -- Top level of the Slinky linker 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 9-March-1985 28 | */ 29 | 30 | #include "slinkyTypes.h" 31 | #include "slinkyGlobals.h" 32 | #include "main.h" 33 | #include "initialize.h" 34 | #include "link.h" 35 | 36 | int 37 | main(int argc, char **argv) 38 | { 39 | initializeStuff(argc, argv); 40 | linkem(); 41 | if (errorFlag) 42 | chokePukeAndDie(); 43 | return 0; 44 | } 45 | 46 | void 47 | printVersion(void) 48 | { 49 | printf("Slinky version 1.16.\n"); 50 | } 51 | -------------------------------------------------------------------------------- /slinky/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H_ 2 | #define MAIN_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | void printVersion(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /slinky/map.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | map.c -- Routines to print out load map for the Slinky linker. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 26-March-1985 28 | 29 | */ 30 | 31 | #include "slinkyTypes.h" 32 | #include "slinkyGlobals.h" 33 | #include "map.h" 34 | #include "debugPrint.h" 35 | #include "link.h" 36 | 37 | int 38 | compareLoadMapEntries(loadMapTableEntryType *entry1, loadMapTableEntryType *entry2) 39 | { 40 | int result; 41 | 42 | if ((result = strcmplc(entry1->symbol->symbolName, entry2-> 43 | symbol->symbolName)) != 0) 44 | return(result); 45 | else if (entry1->symbol->symbolValue < entry2->symbol->symbolValue) 46 | return(-1); 47 | else if (entry1->symbol->symbolValue > entry2->symbol->symbolValue) 48 | return(1); 49 | else 50 | return(strcmplc(entry1->fileName, entry2->fileName)); 51 | } 52 | 53 | void 54 | outputLoadMap(void) 55 | { 56 | loadMapTableEntryType *loadMapTable; 57 | loadMapTableEntryType *loadMapPtr; 58 | objectFileListType *inputFileList; 59 | int symbolCount; 60 | int i; 61 | 62 | loadMapPtr = loadMapTable = typeAllocBlock(loadMapTableEntryType, 63 | totalSymbolCount); 64 | for (inputFileList = objectFileList; inputFileList != NULL; 65 | inputFileList = inputFileList->nextObjectFile) { 66 | if (inputFileList->name != NULL) { 67 | for (symbolCount=0; symbolCount < inputFileList->symbolCount; 68 | symbolCount++) { 69 | loadMapPtr->symbol = inputFileList->symbolTable[ 70 | symbolCount]; 71 | loadMapPtr->fileName = inputFileList->name; 72 | loadMapPtr++; 73 | } 74 | } 75 | } 76 | qsort(loadMapTable, totalSymbolCount, sizeof(loadMapTableEntryType), 77 | compareLoadMapEntries); 78 | loadMapPtr = loadMapTable; 79 | for (i=0; isymbol->symbolName, 81 | (loadMapPtr-1)->symbol->symbolName)==0 && 82 | loadMapPtr->symbol->symbolValue==(loadMapPtr- 83 | 1)->symbol->symbolValue && loadMapPtr-> 84 | symbol->symbolClass==(loadMapPtr-1)->symbol-> 85 | symbolClass) { 86 | if (!leaveOffLoadFiles) 87 | fprintf(mapFileOutput, ", %s", loadMapPtr-> 88 | fileName); 89 | } else { 90 | fprintf(mapFileOutput, "\n"); 91 | printLoadMapSymbol(loadMapPtr->symbol); 92 | if (!leaveOffLoadFiles) 93 | fprintf(mapFileOutput, " %s", loadMapPtr-> 94 | fileName); 95 | } 96 | loadMapPtr++; 97 | } 98 | fprintf(mapFileOutput, "\n"); 99 | } 100 | -------------------------------------------------------------------------------- /slinky/map.h: -------------------------------------------------------------------------------- 1 | #ifndef MAP_H_ 2 | #define MAP_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | typedef struct { 7 | symbolType *symbol; 8 | stringType *fileName; 9 | } loadMapTableEntryType; 10 | 11 | int compareLoadMapEntries(loadMapTableEntryType *entry1, loadMapTableEntryType *entry2); 12 | void outputLoadMap(void); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /slinky/opt/.mark: -------------------------------------------------------------------------------- 1 | Fri Jun 6 14:51:46 PDT 1986 2 | -------------------------------------------------------------------------------- /slinky/opt/Makefile: -------------------------------------------------------------------------------- 1 | .SUFFIXES: .o .c .h .run 2 | 3 | OBJECTS = builtins.o debugPrint.o errorStuff.o expr.o initialize.o\ 4 | instantiate.o link.o main.o map.o poke.o read.o relocate.o slinkyTables.o\ 5 | write.o 6 | 7 | SOURCES = builtins.c debugPrint.c errorStuff.c expr.c initialize.c\ 8 | instantiate.c link.c main.c map.c poke.c read.c relocate.c slinkyTables.c\ 9 | write.c slinkyExpressions.h slinkyGlobals.h slinkyTypes.h y.tab.h 10 | 11 | .c.o: 12 | cc -c -O $*.c 13 | 14 | .c.run: 15 | cc -o $* $*.c 16 | 17 | slinky: $(OBJECTS) 18 | cc -O -o slinky $(OBJECTS) 19 | 20 | update: .mark 21 | kessel "(cd /u0/chip/macross/slinky; make slinky >&errorfyle)" & 22 | 23 | move: .mark 24 | 25 | .mark: $(SOURCES) 26 | cp $? /net/kessel/u0/chip/macross/slinky 27 | cp $? /net/kessel/u0/chip/macross/slinky/prof 28 | cp $? .. 29 | date >.mark 30 | date >/net/kessel/u0/chip/macross/slinky/.mark 31 | date >/net/kessel/u0/chip/macross/slinky/prof/.mark 32 | date >../.mark 33 | 34 | install: slinky 35 | cp slinky slinky_tmp 36 | strip slinky_tmp 37 | cp /u1/gg/bin/slinky /u1/gg/bin/slinky.old 38 | cp slinky_tmp /u1/gg/bin/slinky 39 | /bin/rm slinky_tmp 40 | cp /u1/gg/bin/slinky /net/mycroft/u1/gg/bin 41 | cp /u1/gg/bin/slinky /net/shem/u1/gg/bin 42 | cp /u1/gg/bin/slinky /net/weyr/u1/gg/bin 43 | 44 | builtins.o: builtins.c slinkyGlobals.h slinkyTypes.h slinkyExpressions.h 45 | 46 | debugPrint.o: debugPrint.c slinkyGlobals.h slinkyTypes.h 47 | 48 | errorStuff.o: errorStuff.c slinkyGlobals.h slinkyTypes.h 49 | 50 | expr.o: expr.c slinkyExpressions.h slinkyGlobals.h slinkyTypes.h y.tab.h 51 | 52 | initialize.o: initialize.c slinkyGlobals.h slinkyTypes.h 53 | 54 | instantiate.o: instantiate.c slinkyGlobals.h slinkyTypes.h slinkyExpressions.h 55 | 56 | link.o: link.c slinkyGlobals.h slinkyTypes.h 57 | 58 | main.o: main.c slinkyGlobals.h slinkyTypes.h 59 | 60 | map.o: map.c slinkyGlobals.h slinkyTypes.h 61 | 62 | poke.o: poke.c slinkyGlobals.h slinkyTypes.h 63 | 64 | read.o: read.c slinkyGlobals.h slinkyTypes.h 65 | 66 | relocate.o: relocate.c slinkyGlobals.h slinkyTypes.h 67 | 68 | slinkyTables.o: slinkyTables.c slinkyTypes.h 69 | 70 | write.o: write.c slinkyGlobals.h slinkyTypes.h 71 | 72 | cleanup: 73 | /bin/rm -f *.o slinky 74 | 75 | love: 76 | @echo "Not war?" 77 | 78 | -------------------------------------------------------------------------------- /slinky/poke.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | poke.c -- Routines to poke the values of symbolic references into the 24 | generated code for the Slinky linker. 25 | 26 | Chip Morningstar -- Lucasfilm Ltd. 27 | 28 | 18-March-1985 29 | 30 | */ 31 | 32 | #include "slinkyTypes.h" 33 | #include "slinkyGlobals.h" 34 | #include "poke.h" 35 | #include "debugPrint.h" 36 | #include "errorStuff.h" 37 | #include "expr.h" 38 | 39 | bool 40 | isWordSized(int value) 41 | { 42 | return (-32768<=value && value<=65535); 43 | } 44 | 45 | bool 46 | isByteSized(int value) 47 | { 48 | return (-128<=value && value<=255); 49 | } 50 | 51 | bool 52 | isByteOffset(int value) 53 | { 54 | return (-128<=value && value<=127); 55 | } 56 | 57 | int 58 | computeRelativeValue(int valueToPoke, codeSegmentHeaderType *codeSegment, int offset) 59 | { 60 | int fromLocation; 61 | int result; 62 | 63 | fromLocation = codeSegment->segmentStartAddress + offset; 64 | result = valueToPoke - fromLocation; 65 | /* if (result > 0)*/ if (result != 0) 66 | result = result - 1; 67 | else if (result < 0) 68 | result = result + 1; 69 | if (!isByteOffset(result)) { 70 | error(RELATIVE_OFFSET_TOO_LARGE_ERROR, result, offset, 71 | fromLocation); 72 | result = 0; 73 | } 74 | return(result); 75 | } 76 | 77 | int 78 | getBaseValue(byte *codeBuffer, int offset, int referenceKind) 79 | { 80 | int result; 81 | 82 | switch (referenceKind) { 83 | case REF_BYTE: 84 | result = codeBuffer[offset]; 85 | break; 86 | 87 | case REF_DBYTE: 88 | result = (codeBuffer[offset] << 8) | codeBuffer[offset+1]; 89 | break; 90 | 91 | case REF_WORD: 92 | result = codeBuffer[offset] | (codeBuffer[offset+1] << 8); 93 | break; 94 | } 95 | return(result); 96 | } 97 | 98 | void 99 | pokeValue(int value, byte *codeBuffer, int offset, int referenceKind, int trueAddress) 100 | { 101 | switch (referenceKind) { 102 | case REF_BYTE: 103 | if (!isByteSized(value)) { 104 | error(BYTE_VALUE_TOO_LARGE_ERROR, value, offset, 105 | trueAddress); 106 | } else { 107 | codeBuffer[offset] = value; 108 | } 109 | if (debug) 110 | printf(" Byte: 0x%02x at (0x%04x) 0x%04x\n\n", 111 | value&0xFF, offset, trueAddress); 112 | break; 113 | 114 | case REF_WORD: 115 | if (!isWordSized(value)) { 116 | error(WORD_VALUE_TOO_LARGE_ERROR, value, offset, 117 | trueAddress); 118 | } else { 119 | codeBuffer[offset] = value & 0xFF; 120 | codeBuffer[offset+1] = (value >> 8) & 0xFF; 121 | } 122 | if (debug) 123 | printf(" Word: 0x%04x at (0x%04x) 0x%04x\n\n", 124 | value, offset, trueAddress); 125 | break; 126 | 127 | case REF_DBYTE: 128 | if (!isWordSized(value)) { 129 | error(WORD_VALUE_TOO_LARGE_ERROR, value, offset, 130 | trueAddress); 131 | } else { 132 | codeBuffer[offset] = (value >> 8) & 0xFF; 133 | codeBuffer[offset+1] = 0xFF; 134 | } 135 | if (debug) 136 | printf(" Dbyt: 0x%04x at (0x%04x) 0x%04x\n\n", 137 | value, offset, trueAddress); 138 | break; 139 | } 140 | } 141 | 142 | void 143 | fixupReference(expressionReferenceType *reference, codeSegmentHeaderType *codeSegment) 144 | { 145 | int offset; 146 | addressType baseValue; 147 | int valueToPoke; 148 | 149 | /* at this point, we assume we are already pointing at the 150 | correct codeSegment! */ 151 | if (debug) 152 | printReferenceFixup(reference); 153 | offset = reference->referenceAddress - codeSegment-> 154 | segmentStartAddress + codeSegment->relocationOffset; 155 | relocationOffset = codeSegment->relocationOffset; 156 | baseValue = getBaseValue(codeSegment->segmentCodeBuffer, offset, 157 | reference->referenceKind); 158 | 159 | pc = reference->referenceExpression.inCore; 160 | valueToPoke = evaluateExpression(); 161 | if (reference->referenceRelative) 162 | valueToPoke = computeRelativeValue(valueToPoke, codeSegment, 163 | offset); 164 | else 165 | valueToPoke = (short)baseValue + (short)valueToPoke; 166 | pokeValue(valueToPoke, codeSegment->segmentCodeBuffer, offset, 167 | reference->referenceKind, codeSegment->segmentStartAddress + 168 | offset); 169 | 170 | } 171 | 172 | void 173 | pokem(void) 174 | { 175 | objectFileListType *inputFileList; 176 | codeSegmentHeaderType *codeSegment; 177 | expressionReferenceType *reference; 178 | int referenceCount; 179 | 180 | if (debug) 181 | printf("\nFixups:\n"); 182 | 183 | if (haveExpressionEntryPoint) { 184 | pc = entryPointExpression; 185 | entryPointAddress = evaluateExpression(); 186 | } 187 | 188 | for (inputFileList = objectFileList; inputFileList != NULL; 189 | inputFileList = inputFileList->nextObjectFile) { 190 | if (inputFileList->name != NULL) { 191 | currentFileName = inputFileList->name; 192 | for (codeSegment = inputFileList->codeSegments; codeSegment!= 193 | NULL; codeSegment = codeSegment->nextSegment) { 194 | for (reference=codeSegment->segmentReferences, 195 | referenceCount=codeSegment->referenceCount; 196 | referenceCount >0; reference++, referenceCount--){ 197 | fixupReference(reference, codeSegment); 198 | } 199 | } 200 | } 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /slinky/poke.h: -------------------------------------------------------------------------------- 1 | #ifndef POKE_H_ 2 | #define POKE_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | bool isWordSized(int value); 7 | bool isByteSized(int value); 8 | bool isByteOffset(int value); 9 | int computeRelativeValue(int valueToPoke, codeSegmentHeaderType *codeSegment, int offset); 10 | int getBaseValue(byte *codeBuffer, int offset, int referenceKind); 11 | void pokeValue(int value, byte *codeBuffer, int offset, int referenceKind, int trueAddress); 12 | void fixupReference(expressionReferenceType *reference, codeSegmentHeaderType *codeSegment); 13 | void pokem(void); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /slinky/read.h: -------------------------------------------------------------------------------- 1 | #ifndef READ_H_ 2 | #define READ_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | void fileCheck(FILE *fildes, char *fileName); 7 | wordType readWord(FILE *file, char *fileName); 8 | byte readByte(FILE *file, char *fileName); 9 | bigWord readBigword(FILE *file, char *fileName); 10 | bigWord read3ByteWord(FILE *file, char *fileName); 11 | int readString(char *buffer, FILE *fildes, char *fileName); 12 | void readChunk(byte *buffer, int numberOfBytes, FILE *fildes, char *fileName); 13 | void readCode(addressType startAddress, addressType endAddress, int mode, objectFileListType *objectFile, FILE *objectFildes); 14 | bool compareReferences(expressionReferenceType *reference1, expressionReferenceType *reference2); 15 | void sortReferences(expressionReferenceType *theReferences, int numberOfReferences); 16 | void readReference(expressionReferenceType *reference, FILE *fildes, char *fileName); 17 | void readReferences(objectFileListType *objectFile, FILE *objectFildes); 18 | bool compareSymbolValues(symbolType **symbol1, symbolType **symbol2); 19 | void readSymbols(objectFileListType *objectFile, FILE *objectFildes); 20 | expressionPCType readOneExpression(objectFileListType *objectFile, FILE *objectFildes); 21 | void readExpressions(objectFileListType *objectFile, FILE *objectFildes); 22 | argumentListType *readArgumentList(objectFileListType *objectFile, FILE *objectFildes); 23 | void readFunctions(objectFileListType *objectFile, FILE *objectFildes); 24 | void instantiateExpressionAndSymbolPointers(objectFileListType *objectFile); 25 | void readReservations(objectFileListType *objectFile, FILE *objectFildes); 26 | reservationListType *buildReservation(addressType startAddress, int blockSize, reservationListType *nextReservation); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /slinky/relocate.h: -------------------------------------------------------------------------------- 1 | #ifndef RELOCATE_H_ 2 | #define RELOCATE_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | void removeZeroPageFromFreeList(void); 7 | addressType align(addressType address, int alignment); 8 | addressType constrain(addressType address, int size, addressType constraint); 9 | void moveRelocationBase(addressType newBase); 10 | addressType allocateRelocatable(codeSegmentHeaderType *codeSegment); 11 | void relocateOneCodeSegment(codeSegmentHeaderType *codeSegment, addressType targetLocation); 12 | void relocatem(void); 13 | codeSegmentHeaderType *matchModes(symbolType *symbol, codeSegmentHeaderType *codeSegment); 14 | bool matchedModes(symbolType *symbol, codeSegmentHeaderType *codeSegment); 15 | codeSegmentHeaderType *synchronizeCodeSegment(symbolType *symbol, codeSegmentHeaderType *codeSegment); 16 | void handleGlobalSymbol(symbolType *symbol); 17 | void valueSymbol(symbolType *symbol, codeSegmentHeaderType *codeSegment); 18 | symbolType *lookupGlobalSymbol(char *symbolName); 19 | void valueUndefinedSymbol(symbolType *symbol); 20 | void valuem(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /slinky/slinkyExpressions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | slinkyExpressions.h -- Expression definitions for the Slinky linker 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 6-November-1985 28 | */ 29 | 30 | /* 31 | Expressions are stored in the object file in a compact parse-tree 32 | representation. We just read this directly and interpret it on-the-fly 33 | without much sophistication. Function definitions include whole 34 | statements, but the principle is the same. 35 | 36 | The basic form of a syntactic entity is: 37 | +---------+-------------+ 38 | | tagByte | bodyOfThing | 39 | +---------+-------------+ 40 | where 'tabByte' encodes how 'bodyOfThing' is to be interpreted. 41 | 42 | These are the possible 'thing's, as encoded by the 'tagByte's 43 | +------+ 44 | identifier: | sym# | 'sym#' is an index into the symbol entries 45 | +------+ of the object file when the expression is 46 | in the object file too, and then 'sym#' is converted 47 | to a pointer to symbol structure when the symbol 48 | itself is read in. 49 | +-------+-------+------+------+-----+ 50 | functionCall: | func# | argCt | expr | expr | ... | 'argCt' is a 51 | +-------+-------+------+------+-----+ single byte 52 | argument count (which means that a function may have 53 | no more than 255 arguments if it is to be used 54 | externally) and this is how many 'expr's there are. 55 | +-----+ 56 | number: | num | 'num' is just a 4-byte number. 57 | +-----+ 58 | +----+ 59 | conditionCode: | cc | 'cc' is a single byte condition code. 60 | +----+ 61 | +------+ 62 | subexpression: | expr | 63 | +------+ 64 | +----+------+ 65 | unop: | op | expr | 'op' is a 1-byte operation number. 66 | +----+------+ 67 | +----+------+------+ 68 | binop: | op | expr | expr | 69 | +----+------+------+ 70 | +----+------+ 71 | preop: | op | expr | 72 | +----+------+ 73 | +----+------+ 74 | postop: | op | expr | 75 | +----+------+ 76 | 77 | here: empty body. 78 | 79 | +---+---+---+---+-----+----+ 80 | string: | a | b | c | d | ... | \0 | Typical 'C' string. 81 | +---+---+---+---+-----+----+ 82 | +------+------+ 83 | array: | sym# | expr | 84 | +------+------+ 85 | +-----+ 86 | value: | num | 87 | +-----+ 88 | 89 | null: empty body. Encodes null expression *or* statement. 90 | 91 | +-------+-------+-----+-----+ 92 | block: | thing | thing | ... | end | 'end' acts as a 93 | +-------+-------+-----+-----+ termination symbol. 94 | +------+------+ 95 | mdefine: | sym# | expr | 'expr' can be null. 96 | +------+------+ 97 | +------+------+ 98 | mvar: | sym# | expr | 'expr' can be null. 99 | +------+------+ 100 | +------+-------+-------+ 101 | mif: | expr | block | block | either 'block' can be null. 102 | +------+-------+-------+ 103 | +------+------+------+-------+ 104 | mfor: | expr | expr | expr | block | 105 | +------+------+------+-------+ 106 | +------+-------+ 107 | mwhile: | expr | block | 108 | +------+-------+ 109 | +------+-------+ 110 | mdoWhile: | expr | block | 111 | +------+-------+ 112 | +------+-------+ 113 | mdoUntil: | expr | block | 114 | +------+-------+ 115 | +------+ 116 | freturn: | expr | 117 | +------+ 118 | +------+ 119 | perform: | expr | 120 | +------+ 121 | +-------+ 122 | group: | block | 123 | +-------+ 124 | +------+--------+ 125 | assert: | expr | string | 126 | +------+--------+ 127 | +------+--------+--------+-----+-----+ 128 | mswitch: | expr | clause | clause | ... | end | 129 | +------+--------+--------+-----+-----+ 130 | +------+------+-----+-------+ 131 | clause: | expr | expr | ... | block | 132 | +------+------+-----+-------+ 133 | 134 | end: empty body. 135 | 136 | */ 137 | 138 | #define IDENTIFIER_TAG 0x00 139 | #define FUNCTION_CALL_TAG 0x01 140 | #define NUMBER_TAG 0x02 141 | #define CONDITION_CODE_TAG 0x03 142 | #define SUBEXPRESSION_TAG 0x04 143 | #define UNOP_TAG 0x05 144 | #define BINOP_TAG 0x06 145 | #define PREOP_TAG 0x07 146 | #define POSTOP_TAG 0x08 147 | #define HERE_TAG 0x09 148 | #define STRING_TAG 0x0A 149 | #define ARRAY_TAG 0x0B 150 | #define VALUE_TAG 0x0C 151 | #define NULL_TAG 0x0D 152 | #define BLOCK_TAG 0x0E 153 | #define MDEFINE_TAG 0x0F 154 | #define MVARIABLE_TAG 0x10 155 | #define MIF_TAG 0x11 156 | #define MFOR_TAG 0x12 157 | #define MWHILE_TAG 0x13 158 | #define MDOWHILE_TAG 0x14 159 | #define MDOUNTIL_TAG 0x15 160 | #define PERFORM_TAG 0x16 161 | #define GROUP_TAG 0x17 162 | #define ASSERT_TAG 0x18 163 | #define MSWITCH_TAG 0x19 164 | #define CLAUSE_TAG 0x1A 165 | #define END_TAG 0x1B 166 | #define FRETURN_TAG 0x1C 167 | #define BUILTIN_FUNCTION_CALL_TAG 0x1D 168 | #define RELOCATABLE_TAG 0x1E 169 | -------------------------------------------------------------------------------- /slinky/slinkyGlobals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | slinkyGlobals.h -- Global variables for the Slinky linker. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 9-March-1985 28 | */ 29 | 30 | extern bool debug; /* TRUE iff we should print debug diagnostics */ 31 | extern bool errorFlag; /* TRUE iff an error occured during linking */ 32 | extern bool verbose; 33 | extern bool packFlag; 34 | #define DEFAULT_LOAD_FILE_NAME "s.out" 35 | extern FILE *loadFileOutput; /* where to put the results */ 36 | extern FILE *mapFileOutput; 37 | extern objectFileListType *objectFileList; 38 | extern objectFileListType *endOfObjectFileList; 39 | extern char *currentFileName; 40 | extern freeSegmentEntryType *freeSegmentList; 41 | extern freeSegmentEntryType *effectiveFreeSegmentList; 42 | extern addressType relocationOffset; 43 | extern addressType entryPointAddress; 44 | extern int entryPointMode; 45 | extern expressionPCType entryPointExpression; 46 | extern bool produceLoadMap; 47 | extern bool leaveOffLoadFiles; 48 | extern bool haveEntryPoint; 49 | extern bool haveExpressionEntryPoint; 50 | extern bool readExpressionEntryPoint; 51 | extern symbolType **globalSymbolTable; 52 | extern int globalSymbolCount; 53 | extern symbolType **currentSymbolTable; 54 | extern functionType *currentFunctionTable; 55 | extern reservationListType *reservationList; 56 | extern int totalSymbolCount; 57 | extern expressionPCType pc; 58 | extern addressType here; 59 | extern bindingListType *localBindings; 60 | 61 | #define CODE_REGIONS_IN_ADDRESS_SPACE 256 62 | #define CODE_REGION_SIZE 0x100 63 | extern segmentListType *generatedLoadImage[CODE_REGIONS_IN_ADDRESS_SPACE]; 64 | #define regionOf(addr) (addr / CODE_REGION_SIZE) 65 | 66 | extern struct { 67 | stringType *functionName; 68 | addressType (*functionEntry)(); 69 | } builtInFunctionTable[]; 70 | #define MAX_FUNCTIONS 15 71 | -------------------------------------------------------------------------------- /slinky/slinkyTables.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | slinkyTables.c -- Global tables for the Slinky linker. 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 14-November-1985 28 | */ 29 | 30 | #include "slinkyTypes.h" 31 | #include "builtins.h" 32 | 33 | /* Used to initialize symbols representing built-in functions */ 34 | struct { 35 | stringType *functionName; 36 | addressType (*functionEntry)(); 37 | } builtInFunctionTable[] = { 38 | "atascii", atasciiBIF, /* 0 */ 39 | "atasciiColor", atasciiColorBIF, /* 1 */ 40 | "isAbsoluteValue", isAbsoluteValueBIF, /* 2 */ 41 | "isConditionCode", isConditionCodeBIF, /* 3 */ 42 | "isDefined", isDefinedBIF, /* 4 */ 43 | "isExternal", isExternalBIF, /* 5 */ 44 | "nthChar", nthCharBIF, /* 6 */ 45 | "printf", printfBIF, /* 7 */ 46 | "strcat", strcatBIF, /* 8 */ 47 | "strcmp", strcmpBIF, /* 9 */ 48 | "strcmplc", strcmplcBIF, /* 10 */ 49 | "strlen", strlenBIF, /* 11 */ 50 | "substr", substrBIF, /* 12 */ 51 | "symbolLookup", symbolLookupBIF, /* 13 */ 52 | "symbolName", symbolNameBIF, /* 14 */ 53 | NULL, NULL, 54 | }; 55 | -------------------------------------------------------------------------------- /slinky/slinkyTables.h: -------------------------------------------------------------------------------- 1 | #ifndef SLINKY_TABLES_H_ 2 | #define SLINKY_TABLES_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /slinky/write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | write.c -- Routines to write out the eventual object module for the 24 | Slinky linker 25 | 26 | Chip Morningstar -- Lucasfilm Ltd. 27 | 28 | 19-March-1985 29 | */ 30 | 31 | #include "slinkyTypes.h" 32 | #include "slinkyGlobals.h" 33 | #include "write.h" 34 | 35 | #define writeWord(aWord) putc(aWord & 0xFF, loadFileOutput);\ 36 | putc((aWord >> 8) & 0xFF, loadFileOutput) 37 | #define writeByte(aByte) putc(aByte & 0xFF, loadFileOutput) 38 | 39 | void 40 | writeEntryPoint(void) 41 | { 42 | writeWord(entryPointAddress); 43 | writeWord(entryPointAddress); 44 | writeByte(0); 45 | } 46 | 47 | void 48 | writeCodeSegment(codeSegmentHeaderType *codeSegment) 49 | { 50 | int length; 51 | int i; 52 | 53 | writeWord(codeSegment->segmentStartAddress); 54 | writeWord(codeSegment->segmentEndAddress); 55 | length = codeSegment->segmentEndAddress - codeSegment-> 56 | segmentStartAddress + 1; 57 | for (i=0; isegmentCodeBuffer[i]); 59 | } 60 | 61 | void 62 | writem(void) 63 | { 64 | int regionNumber; 65 | codeSegmentHeaderType *lastSegment; 66 | segmentListType *segment; 67 | 68 | writeWord(0xFFFF); 69 | if (haveEntryPoint) 70 | writeEntryPoint(); 71 | lastSegment = NULL; 72 | for (regionNumber = 0; regionNumber < CODE_REGIONS_IN_ADDRESS_SPACE; 73 | regionNumber++) { 74 | for (segment = generatedLoadImage[regionNumber]; segment != 75 | NULL; segment = segment->nextSegment) { 76 | if (segment->thisSegment != lastSegment) 77 | writeCodeSegment(lastSegment = segment-> 78 | thisSegment); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /slinky/write.h: -------------------------------------------------------------------------------- 1 | #ifndef WRITE_H_ 2 | #define WRITE_H_ 3 | 4 | #include "slinkyTypes.h" 5 | 6 | void writeEntryPoint(void); 7 | void writeCodeSegment(codeSegmentHeaderType *codeSegment); 8 | void writem(void); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /slinkyExpressions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | slinkyExpressions.h -- Expression definitions for the Slinky linker 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 6-November-1985 28 | */ 29 | 30 | /* 31 | Expressions are stored in the object file in a compact parse-tree 32 | representation. We just read this directly and interpret it on-the-fly 33 | without much sophistication. Function definitions include whole 34 | statements, but the principle is the same. 35 | 36 | The basic form of a syntactic entity is: 37 | +---------+-------------+ 38 | | tagByte | bodyOfThing | 39 | +---------+-------------+ 40 | where 'tabByte' encodes how 'bodyOfThing' is to be interpreted. 41 | 42 | These are the possible 'thing's, as encoded by the 'tagByte's 43 | +------+ 44 | identifier: | sym# | 'sym#' is an index into the symbol entries 45 | +------+ of the object file when the expression is 46 | in the object file too, and then 'sym#' is converted 47 | to a pointer to symbol structure when the symbol 48 | itself is read in. 49 | +-------+-------+------+------+-----+ 50 | functionCall: | func# | argCt | expr | expr | ... | 'argCt' is a 51 | +-------+-------+------+------+-----+ single byte 52 | argument count (which means that a function may have 53 | no more than 255 arguments if it is to be used 54 | externally) and this is how many 'expr's there are. 55 | +-----+ 56 | number: | num | 'num' is just a 4-byte number. 57 | +-----+ 58 | +----+ 59 | conditionCode: | cc | 'cc' is a single byte condition code. 60 | +----+ 61 | +------+ 62 | subexpression: | expr | 63 | +------+ 64 | +----+------+ 65 | unop: | op | expr | 'op' is a 1-byte operation number. 66 | +----+------+ 67 | +----+------+------+ 68 | binop: | op | expr | expr | 69 | +----+------+------+ 70 | +----+------+ 71 | preop: | op | expr | 72 | +----+------+ 73 | +----+------+ 74 | postop: | op | expr | 75 | +----+------+ 76 | 77 | here: empty body. 78 | 79 | +---+---+---+---+-----+----+ 80 | string: | a | b | c | d | ... | \0 | Typical 'C' string. 81 | +---+---+---+---+-----+----+ 82 | +------+------+ 83 | array: | sym# | expr | 84 | +------+------+ 85 | +-----+ 86 | value: | num | 87 | +-----+ 88 | 89 | null: empty body. Encodes null expression *or* statement. 90 | 91 | +-------+-------+-----+-----+ 92 | block: | thing | thing | ... | end | 'end' acts as a 93 | +-------+-------+-----+-----+ termination symbol. 94 | +------+------+ 95 | mdefine: | sym# | expr | 'expr' can be null. 96 | +------+------+ 97 | +------+------+ 98 | mvar: | sym# | expr | 'expr' can be null. 99 | +------+------+ 100 | +------+-------+-------+ 101 | mif: | expr | block | block | either 'block' can be null. 102 | +------+-------+-------+ 103 | +------+------+------+-------+ 104 | mfor: | expr | expr | expr | block | 105 | +------+------+------+-------+ 106 | +------+-------+ 107 | mwhile: | expr | block | 108 | +------+-------+ 109 | +------+-------+ 110 | mdoWhile: | expr | block | 111 | +------+-------+ 112 | +------+-------+ 113 | mdoUntil: | expr | block | 114 | +------+-------+ 115 | +------+ 116 | freturn: | expr | 117 | +------+ 118 | +------+ 119 | perform: | expr | 120 | +------+ 121 | +-------+ 122 | group: | block | 123 | +-------+ 124 | +------+--------+ 125 | assert: | expr | string | 126 | +------+--------+ 127 | +------+--------+--------+-----+-----+ 128 | mswitch: | expr | clause | clause | ... | end | 129 | +------+--------+--------+-----+-----+ 130 | +------+------+-----+-------+ 131 | clause: | expr | expr | ... | block | 132 | +------+------+-----+-------+ 133 | 134 | end: empty body. 135 | 136 | */ 137 | 138 | #define IDENTIFIER_TAG 0x00 139 | #define FUNCTION_CALL_TAG 0x01 140 | #define NUMBER_TAG 0x02 141 | #define CONDITION_CODE_TAG 0x03 142 | #define SUBEXPRESSION_TAG 0x04 143 | #define UNOP_TAG 0x05 144 | #define BINOP_TAG 0x06 145 | #define PREOP_TAG 0x07 146 | #define POSTOP_TAG 0x08 147 | #define HERE_TAG 0x09 148 | #define STRING_TAG 0x0A 149 | #define ARRAY_TAG 0x0B 150 | #define VALUE_TAG 0x0C 151 | #define NULL_TAG 0x0D 152 | #define BLOCK_TAG 0x0E 153 | #define MDEFINE_TAG 0x0F 154 | #define MVARIABLE_TAG 0x10 155 | #define MIF_TAG 0x11 156 | #define MFOR_TAG 0x12 157 | #define MWHILE_TAG 0x13 158 | #define MDOWHILE_TAG 0x14 159 | #define MDOUNTIL_TAG 0x15 160 | #define PERFORM_TAG 0x16 161 | #define GROUP_TAG 0x17 162 | #define ASSERT_TAG 0x18 163 | #define MSWITCH_TAG 0x19 164 | #define CLAUSE_TAG 0x1A 165 | #define END_TAG 0x1B 166 | #define FRETURN_TAG 0x1C 167 | #define BUILTIN_FUNCTION_CALL_TAG 0x1D 168 | #define RELOCATABLE_TAG 0x1E 169 | -------------------------------------------------------------------------------- /statementSemantics.h: -------------------------------------------------------------------------------- 1 | #ifndef STATEMENT_SEMANTICS_H_ 2 | #define STATEMENT_SEMANTICS_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | void assembleBlock(blockType *block); 7 | simpleFixupListType *assembleBlockInsideIf(blockType *block, simpleFixupListType *ongoingFixupList); 8 | bool operandCheck(opcodeTableEntryType *opcode, int numberOfOperands, valueType **evaluatedOperands); 9 | void assembleMachineInstruction(opcodeTableEntryType *opcode, operandListType *operands); 10 | void assembleMacro(macroTableEntryType *macroInstruction, operandListType *operands); 11 | void assembleAlignStatement(alignStatementBodyType *alignStatement); 12 | void assembleAssertStatement(assertStatementBodyType *assertStatement); 13 | void assembleBlockStatement(blockStatementBodyType *blockStatement); 14 | void assembleByteStatement(byteStatementBodyType *byteStatement); 15 | void assembleConstrainStatement(constrainStatementBodyType *constrainStatement); 16 | void assembleDbyteStatement(dbyteStatementBodyType *dbyteStatement); 17 | void assembleDefineStatement(defineStatementBodyType *defineStatement); 18 | void assembleDoUntilStatement(doUntilStatementBodyType *doUntilStatement); 19 | void assembleDoWhileStatement(doWhileStatementBodyType *doWhileStatement); 20 | void assembleExternStatement(externStatementBodyType *externStatement); 21 | void assembleFreturnStatement(freturnStatementBodyType *freturnStatement); 22 | void assembleFunctionStatement(functionStatementBodyType *functionStatement); 23 | void assembleGroupStatement(blockType *groupStatement); 24 | simpleFixupListType *assembleIfStatement(ifStatementBodyType *ifStatement, bool terminalIf, simpleFixupListType *ongoingFixupList); 25 | void assembleIfStatementOldStyle(ifStatementBodyType *ifStatement); 26 | void assembleIncludeStatement(includeStatementBodyType *includeStatement); 27 | void assembleInstructionStatement(instructionStatementBodyType *instructionStatement, int cumulativeLineNumber); 28 | void assembleLongStatement(longStatementBodyType *longStatement); 29 | void assembleMacroStatement(macroStatementBodyType *macroStatement); 30 | void assembleMdefineStatement(defineStatementBodyType *mdefineStatement); 31 | void assembleMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement); 32 | void assembleMdoWhileStatement(mdoWhileStatementBodyType *mdoWhileStatement); 33 | void assembleMforStatement(mforStatementBodyType *mforStatement); 34 | void assembleMifStatement(mifStatementBodyType *mifStatement, int cumulativeLineNumber); 35 | void assembleMswitchStatement(mswitchStatementBodyType *mswitchStatement); 36 | void assembleMvariableStatement(mvariableStatementBodyType *mvariableStatement); 37 | void assembleMwhileStatement(mwhileStatementBodyType *mwhileStatement); 38 | void assembleOrgStatement(orgStatementBodyType *orgStatement); 39 | void assemblePerformStatement(performStatementBodyType *performStatement); 40 | void assembleRelStatement(relStatementBodyType *relStatement); 41 | void assembleStartStatement(startStatementBodyType *startStatement); 42 | void assembleStringStatement(stringStatementBodyType *stringStatement); 43 | void assembleStructStatement(structStatementBodyType *structStatement); 44 | void assembleTargetStatement(targetStatementBodyType *targetStatement); 45 | void assembleUndefineStatement(undefineStatementBodyType *undefineStatement); 46 | void assembleVariableStatement(variableStatementBodyType *variableStatement); 47 | void assembleWhileStatement(whileStatementBodyType *whileStatement); 48 | void assembleWordStatement(wordStatementBodyType *wordStatement); 49 | void assembleLabelList(labelListType *labelList); 50 | simpleFixupListType *assembleStatement(statementType *statement, bool insideIf, simpleFixupListType *ongoingFixupList); 51 | bool assembleStatementBody(statementKindType kind, statementBodyType body, int cumulativeLineNumber, bool worryAboutIf, simpleFixupListType **ifFixupList); 52 | void eatStatement(statementType *statement); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /structSemantics.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | structSemantics.c -- Routines to handle struct's for Macross assembler 24 | 25 | Chip Morningstar -- Lucasfilm Ltd. 26 | 27 | 7-December-1984 28 | */ 29 | 30 | #include "macrossTypes.h" 31 | #include "macrossGlobals.h" 32 | #include "emitStuff.h" 33 | #include "errorStuff.h" 34 | #include "listing.h" 35 | #include "parserMisc.h" 36 | #include "semanticMisc.h" 37 | #include "statementSemantics.h" 38 | #include "structSemantics.h" 39 | 40 | void 41 | putStructFixups(int base, fixupListType *fixups) 42 | { 43 | fixupListType *newFixup; 44 | 45 | while (fixups != NULL) { 46 | newFixup = typeAlloc(fixupListType); 47 | newFixup->locationToFixup = base + fixups->locationToFixup; 48 | newFixup->kindOfFixup = fixups->kindOfFixup; 49 | newFixup->theFixupExpression = fixups->theFixupExpression; 50 | if (structNestingDepth == 0) { 51 | newFixup->nextFixup = fixupList; 52 | fixupList = newFixup; 53 | } else { 54 | newFixup->nextFixup = newStruct->structFixups; 55 | newStruct->structFixups = newFixup; 56 | } 57 | fixups = fixups->nextFixup; 58 | } 59 | } 60 | 61 | void 62 | putStructReferences(int base, expressionReferenceListType *references) 63 | { 64 | expressionReferenceListType *newReference; 65 | int currentMode; 66 | 67 | if (!produceLinkableObject) 68 | return; 69 | 70 | currentMode = structNestingDepth==0 ? (int)currentCodeMode : 71 | STRUCT_BUFFER; 72 | while (references != NULL) { 73 | newReference = typeAlloc(expressionReferenceListType); 74 | newReference->relocation = references->relocation; 75 | newReference->relocation.referenceAddress += base; 76 | newReference->expressionReferenced = references-> 77 | expressionReferenced; 78 | newReference->nextReference = expressionReferenceList[ 79 | currentMode]; 80 | expressionReferenceList[currentMode] = newReference; 81 | references = references->nextReference; 82 | } 83 | } 84 | 85 | void 86 | instantiateStruct(structStatementBodyType *structStatement) 87 | { 88 | int i; 89 | int base; 90 | symbolInContextType *context; 91 | 92 | #define structInstance ((structInstanceType *) context->value->value) 93 | 94 | context = getWorkingContext(structStatement->structName); 95 | if (context == NULL) 96 | botch("struct doesn't have working context\n"); 97 | if (context->usage != STRUCT_NAME_SYMBOL) { 98 | error(NOT_A_STRUCT_NAME_ERROR, structStatement->structName-> 99 | symbolName); 100 | } else if (context->value->kindOfValue != STRUCT_VALUE) { 101 | botch("struct name doesn't have struct value\n"); 102 | } else { 103 | expand((moreText("struct\t%s", structStatement->structName-> 104 | symbolName), endLine())); 105 | base = structNestingDepth==0 ? currentLocationCounter.value : 106 | currentFieldOffset; 107 | for (i=0; istructSize; i++) 108 | emitByte(structInstance->structMap[i]); 109 | putStructFixups(base, structInstance->structFixups); 110 | putStructReferences(base, structInstance->structReferences); 111 | } 112 | } 113 | 114 | structInstanceType * 115 | assembleStructDefinitionBody(structBodyType *structBody) 116 | { 117 | int i; 118 | simpleFixupListType *dummy; 119 | 120 | newStruct = typeAlloc(structInstanceType); 121 | newStruct->structFixups = NULL; 122 | currentFieldOffset = 0; 123 | while (structBody != NULL) { 124 | expand(listableStatement(structBody->kindOfStatement) ? 125 | startLine() : 0); 126 | assembleLabelList(structBody->labels); 127 | expand(listableStatement(structBody->kindOfStatement) ? 128 | (expandLabel(), tabIndent()) : 0); 129 | assembleStatementBody(structBody->kindOfStatement, 130 | structBody->statementBody, 0 /* random guess */, FALSE, &dummy); 131 | if (currentFieldOffset > MAXIMUM_ALLOWED_STRUCT_SIZE) { 132 | error(STRUCT_TOO_BIG_ERROR); 133 | return(NULL); 134 | } 135 | structBody = (blockType *)structBody->nextStatement; 136 | } 137 | newStruct->structSize = currentFieldOffset; 138 | newStruct->structMap = (byte *)malloc(currentFieldOffset); 139 | newStruct->structReferences = expressionReferenceList[STRUCT_BUFFER]; 140 | for (i=0; istructMap[i] = structScratchBuffer[i]; 142 | return(newStruct); 143 | } 144 | 145 | void 146 | assembleStructDefinition(structStatementBodyType *structStatement) 147 | { 148 | symbolTableEntryType *name; 149 | symbolInContextType *context; 150 | 151 | name = effectiveSymbol(structStatement->structName, &context); 152 | if (context == NULL) 153 | botch("struct definition doesn't have working context\n"); 154 | if (context->usage != STRUCT_NAME_SYMBOL) 155 | error(NOT_A_STRUCT_NAME_ERROR, structStatement->structName-> 156 | symbolName); 157 | else if (structNestingDepth > 0) 158 | error(STRUCT_DEFINITION_INSIDE_STRUCT_DEFINITION_ERROR); 159 | else { 160 | structNestingDepth++; 161 | expressionReferenceList[STRUCT_BUFFER] = NULL; 162 | numberOfReferencesInList[STRUCT_BUFFER] = 0; 163 | context->value->kindOfValue = STRUCT_VALUE; 164 | expand((moreText("struct {"), endLine(), tabCount++)); 165 | context->value->value = (int) 166 | assembleStructDefinitionBody(structStatement->structBody); 167 | expand((tabCount--, startLineMarked(), tabIndent(), 168 | moreText("} %s", symbName(structStatement-> 169 | structName)), endLine())); 170 | context->environmentNumber = GLOBAL_ENVIRONMENT_NUMBER; 171 | structNestingDepth--; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /structSemantics.h: -------------------------------------------------------------------------------- 1 | #ifndef STRUCT_SEMANTICS_H_ 2 | #define STRUCT_SEMANTICS_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | void putStructFixups(int base, fixupListType *fixups); 7 | void putStructReferences(int base, expressionReferenceListType *references); 8 | void instantiateStruct(structStatementBodyType *structStatement); 9 | structInstanceType *assembleStructDefinitionBody(structBodyType *structBody); 10 | void assembleStructDefinition(structStatementBodyType *structStatement); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /tokenStrings.h: -------------------------------------------------------------------------------- 1 | #ifndef TOKEN_STRINGS_6502_H_ 2 | #define TOKEN_STRINGS_6502_H_ 3 | 4 | #include "macrossTypes.h" 5 | 6 | char *conditionString(conditionType condition); 7 | char *tokenString(int token); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /tokenStrings_6502.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | tokenStrings_6502.c -- Target processor dependent string generators 24 | for the Macross assembler (6502 version). 25 | 26 | Chip Morningstar -- Lucasfilm Ltd. 27 | 28 | 23-April-1985 29 | 30 | */ 31 | 32 | #include "macrossTypes.h" 33 | #include "macrossGlobals.h" 34 | 35 | /* conditionString similarly deals with condition codes */ 36 | char * 37 | conditionString(conditionType condition) 38 | { 39 | /* This table MUST be maintained congruently with the definition of the 40 | enumerated type 'conditionType' */ 41 | 42 | static char *conditionStringTable[] = { 43 | "(carry)", 44 | "(zero)", 45 | "(minus)", 46 | "(overflow)", 47 | "(lt)", 48 | "(leq)", 49 | "(slt)", 50 | "(sleq)", 51 | "(always)", 52 | "(!carry)", 53 | "(!zero)", 54 | "(plus)", 55 | "(!overflow)", 56 | "(geq)", 57 | "(gt)", 58 | "(sgeq)", 59 | "(sgt)", 60 | "(never)", 61 | }; 62 | return(conditionStringTable[(int)condition]); 63 | } 64 | 65 | 66 | /* tokenString similarly deals with parser tokens */ 67 | 68 | char * 69 | tokenString(int token) 70 | { 71 | /* This table MUST be maintained congruently with the token definitions in 72 | the file 'y.tab.h' as output by yacc. */ 73 | 74 | static char *tokenTable[] = { 75 | "A", 76 | "ALIGN", 77 | "ASSERT", 78 | "BLOCK", 79 | "BYTE", 80 | "CONSTRAIN", 81 | "DBYTE", 82 | "DEFINE", 83 | "DO", 84 | "ELSE", 85 | "ELSEIF", 86 | "ENDFILE", 87 | "EOL", 88 | "EXTERN", 89 | "FRETURN", 90 | "FUNCTION", 91 | "HERE", 92 | "IF", 93 | "INCLUDE", 94 | "LONG", 95 | "MACRO", 96 | "MCASE", 97 | "MDEFAULT", 98 | "MDEFINE", 99 | "MDO", 100 | "MELSE", 101 | "MELSEIF", 102 | "MFOR", 103 | "MIF", 104 | "MSWITCH", 105 | "MUNTIL", 106 | "MVARIABLE", 107 | "MWHILE", 108 | "ORG", 109 | "REL", 110 | "START", 111 | "STRING", 112 | "STRUCT", 113 | "TARGET", 114 | "UNDEFINE", 115 | "UNTIL", 116 | "VARIABLE", 117 | "WHILE", 118 | "WORD", 119 | "X", 120 | "Y", 121 | "ConditionCode", 122 | "Identifier", 123 | "MacroName", 124 | "Number", 125 | "Opcode", 126 | "TextString", 127 | "Assignment", 128 | "||", 129 | "^^", 130 | "&&", 131 | "|", 132 | "^", 133 | "&", 134 | "==", 135 | "!=", 136 | "<", 137 | "<=", 138 | ">", 139 | ">=", 140 | "<<", 141 | ">>", 142 | "+", 143 | "-", 144 | "*", 145 | "/", 146 | "%", 147 | "-", 148 | "!", 149 | "~", 150 | "?", 151 | "/", 152 | ".", 153 | "++", 154 | "--", 155 | }; 156 | return(tokenTable[token-257]); 157 | } 158 | -------------------------------------------------------------------------------- /tokenStrings_68000.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1987 Fujitsu 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | /* 23 | tokenStrings_68000.c -- Target processor dependent string generators 24 | for the Macross assembler (68000 version). 25 | 26 | Chip Morningstar -- Lucasfilm Ltd. 27 | 28 | 26-April-1985 29 | 30 | */ 31 | 32 | #include "macrossTypes.h" 33 | #include "macrossGlobals.h" 34 | 35 | /* conditionString similarly deals with condition codes */ 36 | char * 37 | conditionString(condition) 38 | conditionType condition; 39 | { 40 | /* This table MUST be maintained congruently with the definition of the 41 | enumerated type 'conditionType' */ 42 | 43 | static char *conditionStringTable[] = { 44 | "(carry)", 45 | "(equal)", 46 | "(overflow)", 47 | "(minus)", 48 | "(lt)", 49 | "(leq)", 50 | "(ls)", 51 | "(always)", 52 | "(!carry)", 53 | "(!equal)", 54 | "(!overflow)", 55 | "(plus)", 56 | "(geq)", 57 | "(gt)", 58 | "(high)", 59 | "(never)", 60 | }; 61 | return(conditionStringTable[(int)condition]); 62 | } 63 | 64 | 65 | /* tokenString similarly deals with parser tokens */ 66 | 67 | char * 68 | tokenString(token) 69 | int token; 70 | { 71 | /* This table MUST be maintained congruently with the token definitions in 72 | the file 'y.tab.h' as output by yacc. */ 73 | 74 | static char *tokenTable[] = { 75 | "A0", 76 | "A1", 77 | "A2", 78 | "A3", 79 | "A4", 80 | "A5", 81 | "A6", 82 | "A7", 83 | "ALIGN", 84 | "ASSERT", 85 | "BLOCK", 86 | "BYTE", 87 | "CCR", 88 | "CONSTRAIN", 89 | "D0", 90 | "D1", 91 | "D2", 92 | "D3", 93 | "D4", 94 | "D5", 95 | "D6", 96 | "D7", 97 | "DBYTE", 98 | "DEFINE", 99 | "DFC", 100 | "DO", 101 | "ELSE", 102 | "ELSEIF", 103 | "ENDFILE", 104 | "EOL", 105 | "EXTERN", 106 | "FRETURN", 107 | "FUNCTION", 108 | "HERE", 109 | "IF", 110 | "INCLUDE", 111 | "L", 112 | "LONG", 113 | "MACRO", 114 | "MCASE", 115 | "MDEFAULT", 116 | "MDEFINE", 117 | "MDO", 118 | "MELSE", 119 | "MELSEIF", 120 | "MFOR", 121 | "MIF", 122 | "MSWITCH", 123 | "MUNTIL", 124 | "MVARIABLE", 125 | "MWHILE", 126 | "ORG", 127 | "PC", 128 | "REL", 129 | "SFC", 130 | "SR", 131 | "START", 132 | "STRING", 133 | "STRUCT", 134 | "TARGET", 135 | "UNDEFINE", 136 | "UNTIL", 137 | "USP", 138 | "VARIABLE", 139 | "VBR", 140 | "W", 141 | "WHILE", 142 | "WORD", 143 | "X", 144 | "Y", 145 | "ConditionCode", 146 | "Identifier", 147 | "MacroName", 148 | "Number", 149 | "Opcode", 150 | "TextString", 151 | "Assignment", 152 | "||", 153 | "^^", 154 | "&&", 155 | "|", 156 | "^", 157 | "&", 158 | "==", 159 | "!=", 160 | "<", 161 | "<=", 162 | ">", 163 | ">=", 164 | "<<", 165 | ">>", 166 | "+", 167 | "-", 168 | "*", 169 | "/", 170 | "%", 171 | "-", 172 | "!", 173 | "~", 174 | "?", 175 | "/", 176 | ".", 177 | "++", 178 | "--", 179 | }; 180 | return(tokenTable[token-257]); 181 | } 182 | --------------------------------------------------------------------------------