-- TriArith.mesa; arithmetic, bitblttery, Random, & fast triangles
-- Bill Gosper, October 4, 1979 7:12 PM
DIRECTORY
AltoDisplay:FROM "AltoDisplay",
BitBltDefs:FROM "BitBltDefs",
InlineDefs:FROM "InlineDefs";
TriArith: DEFINITIONS IMPORTS InlineDefs =
BEGIN
OPEN AltoDisplay, InlineDefs;
ScreenPt:TYPE = RECORD [x: CARDINAL--[0..fullX]--,
y: CARDINAL--[0..fullY]--];--dawk
LongPair:TYPE = RECORD [LONG UNSPECIFIED, LONG UNSPECIFIED];
LONGNUMBER:TYPE = MACHINE DEPENDENT RECORD [
SELECT OVERLAID * FROM
li=> [li: LONG INTEGER],
lc=> [lc: LONG CARDINAL],
num=> [lobits: CARDINAL,
hibits: SELECT OVERLAID * FROM
i=> [i: INTEGER],
c=> [c: CARDINAL],
ENDCASE],
ENDCASE];
one: INTEGER = LAST[INTEGER]/2 + 1;
hi1: READONLY LONG INTEGER-- = LONG[LAST[CARDINAL]] + 1 --;
longOne: READONLY LONG INTEGER-- = one*hi1 --;--dawk!
fullX, fullY, midX, midY: CARDINAL;
bbptr: BitBltDefs.BBptr;
stepping: BOOLEAN;
multiplier, offset, randum1, randum2: CARDINAL;
-- modulus = 2↑wordLength
DIV: PROCEDURE[num: LONG INTEGER, den: CARDINAL]
RETURNS[quo: INTEGER, rem: CARDINAL] = INLINE
BEGIN
[quo, rem] ← LongDivMod[ABS[num], den];
IF num < 0 THEN IF rem = 0 THEN RETURN[-quo, 0] ELSE
RETURN[BITNOT[quo], den - rem] END;
LICDiv: PROCEDURE[num: LONG INTEGER, den: CARDINAL] RETURNS[LONG INTEGER];
LIIDiv: PROCEDURE[num: LONG INTEGER, den: INTEGER] RETURNS[LONG INTEGER];
LFracDiv: PROCEDURE[num: LONG INTEGER, den: INTEGER] RETURNS[LONG INTEGER];
SIN: PROCEDURE[x: LONG INTEGER] RETURNS[s: LONG INTEGER];
CSQRT: PROCEDURE[x: LONG CARDINAL] RETURNS[app: CARDINAL];
ICLongMult: PROCEDURE[x: INTEGER, y: CARDINAL] RETURNS[LONG INTEGER] = INLINE
BEGIN
RETURN[IF x < 0 THEN -LongMult[-x, y] ELSE LongMult[x, y]]
END;
ILongMult: PROCEDURE[x, y: INTEGER] RETURNS[LONG INTEGER] = INLINE
BEGIN
RETURN[IF BITXOR[x, y] < 0 THEN -LongMult[ABS[x], ABS[y]] ELSE
LongMult[ABS[x], ABS[y]]]
END;
LIILongMult: PROCEDURE[x: LONG INTEGER, y: INTEGER] RETURNS[LONG INTEGER];
--LLFracMul: PROCEDURE[x, y: LONG INTEGER] RETURNS[LONG INTEGER] = INLINE
--BEGIN
x ← ILongMult[HighHalf[x], HighHalf[y]]
--+ LONG[INTEGER[HighHalf[ICLongMult[HighHalf[x], LowHalf[y]]]]]
--
+ LONG[INTEGER[HighHalf[ICLongMult[HighHalf[y], LowHalf[x]]]]];
--
x ← x + x; RETURN[x + x]
--END;
LLFracMul: PROCEDURE[x, y: LONG INTEGER] RETURNS[LONG INTEGER];
LL4Mul: PROCEDURE[x, y: LONG INTEGER] RETURNS[LONG INTEGER];
--LFracMul: PROCEDURE[x: LONG INTEGER, y:INTEGER] RETURNS[LONG INTEGER]=INLINE
--BEGIN
x ← ILongMult[HighHalf[x], y]
--+ LONG[INTEGER[HighHalf[ICLongMult[y, LowHalf[x]]]]];
--
x ← x + x; RETURN[x + x]
--END;
-- *4 to make ...Mul[...one, one] = ...one
LFracMul: PROCEDURE[x: LONG INTEGER, y:INTEGER] RETURNS[LONG INTEGER];
--FracMul: PROCEDURE[x, y: INTEGER] RETURNS[INTEGER] = INLINE
--BEGIN
r: LONG INTEGER ← ILongMult[x, y]; r ← r + r; RETURN[HighHalf[r + r]]
--END;
FracMul: PROCEDURE[x, y: INTEGER] RETURNS[INTEGER];
--FracLongMult: PROCEDURE[x, y: INTEGER] RETURNS[LONG INTEGER];
LCM: PROCEDURE[a, b: CARDINAL] RETURNS[LONG CARDINAL];
Init:
PROCEDURE;
InitDisplay: PROCEDURE;
InitRandom: PROCEDURE[mult,add: CARDINAL];
Randm1: PROCEDURE[m: CARDINAL] RETURNS[CARDINAL];
Randm2: PROCEDURE[m: CARDINAL] RETURNS[CARDINAL];
DrawTri: PROCEDURE[p1, p2, p3: ScreenPt];
Finish: PROCEDURE;
END.