-- BltImpl.mesa
-- Last changed by Doug Wyatt, September 30, 1980 3:22 PM

DIRECTORY
Blt,
Memory USING [mds, long],
BitBltDefs USING [BBptr, BBTableSpace, AlignedBBTable, BITBLT],
InlineDefs USING [HighHalf, LowHalf];

BltImpl: PROGRAM
IMPORTS Memory,BitBltDefs,InlineDefs
EXPORTS Blt SHARES Blt = {
OPEN Blt;

mds: MDSZone = Memory.mds;

New: PUBLIC PROCEDURE[base: LONG POINTER, raster: CARDINAL]
RETURNS[Handle] = {
d: Handle=mds.NEW[Data ← [
bbt: NIL, grays: ALL[0], sdx: 0, sdy: 0,
space: ALL[0]
]];
bbt: BBptr=(d.bbt←BitBltDefs.AlignedBBTable[@d.space]);
bbt↑ ← [
ptrs: IF Memory.long THEN long ELSE short,
pad: 0, destalt: FALSE, sourcealt: FALSE, unused: 0,
sourcetype: gray, function: replace,
dw: 0, dh: 0, dlx: 0, dty: 0, slx: 0, sty: 0,
dbca: NIL, sbca: NIL, dbmr: 0, sbmr: 0,
gray0: 0, gray1: 0, gray2: 0, gray3: 0,
dlbca: NIL, slbca: NIL
];
IF Memory.long THEN bbt.dlbca←base
ELSE {
bh: CARDINAL=InlineDefs.HighHalf[base];
bl: POINTER=InlineDefs.LowHalf[base];
bbt.dbca←bl; IF bh#0 THEN { bbt.destalt←TRUE; bbt.unused←bh };
};
bbt.dbmr←raster;
RETURN[d];
};

Source: PUBLIC PROC[d: Handle,
base: LONG POINTER, raster: CARDINAL] = {
bbt: BBptr=d.bbt;
IF Memory.long THEN bbt.slbca←base
ELSE {
bh: CARDINAL=InlineDefs.HighHalf[base];
bl: POINTER=InlineDefs.LowHalf[base];
bbt.sbca←bl; IF bh#0 THEN { bbt.sourcealt←TRUE;
IF bbt.unused=0 THEN bbt.unused←bh
ELSE IF bbt.unused#bh THEN ERROR;
};
};
bbt.sbmr←raster;
};

Rect: PUBLIC PROCEDURE[d: Handle] = {
bbt: BBptr=d.bbt;
IF bbt.dw>0 AND bbt.dh>0 THEN {
y: CARDINAL=bbt.dty;
IF bbt.sourcetype#gray THEN {
bbt.slx←bbt.dlx-d.sdx; bbt.sty←y-d.sdy
};
bbt.gray0←d.grays[y MOD 4];
IF bbt.dh>1 THEN {
bbt.gray1←d.grays[(y+1) MOD 4];
bbt.gray2←d.grays[(y+2) MOD 4];
bbt.gray3←d.grays[(y+3) MOD 4];
};
BitBltDefs.BITBLT[bbt];
};
};

CFree: PUBLIC PROCEDURE[d: Handle] = {
mds.FREE[@d];
};

}.