% MICRO TEST PROGRAM %
% last edited July 7, 1980 9:12 AM %

* Test setting output extension
SETMBEXT[MT];

* Test line count of title message
ER[Micro.test.program];

M[W,];
MEMORY[SM,44,1000,SSRC,SSINK];
MEMORY[DM,44,1000,DSRC,DSINK];
MEMORY[RM,44,40,RSRC,RSINK];
MEMORY[LM,44,40,LSRC,LSINK];
MEMORY[IM,110,4000,ISRC,ISINK];
*LOCATION COUNTERS
SM[SLC,0]; DM[DLC,0]; RM[RLC,0]; LM[LLC,0]; IM[ILC,0];
LIST[IM,13];
LIST[SM,11];
LIST[DM,11];
LIST[RM,11];
LIST[LM,31];
LIST[,3];
*INSTRUCTION MEMORY FIELD DEFINITIONS
F[BT,0,1];
*BRANCH TYPE
F[BC,2,6];
*BRANCH CONDITION
F[LA,7,13];
*LEFT BANK ADDRESS
F[RA,14,20];
*RIGHT BANK ADDRESS
F[PS,21,26];
*P INPUT SELECT
F[QS,27,31];
*Q INPUT SELECT
F[AF,32,36];
*ALU FUNCTION SELECT
F[BS,37,43];
*BUS SOURCE
F[BD,44,50];
*BUS DESTINATION
F[F1,51,56];
*FUNCTION 1
F[F2,57,62];
*FUNCTION 2
F[SA,63,72];
*SCRATCH MEMORY ADDRESS
F[BA,73,105];
*BRANCH ADDRESS

*RM/LM field definitions
F[W0,0,3];
F[W1,4,23];
F[W2,24,43];

* Macros for verifying results
M[EQ?,ER[#1--SHOULD.BE--#2--IS--,0,#1]];
M[!,];
* Argument will show up on the listing

* Test subsequent definition of source and sink macros
M[SSRC,?];
M[SSINK,?];

*TEST PROGRAM
IM[ILC,20];
TARGET[ILC];
BC[5], BA[L1];
L2:
LA[3], RA[3];
L1:
BC[7], BA[L2];

* Test negative constants
M[.-2,ADD[IP[ILC],-2]];
BA[.-2];

* Test macro with lots of args
M[LOTS,ER[#0:#1#2#3/#4#5#6/#7#8#9]];
LOTS[A,B,C,D,E];
LOTS[Q,W,E,R,T,Y,U,I,O];

*TEST RPT
RPT[3,ILC[(BT[1],BA[ADD[1,IP[ILC]]])]];
* Test "value" option of ER
M[HERE,
ER[ILC=,0,IP[ILC]]
];
HERE[];

* Test arithmetic
EQ?[ADD[100,NOT[5]],72];
EQ?[OR[101,XOR[AND[33,67],32]],111];
EQ?[SUB[11,3],6];

*Test COMMENTCHAR
COMMENTCHAR[~];
*~ this should be skipped
SA[101];
*~ end of skip
SA[102];
COMMENTCHAR[];
*~ this should not be skipped
SA[103];
*~ end of not skip
SA[104];

* Test LISTFIELDS
LISTFIELDS[IM, (BC[1], AF[1], SA[1])];

* Test 16-bit listing
RLC[W0[2] W1[116273] W2[104321]];*1234 5670 4321
LLC[W0[7] W1[123456] W2[54321]];

*COMMA AND PAREN PROBLEMS?
N[Q]; N[Q←]; N[R];
M[XYZ,(LA[1])R];
M[Q←Q,F1[3]];
Q←Q,XYZ;
ZZ (![ZZ.undefined]);
N[X]; N[Z];
M[XX,(RA[1])X];
M[ZZ,(PS[1])Z];
(XX)Y(ZZ);

* TEST PREASSIGN AND SETPOST
LIST[IM,6];
SETPOST[IM,HERE];
AS:
BT[2], BT[2];
BT[2], BT[3] (![BT.already.set]);
BT[2], PF[BT,3];
PF[BT,2], BT[3];
SETPOST[IM,];
PF[BT,1], PF[BT,2];
* Check literal decomposition
M[LIT,ER[LIT(#0):#1.#2.#3]];
M[-LIT,ER[-LIT(#0):#1.#2.#3]];
123LIT;
123456LIT;
123456700LIT;
-7654321LIT;
* Check undefined literals
321K (![Undefined.literal.321.K]);
-12345K (![Undefined.literal.12345.-K]);

*CHECK LISTING MODE 4
LIST[IM,4];
BT[1];
BT[2];
BT[3];
LIST[IM,6];
AT:
BT[2];

* Test FIELDVAL
BS[FIELDVAL[BD]], BD[3];

* Test SELECT
M[SELB,SELECT[#1,1,2,4,10,20,40]];
BA[SELB[2]];
BA[SELB[3]];
BA[SELB[4]];

* Test Bravo formatting in program and comments
BA[123];
* This comment is formatted
BA[456];% So is this one %

* Test distinguishing lower and upper case
M[foo,BA[123]];
foo;* should be OK
FOO (![FOO.undefined]);

* Test bittable stuff
BITTABLE[ZOT,100];
SETBIT[ZOT,3];
EQ?[GETBIT[ZOT,3],1];
EQ?[GETBIT[ZOT,13],0];
EQ?[FINDBIT[ZOT,1,2,2,2,10],5];

* Test EQUATE
EQUATE[THERE,foo];
foo;
EQUATE[THERE,HERE];
THERE;
EQUATE[AB,BA];
AB[567];

* Test INSERT and restoring symbolic address
IN:
INSERT[MTESTREDEF];

* Test variations of ER
ER[This.is.an.error,2];
ER[This.is.a.warning,3];

* Test PROCESSMODE
:ER[Line.with.:];
PROCESSMODE[1];
ER[This.shouldn’t.appear];
:ER[This.should.appear];
:PROCESSMODE[0];
ER[So.should.this];
PROCESSMODE[2]; *Should give an error

* Test TRACEMODE
TRACEMODE[0,1]; *Enable symbol tracing
EQ?[ADD[1,2],3];
TRACEMODE[0,0];
TRACEMODE[1,1];*Enable macro tracing
EQ?[SUB[3,2],1];
TRACEMODE[1,0];

* Test WHILE
SET[MSK,1000];
SET[CNT,0];
WHILE[SUB[MSK,1],SET[MSK,RSHIFT[MSK,1]]SET[CNT,ADD[CNT,1]]];
EQ?[CNT,11];
* END
% THIS IS AN UNTERMINATED COMMENT