*-----------------------------------------------------------
Title[DMesaVersion.mc...May 11, 1984  4:16 PM...Willie-Sue];
* Microcode version number declaration and VERSION opcode
*-----------------------------------------------------------

*-----------------------------------------------------------
Macro[DefineVersion,
* Major version number; increment only when incompatible changes are
* made to the instruction set.  This requires coordination among all
* microcode implementations and all software that uses them.
  Set[VersionNumber, 0]

* Release date; change whenever a new change is made, however trivial.
  MakeYear[124]		* 84
  MakeMonth[5]		* May
  MakeDay[16]];		* ???
*-----------------------------------------------------------


% Macros to encode information for the VERSION opcode.

  MachineType: TYPE = MACHINE DEPENDENT {
    altoI (1), altoII (2), altoIIXM (3), dolphin (4), dorado (5), dandelion (6),
    dicentra (7), (17B)};

  VersionResult: TYPE = MACHINE DEPENDENT RECORD [
    machineType (0: 0..3): MachineType,
    majorVersion (0: 4..7): [0..17B],  -- incremented by incompatible changes
    unused (0: 8..13): [0..77B],
    floatingPoint (0: 14..14): BOOLEAN,
    cedar (0: 15..15): BOOLEAN,
    releaseDate (1): CARDINAL];  -- days since January 1, 1901

For the macros below, 1904, 1908, ..., 1980, 1984, etc. are leap years.
So 1 January 1982 is 81*365 + 19 days = 29584 days (=71620b) after
1 January 1901; 365d = 555b.
%

Macro[MakeYear, Set[YearOffset,
	Add[71620,Select[Sub[#1,122],0,555,1332,2110,2665,3442,4217,4775]]]
	Set[LeapOffset,Select[Sub[#1,122],0,0,1,0,0,0,1,0]]
];

Macro[MakeDay, Set[DayOffset,Sub[#1,1]]];

Macro[MakeMonth, Set[MonthOffset,
	IFG[#1,6,Select[Sub[#1,7],265,324,363,421,460,516],
		Select[Sub[#1,1],0,37,73,132,170,227]]]
	IFG[MonthOffset,72,Set[MonthOffset,Add[LeapOffset,MonthOffset]]]
];

DefineVersion[];
MC[VersionFlags,
  Add[50000,
    LShift[VersionNumber, 10],
    * Cedar is always present
    * Presence of floating point is determined dynamically
  ]];
MC[ReleaseDate, Add[YearOffset, MonthOffset, DayOffset]];

Set[XTask, IP[EMU]];
TopLevel;

*-----------------------------------------------------------
VersionM: MiscTable[104],
* Push[VersionFlags]; Push[ReleaseDate];
*-----------------------------------------------------------

	Stack← VersionFlags, Call[FloatingPointPresent]; * Returns 0 or 2
:If[AltoMode];		********** Alto version **********
	Stack&+1← (Stack&+1)+T;		* B15=0: Cedar never present
:Else;			******** PrincOps version ********
	Stack&+1← (Stack&+1)+T+1;	* B15=1: Cedar always present
:EndIf;			**********************************
	Stack← HighByte[ReleaseDate];
	StackT← (StackT) OR (LowByte[ReleaseDate]), IFUNext2;