// P R E P R E S S -- The real thing!
//
//Bcpl/f Prepress.bcpl
//
//Command decoder and dispatcher.

//CHANGES!! - (Most recent first)

//Modified January 20, 1982 by Lyle Ramshaw:
// Changed PrepressCommands.bcpl so that point sizes would be
// correctly rounded to micas when getting parameters from the
// command line.
// Result is 2.5.

//Modified December 27, 1980 by Lyle Ramshaw:
// Added more typeout during dictionary commands: one "." per
// font processed. Also modified MergeDelete so that the new
// mica size always wins over the old during a merge, even if
// MultiChars blocks are involved. Changed IxOrdering in
// MergeDelete so that TEX fonts would be ordered more
// rationally: TEX fonts come after Xerox fonts, and are ordered
// first by logical size (=-face), and then by physical size.
// Changed storage allocation in MergeDeleteOutput so that
// writing a dictionary with the Verify flag does not demand
// that there be enough free core for an entire character.
// Result is 2.4.

//Modified December 5-10, 1980 by Lyle Ramshaw, Kerry LaPrade:
// Fixed bug in Width processor (Filops) in computation of
// font bounding box. Also fixed bug in Editor clipping of
// large charcters against the top of the editor window.
// Result is 2.3.

//Modified November 23, 1980 2:35 PM by Lyle Ramshaw:
// Installed new Trident modules and adjusted the RAM
// loading code so that Prepress can run on a Dolphin
// or Dorado with extra Tridents attached and use them
// as if they were Alto Tridents. Result is 2.2.

//Modified October 1, 1980 1:06 PM by Lyle Ramshaw:
// Changed TEX face encoding/decoding to work backwards.
// Fixed MapACtemp to follow the pointer in the IX to find
// the data segment in the input instead of assuming that
// that the data segment immediately follows the EndIX.
// Added the Verify flag to the MergeDelete commands:
// a Verified operation sorts the individual raster blocks
// within Chars, OrbitChars, and MultiChars fonts, and checks that
// the CharWidth blocks and raster blocks give consistent
// descriptions of the raster dimensions. Also fixed
// several bugs in the Area code in FEdit. Result is 2.1.

//Modified September 17, 1980 12:10 PM by Kerry LaPrade:
// Edit function now works differently for Dot Size of 1.
// Also in Edit, fixed bug so that characters which do
// not fit in the editing area are once again clipped
// more properly. Updated files: AuxiliaryMenuBox.bcpl,
// FEdit.bcpl, FEditFile.bcpl, FEditUtil.bcpl, and
// Prepress.bcpl. Result is 1.21.

//Modified September 12, 1980 5:48 PM by Lyle Ramshaw:
// changed storage allocation in MergeDelete to allow larger
// dictionaries to be merged. Also went through and made
// most of the static variables "page zero statics" to save
// space; the statics themselves don’t take up as much room,
// and the code that references them is shorter and runs
// faster. Result is 1.20.

//Modified August 18, 1980 9:56 PM by Lyle Ramshaw:
// fixed bug in MakeStrike: the Length field in the StrikeBody was
// getting computed wrong. (How is it that this wasn’t noticed
// before, I wonder..) Result is version 1.19.

//Modified July 31, 1980 11:40 AM by Lyle Ramshaw:
// fixed bug in PrepressMenu1; adjusted dictionary commands
// so that all family names are output in all caps, and with all
// all trailing bytes = 0. Result is version 1.18.

//Modified July 6, 1980 9:53 PM by Lyle Ramshaw:
// Delete was bitten by the same CompareIx problem that bugged
// Extract last October!! So I moved the Extract patch to a
// place where it fixes both problems. In passing, I also added
// a "Beginning dictionary command..." message; result
// is version 1.17.

//Modified June 25, 1980 12:42 PM by Lyle Ramshaw:
// Improved the quadratic equation solver in SCVMain; result
// is version 1.16.

//Modified June 17, 1980 3:11 PM by Lyle Ramshaw:
// Fixed bug in Show command: released version 1.15.

//Modified June 15, 1980 3:33 PM by Lyle Ramshaw:
// Added a Junta back to levDisplay, to save enough space so
// that the Edit overlay will fit for a little while longer (sigh)...
// Also installed new Trident package.

//Modified: May 22, 1980 12:43 PM by Lyle Ramshaw, PARC:
//
This version will run on Dorados emulating Altos; on
// a Dorado, the floating point is done in software and the
// Trident disk stuff is disabled.
//
The code for editing dictionaries has been redone. The
// primary new feature is the Fast mode, in which the dictionary
// is rewritten in place. Minor new features are that the index
// now appears in sorted order, and that family names with no
// associated fonts are deleted. In passing, fixed a longstanding
// bug that sometimes smashed fonts when doing Merges into
// dictionaries that contained MultiChars blocks.
//
Added the new segment type TexMetrics for use by
// the local Tex hackers; PrePress doesn’t create or modify
// such segments, but it will Merge, Extract, and Delete
// them from dictionaries.
//
Added the MakeKS and ReadKS commands that translate
// back and forth between .AC and the new kerned strike
// format, .KS. In the process, altered the MakeStrike
// command by changing the old "Kerned" flag to the new
// "Clip" flag. The MakeAL command also now pays attention
// to the "Clip" flag. "Clip" flag is settable from the
// command line with /K.
//
Changed the DecodeFace and EncodeFace definitions and
// calls to allow for a fourth letter in the face code (X, A,
// or O), and also to allow for numeric face codes (TEX logical
// sizes). For details, see the new version of "Font
// Representations and Formats."
//
Added stack space to the Trident overlay to prevent a
// fall into Swat when the requested file is not on the Trident.
//
Fixed a bug in the menu interface that caused falls into
// Swat under certain conditions, especially when several
// commands are selected before any are executed.
//
Restored the FileName/B feature for driving the
// dictionary commands from the command line.
//
Changed List so that MultiChars segments are
// distinguished from OrbitChars, and took some of the
// carriage returns out of the List output to save space.
//
Changed the overlaying structure to make overlaying
// faster. The first time that the .RUN file is started,
// PrePress will go through the file to find the starts of all of
// the overlays, and store these in the .RUN file. Subsequent
// invocations of PrePress and overlay swaps within PrePress
// will be fast, working from a table of file addresses.

//Prepress version 1.12 (incompatible with OS versions
// prior to OS 17)

//Modified April 7, 1980 12:41 PM by Kerry LaPrade, XEOS
// and Lyle Ramshaw, PARC
//
// Fixed bugs introduced in version 1.11 to Main Menu
// user interface and to writing of family names in
// dictionaries. Fixed MakeStrike to handle kerned
// characters more reasonably. Increased List capacity
// from 100 to 200 names, and changed carriage return-
// line feed sequences to simply carriage returns.
// Restored and modified command line capabilities for
// calling Edit, which first disappeared in version 1.9.
// Updated the set of device resolutions which the /D
// and /E command line switches recognize. Changed
// command line and PrepressNames.d spellings from
// Supercede to Supersede. Supersede again allows
// dictionary and/or Trident files as source files from
// the menu. Incorporated Trident microcode version of
// 1-31-80.
//
//Changed files: (added [a] updated [u] deleted [d])
// BitBlt.d [d]
// FEdit.bcpl [u]
// FEditUtil.bcpl [u]
// Filops.bcpl [u]
// PlayOut.bcpl [u]
// Prepress.bcpl [u]
// PrepressCommands.bcpl [u]
// PrepressComponents.cm [u]
// PrepressMenu1.bcpl [u]
// PrepressMenu2.bcpl [u]
// PrepressNames.d [u]
// PrepressUtil.bcpl [u]
// Scan.bcpl [u]
// TFSA.BR, TFSBase.BR, TFSClose.BR, TFSCreate.BR, TFSDDMgr.BR,
// TFSInit.BR, TFSSwat.BR, TFSWrite.BR [u]

//Modified February 7, 1980 11:55 AM by Kerry A. LaPrade, XEOS
// Sped up FEdit "Get" command for high resolution (small dot size)
// editing. Added obscure BravoX-like capability to "TypeIn"
// chars > 200b in FEdit show string box. Added toggleable
// "gnat" to update box. Increased size of show string box
// (again) necessitating transferal of some resident code to
// overlay in order to allow user to use moderately-sized
// sysFonts. Fixed bug in, and improved function of, "Cancel"
// operation.
// Decreased size of resident code by moving some stuff from
// Prepress.Bcpl to PrepressCommands.Bcpl.
// Cleaned up PrePressMenu code for smarter and more protective
// user interface. Different mouse buttons do different
// things. In general, first and second mouse buttons invoke
// standard default and third button reverts to last thing
// used. As per Lyle Ramshaw’s sugestions and instructions,
// fixed Trident drive menu specification to allow access
// to multiple directories on T-300’s. Menu boxes can no
// longer be bugged in the wrong order. User is warned
// if source file isn’t on local (sysDisk) disk.
// Fixed list bug for chars > 200b.
// Lyle Ramshaw (PARC) changed representation of blank characters
// in .AC files as produced in OrbitFormat.bcpl, and bounding
// box calculation as produced in Convert.bcpl.
// Also due to Ramshaw, Prepress documentation is now kept as
// [MAXC]<AltoSource>PrepressDocSources.DM.
// Changed point size in ReadAL from 77 to 72.
// Added measurement messages to bit manipulations
// in Edit, and "ACEdits" vs original file notification
// to "Get" command in Edit. Changed background/foreground
// ratio determination to have a plus or minus 5 mica
// tolerance in background size as opposed to plus or
// minus 1 previously.
// Changed "Incline" prompt to percentage instead of degrees.

//
//Changed files: (added [a] updated [u] deleted [d])
// CompilePrePress.cm [u]
// Convert.bcpl [u]
// FEdit.bcpl, FEditFile.bcpl, FEditUtil.bcpl [u]
// FEditLoop.bcpl [a]
// FEditNames.d [u]
// FEditTables.bcpl [u]
// Filops.bcpl [u]
// GoodFoo.d [u]
// LoadPrePress.cm [u]
// OrbitFormat.bcpl [u]
// PlayOut.bcpl [u]
// Prepress.bcpl [u]
// PrepressCommands.bcpl [a]
// PrepressComponents.cm [u]
// PrepressMenu1.bcpl [u]
// PrepressMenu2.bcpl [u]
// PrepressMenuUtil.bcpl [d]
// PrepressUtil.bcpl [u]
// PrepressTables.bcpl [u] //Made some boxes "inactive"
// ReadAL.bcpl [u]
// Rotate.bcpl [u]
// Scan.bcpl [u]
//
//Modified December 21, 1979 9:15 AM by Lyle Ramshaw, PARC
//
//Put in an OS version warning.
//Added a Notify window to the main menu, for prompt strings.
//Installed the new Trident microcode of Ed Taft.
//Fixed the Rename bug associated with ACtemp’s parameters.
//Installed the fix for the "ConvertAChar returns 14" bug (discussed below).
//Allowed Tridents other than drive zero to be accessed.
//Made ReadAL and DeOrbitize accessible from the command line.
//Improved Rotate to handle rotations by any multiple of 90 degrees:
// there is a new window in the main menu called
// "Angle" that holds the amount of rotation to be added, positive or
// negative, measured in degrees and stored in the static
// angleToRotate.
//
//Changed files: (added [a] updated [u])
// AuxiliaryMenuBox.bcpl [u]
// ReadAL.bcpl [u]
// Rotate.bcpl [u]
// Prepress.bcpl [u]
// prepressmenu1.bcpl and prepressmenu2.bcpl [u]
// prepressmenuutil.bcpl [u]
// PrepressNames.d, PrepressTables.bcpl [u] //? (LaPrade)
// SCVMain.bcpl [u]
// TFSSwat.BR [a]


//Modified December 5, 1979 12:57 PM (by LaPrade)
//
//Changed user type-in scheme to be echoed inside menu box instead
// of dsp, reducing the amount of resident code and freeing up
// room for work on FEdit overlay. Enlarged FEdit "show string"
// box. Sped up FEdit "Put" command for high resolution (small
// dot size) editing. Updated .d files to David Boggs’ 1979
// versions. Miscellaneous housekeeping.
//
//Changed files: (added [a] updated [u] deleted [d])
// AltoByteBlT.BR [a]
// AltoDefs.d [a]
// AltoFileSys.d [u]
// AuxiliaryMenuBox.bcpl, AuxiliaryMenuDefs.d [u]
// BitBlt.BR [d]
// CompilePrePress.cm [u]
// DCBPress.BR [a]
// FEdit.bcpl, FEditFile.bcpl, FEditTables.bcpl, FEditUtil.bcpl [u]
// FlipBox.bcpl [d]
// GoodFoo.d [a]
// LoadPrePress.cm [u]
// MenuKeyBoard.BR [a]
// OS.d [d]
// Prepress.bcpl [u]
// PrePressComponents.cm [a]
// PrepressMenu.bcpl [d]
// PrepressMenu1.bcpl [a], PrepressMenu2.bcpl [a]
// PrepressMenuUtil.bcpl [u]
// PrePressToIFS.cm [d]
// Scan.bcpl [u]
// SDialog.BR [d]
// Streams.d [u]
// StringStreams.BR, StringUtil.BR [a]
// SysDefs.d [a]
// UtilSTR.BR [d]

//Modified November 26, 1979
//A bug fix by Lyle Ramshaw in the microcoded floating point,
// and in the Convert routin, Arithmetic Splines.
// The microcoded version of FCM was using a signed instead of
// an unsigned compare to compare the lower order parts of the
// mantissa, and hence came up with the wrong answers once in
// a great while.
//
//The Arithmetic Splines version of the routine SCVReadRuns had
// an apparent problem as well, which I fixed, although I never
// found an actual case where this bug showed up once the FCM
// bug mentioned above was fixed. The problem is the following:
// in the ArithmeticSplines version of SCVMain, each monotone
// spline segment is considered as linearly interpolating the spline
// values at the points t0, t0+dt, t0+2*dt, ... t0+K*dt=t1. The
// value of dt is calculated in floating point from the values of
// t0, t1, and K. But then, while finding intersections with
// successive scan lines, the t values are computed by repeated
// addition of dt, as in the sequence above. If rounding error
// leads to t0+K*dt being substantially different than t1, and it
// the spline has as s value at t1 a number just barely bigger than
// an integer, the s value at t0+j*dt might be smaller than that
// integer (which will be smax) for all j.

//Prepress version 1.10

//Modified October 26, 1979
//Bug fix by Lyle Ramshaw in Extract command, related to MultiChars
// hack. See the description in the changed module, Filops.

//Modified by Lyle Ramshaw, September/October 1976. The main changes were:
// -getting a version of the Trident BR’s compatible with OS17
// -adding the ReadAL command, to go from .AL to .AC
// -adding the DeOrbitize command, orbitized .AC to vanilla .AC
// -loading a newer version of the microcoded floating point
// -adding a window to the main menu which displays the file type
//
//New modules: ReadAL
// (Code for DeOrbitize is in the file OrbitFormat.BCPL)
//
//Changed modules:
//
Prepress
//
PrepressMenu
//
PrepressMenuUtil
//
OrbitFormat
//
PlayOut
//
//Changed LoadPrePress.CM by
//
-deleting FEditMenu from overlay 4 on instructions from LaPrade
//
-added an overlay 5 for ReadAL
//
//Changed CompilePrePress.CM by
//
-adding ReadAL
//
-adding MergeDelete, which seems to have been left out by mistake
//
//Changed PrePressSources.DM by
//
-adding ReadAL.BCPL
//
-adding MergeDelete, which seems to have been left out by mistake

//Prepress version 1.9

//Modified September, 1978 by Kerry A. LaPrade, XEOS
//Major improvements to "Edit" section:
// - now uses Keith Knox’s menu package
// - business-like looking menu displays more information
// than before
// - larger editting area
// - less likely to accidentally change character’s widths
// - can turn background off during session
// - confirmations required before invoking "hazardous" functions
// - faster grid, exclusively ored for eraseability without
// leaving holes
// - new window for viewing character being editted at one
// Alto pixel per printer pixel
// - strings are clipped if necessary
// - "Auto" command makes filing easier
//Bob Sproull fixed a bug in ImposeWidths, and Joe Maleson
// revised the menu to allow calling ImposeWidths with
// arbitrary source and destination files.
//File names CDTemp and CDEdits were replaced by ACTemp and
// ACEdits, respectively.

get "GoodFoo.d"
get "ix.dfs"
get "OverlayStuff.d"
get "BcplFiles.d"

// outgoing procedures
external
[
CheckParams
PrePressWindowInit
SwappedOut
]

// outgoing statics
//external
// [
// ]

//static
// [
// ]

// incoming procedures
external
[
//PrePressCommands
Disambiguate
GetOverlayNumber
InitCommands
ReadParams

//PrePressMenu
MenuGetCommand

//Main command-processing procedures
Convert
Coordinate
DeOrbitFormat
Extract
FEdit
Grow
ImposeWidths
List
MakeWidths
MergeDelete
// MMFonts
OrbitFormat
PlayOut
ReadAL
ReadCU
Rotate
Rename
Scale
SFTOSD
WidthCalc
ReadKS
MakeKS

// PrePressUtil
FSGetX
FSInit
FSPut
IllCommand
NoFile
Scream

//PrepressWindow //File window stuff.
WindowInit

//Scan
PrintNumber
ReadCom
ReadComInit
ReadNumber
StrCop
StrEq
TypeForm

//TFS + RAM
DiskRamImage
LoadRam
lvSwatContextProc
lvUserFinishProc
MicroFloatRamImage
TFSClose
TFSInit
TFSSilentBoot
TFSSwatContextProc

//OS
MyFrame
Usc
GetCurrentFa
PositionPage
InitializeZone
Junta
]

// incoming statics
external
[
@convertThicken
//from Convert
@prePressZone

//Float
FPSetup

//PrepressCommands
@BackgroundFileName
@bigfilename
@fam
@InputFileName
@fastFlag
@verifyFlag
@OutputFileName
@params
@tridentDriveNumber
@tridentNeeded
@updateflag
@xfp
@yfp

//OS
fpSysFont
lvSysZone
]

// internal statics
static
[
@blvStartOfStatics
@blvEndOfStatics
@blvStartOfCode
@cfa
@sysFontHeight
@sysFontLength
@OvTbl
//table of FA’s to the starts of the overlays
@OverlayReloc = 0
@standardSwatContextProc
@standardUserFinishProc
@tridentDisk // non-zero if look for things on Trident
]

// File-wide structure and manifest declarations.

// Procedures

//*********************************************************
let StartUp(blv,nil,cfaIn) be
//*********************************************************
[
//Pull the relevant data out of the BLV, and salt it away
blvStartOfStatics = blv>>BLV.startOfStatics
blvEndOfStatics = blv>>BLV.endOfStatics
blvStartOfCode = blv>>BLV.startOfCode
//We must copy the cfaIn out of the stack, which the Junta will smash
cfa = GetFixed(lCFA)
MoveBlock(cfa,cfaIn,lCFA)
let s=OpenFileFromFp(fpSysFont)
sysFontHeight=Gets(s)
sysFontLength=FileLength(s)/2
Closes(s)

//And save away the swat and finish procedures:
standardSwatContextProc = @lvSwatContextProc
standardUserFinishProc = @lvUserFinishProc

Junta(levDisplay, Main)
]

//*********************************************************
and Main() be
//*********************************************************
[
@lvUserFinishProc = TurnOffDisplay

//The first task is to restore our state from the Junta...
// This involves rebuilding the system display stream "dsp"
// and sysZone. The following code builds them up to be the
// same size as the OS defaults as of OS18. The next time that
// we get tight on space, we might want to steal some space from
// one or both of these places: after all, our dsp lines aren’t
// normally full lines, and we don’t use nearly all of sysZone.

let fHeven=(sysFontHeight+1) & -2
//We will allow for 6 lines of dsp, each 36 words long, same as OS does
let disAreaNeeded=(6*(lDCB+fHeven*36)+1)/2
//Also, allow for 2 display streams + 7 disk streams + room to play
let sysNeeded=lDS*2+ (lKS+256)*7 + 5*lST + 100
let v=GetFixed(sysNeeded+disAreaNeeded+sysFontLength)
v=InitializeZone(v, sysNeeded+disAreaNeeded+sysFontLength)
@lvSysZone=v
//patch the OS’s copy
sysZone=v //and patch our copy
let s=OpenFileFromFp(fpSysFont)
let f=Allocate(sysZone,sysFontLength)
Resets(s); ReadBlock(s,f,sysFontLength); Closes(s)
sysFont=f+2
let w=Allocate(sysZone,disAreaNeeded)
dsp=CreateDisplayStream(6,w,disAreaNeeded,sysFont,0,0,sysZone)
ShowDisplayStream(dsp,DSalone)

Wl("*N*N*N*NPrePress 2.5 of January 20, 1982")

let permMemBottom, firstTime, useCommandLine =
@#335, true, nil
let str, sw, swt, fileCode, defFileCode, commandCode =
nil, nil, nil, nil, nil, nil
//now for some overlay hackery: initialize OvTbl to point
// to a table of zeros of length lFaTbl
compileif lFaTbl ne 24 then [ foo = nil ]
let OvTblTemp = table [ 0;0;0;0;0;0;
0;0;0;0;0;0;
0;0;0;0;0;0;
0;0;0;0;0;0 ] //table of 24 zeros
OvTbl = OvTblTemp
OverlayTableInit()

[
//global repeat loop (once if command line, until quit button otherwise)
//start by throwing everything away, and trying to load the RAM with
// the microcoded floating point
@#335 = permMemBottom
Overlay(MicroFloatLoad)
OverlayReloc = 0
//don’t mark microFloat as swapped out
let isRam = LoadRam(MicroFloatRamImage)
let newMemBottom = nil
test isRam ls 0 ifso
[ //Woops, the Ram is missing or doesn’t work; maybe
//this is a Dorado we are running on, eh?
//Well, its back to the software floating point...
@#335 = permMemBottom
Overlay(SoftwareFloat)
newMemBottom = OverlayReloc
OverlayReloc = 0//don’t mark softFloat as swapped out
]
ifnot
[
newMemBottom = LoadRam
newMemBottom!0 = 32 //number of ACs
FPSetup(newMemBottom)
newMemBottom = newMemBottom + 32 * 4 + 1 //work space for floating point accumulators
]
@#335 = newMemBottom
//keep the floating point around
Overlay(CommandInterpret)

if firstTime then
[
useCommandLine = InitCommands(lv str, lv sw, lv swt, lv fileCode, lv defFileCode, lv commandCode)
firstTime = false
]
unless useCommandLine do
commandCode = MenuGetCommand()

let overlayNumber = GetOverlayNumber(commandCode)
@#335 = newMemBottom
//flush the commandInterpret overlay
Overlay(overlayNumber)

test useCommandLine
ifso
DoCommandLineSelection(commandCode, swt, defFileCode, fileCode)
ifnot
DoMenuSelection(commandCode)
if tridentDisk then TFSCleanupProc()
] repeatuntil useCommandLine //once only?

finish //must be explicit because of Junta
]

//*********************************************************
and DoCommandLineSelection(commandCode, swt, defFileCode, fileCode) be
//*********************************************************
[
switchon commandCode into
[
case 1:
SFTOSD(swt eq $U)
endcase

case 2:
PlayOut(0)
endcase

case 3:
PlayOut(1)
endcase

case 4:
PlayOut(2)
endcase

// case 5:
// MMFonts(swt)
// endcase

case 6:
PlayOut(3)
endcase

case 7:
MakeWidths()
endcase

case 8:
ReadCU()
endcase

case 9:
ReadAL()
endcase

case 10:
MakeKS()
endcase

case 11:
ReadKS()
endcase

case 12:
// FEdit(swt eq $N)
FEdit()
endcase

case 13:
Convert(swt eq $T)
endcase

case 14:
MergeDelete(defFileCode, 0, not fastFlag)
endcase

case 15:
List(defFileCode, not fastFlag)
endcase

case 16:
Coordinate()
endcase

case 17:
OrbitFormat()
endcase

case 18:
Scale()
endcase

case 19:
ImposeWidths(defFileCode)
endcase

case 20:
DeOrbitFormat()
endcase

case 21:
Rotate()
endcase

case 22:
Grow(true)
endcase

case 23:
Grow(false)
endcase

case 24:
MergeDelete(fileCode, 3, not fastFlag)
endcase

case 30:
Extract(fileCode)
endcase

case 31:
MergeDelete(fileCode, 1, not fastFlag)
endcase

case 32:
MergeDelete(fileCode, 2, not fastFlag)
endcase

case 33:
if fileCode eq 3 then IllCommand()
WidthCalc(fileCode)
endcase

case 34:
Rename(-fileCode)
endcase

default:
Scream("Unknown command")
endcase
]
]

//*********************************************************
and DoMenuSelection(commandCode) be
//*********************************************************
[
switchon commandCode into
[
case 1:
SFTOSD(updateflag, InputFileName, OutputFileName)
endcase

case 2:
PlayOut(0, InputFileName)
endcase

case 3:
PlayOut(1, InputFileName, OutputFileName)
endcase

case 4:
PlayOut(2, InputFileName, OutputFileName)
endcase

// case 5:
// MMFonts()
// endcase

case 6:
PlayOut(3, InputFileName, OutputFileName)
endcase

case 7:
MakeWidths(InputFileName, OutputFileName)
endcase

case 8:
ReadCU(InputFileName, OutputFileName)
endcase

case 9:
ReadAL(InputFileName, OutputFileName)
endcase

case 10:
MakeKS(InputFileName, OutputFileName)
endcase

case 11:
ReadKS(InputFileName, OutputFileName)
endcase

case 12:
// FEdit(BackgroundFileName>> STRING.length eq 0, InputFileName)
FEdit()
endcase

case 13:
Convert(convertThicken, InputFileName, OutputFileName)
endcase

case 14:
MergeDelete(nil, 0, not fastFlag, bigfilename)
endcase

case 15:
List(nil, not fastFlag, bigfilename)
endcase

case 16:
Coordinate(InputFileName, OutputFileName)
endcase

case 17:
OrbitFormat(InputFileName, OutputFileName)
endcase

case 18:
Scale(InputFileName, OutputFileName)
endcase

case 19:
ImposeWidths(nil,InputFileName,OutputFileName)
endcase

case 20:
DeOrbitFormat(InputFileName, OutputFileName)
endcase

case 21:
Rotate(InputFileName, OutputFileName)
endcase

case 22:
Grow(true, InputFileName, OutputFileName)
endcase

case 23:
Grow(false, InputFileName, OutputFileName)
endcase

case 24:
MergeDelete(nil, 3, not fastFlag, bigfilename)
endcase

case 30:
Extract(nil, OutputFileName, bigfilename)
endcase

case 31:
MergeDelete(nil, 1, not fastFlag, bigfilename, InputFileName)
endcase

case 32:
MergeDelete(nil, 2, not fastFlag, bigfilename, InputFileName)
endcase

case 33:
WidthCalc(InputFileName, OutputFileName)
endcase

case 34:
Rename(InputFileName)
endcase

default:
Scream("Unknown command")
endcase
]
]

//*********************************************************
and CheckParams(p)= valof
//*********************************************************
[
let ans = ((p & (not params)) eq 0)
unless ans do Wl("Insufficient parameters.")
resultis ans
]

//*********************************************************
and PrePressWindowInit(n,rw,lvnam; numargs nargs) = valof [
//*********************************************************
if nargs eq 1 then rw=true
let nam=selecton n into [
case 0:"PrePress.Scratch"
case 1:"CD"
case 2:"SD"
case 3: "WD"
case -1: "ACtemp"
case -2: "SDtemp"
case -3: "WDtemp"
default: n ]
if n gr 0 & n le 3 & bigfilename!0 ne 0 then nam=bigfilename
if nargs gr 2 then @lvnam=nam

//Look for files on Trident first if tridentDisk exists (ne 0)
let typ=(rw ne 0)? ksTypeReadWrite, ksTypeReadOnly
let disk=tridentDisk
let zone=prePressZone
let ver=verLatest

for diskNo = 0 to 1 do
[
if disk ne 0 then
[
let s=OpenFile(nam, typ, 2, ver, 0, 0, zone, 0, disk)
if s then resultis WindowInit(s)
]
disk=sysDisk
ver=0
]

if nam eq n then resultis 0
NoFile(nam)
finish
]

// Overlay-reading routine: sets up OvTbl, a table of pointers
// to the starts of the NumOvs different overlays.

//*********************************************************
and OverlayTableInit() be
//*********************************************************
[
//The first time that this .RUN file is executed, we will compute
// the addresses of the overlays, and store them into the .Run
// file in the "table" declaration of OvTbl. From then on, when
// PrePress is started, we will just use what’s there.

//First, we check the current contents of OvTbl to see if it’s
// correct:
if OvTbl>>FaTbl↑1.da eq cfa>>CFA.fa.da &
OvTbl>>FaTbl↑1.pageNumber eq cfa>>CFA.fa.pageNumber
then return//table is already set up

let curPageNum, curFA = vec 1, vec lFA

//extract first overlay position from cfa, and store in OvTbl
MoveBlock(curFA, lv cfa>>CFA.fa, lFA)
MoveBlock(lv OvTbl>>FaTbl↑1, curFA, lFA)

//open .RUN file to find the starts of the other overlays
let s=OpenFileFromFp(lv cfa>>CFA.fp)
JumpToFa(s, curFA)

//now, cycle through
let dope = vec lBBHeader
curPageNum = curFA>>FA.pageNumber
for i=2 to NumOvs do
[
ReadBlock(s, dope, lBBHeader)
curPageNum=curPageNum+((dope>>BBHeader.fileLength+255) rshift 8)
PositionPage(s, curPageNum)
GetCurrentFa(s, lv OvTbl>>FaTbl↑i)
]
//And now for some real magic, (with help from Ed Taft)
//We now reach into the .Run file and store this table data
let ovTblFp= vec 1
ovTblFp!0=0
ovTblFp!1=(offset SV.statics)/16+
(blvEndOfStatics-blvStartOfStatics+1)+
(OvTbl-blvStartOfCode)
//next, convert to byte address
DoubleAdd(ovTblFp, ovTblFp)
SetFilePos(s,ovTblFp)
WriteBlock(s, OvTbl, lFaTbl)
Closes(s)
]

// Overlay-reading routine. Given number of overlay, read it in.
// File locations are stored in OvTbl.

//*********************************************************
and Overlay(ovNum) be
//*********************************************************
[
let p=OverlayReloc
unless p eq 0 do for i=1 to p!0 do
[ @(p!1)=SwappedOut;p=p+2 ]

let s=OpenFileFromFp(lv cfa>>CFA.fp)
JumpToFa(s, lv OvTbl>>FaTbl↑ovNum)
let dope=vec lBBHeader
let overlayBottom=@#335

ReadBlock(s, dope, lBBHeader)
let len=((dope>>BBHeader.fileLength+255)&(-256))-16
if Usc(len+overlayBottom,MyFrame()-200) ge 0 then
Scream("Overlay won’t fit!")
ReadBlock(s, overlayBottom, len)
Closes(s)

OverlayReloc=overlayBottom+dope>>BBHeader.relPairTable-16
let nRel=OverlayReloc!0*2
for p=1 to nRel by 2 do @(OverlayReloc!p)=OverlayReloc!(p+1)+overlayBottom
@#335=OverlayReloc+nRel+1


// If he asked for trident disk, and if routines are loaded in this
// overlay, and if RAM will load, give it to him!
if tridentNeeded eq 0 % TFSInit eq SwappedOut
then [ FSInit(2000); return ]
let AltoVersion =(table [ #61014; #1401 ] )()
let eng=AltoVersion<<VERS.eng
let load=LoadRam(DiskRamImage, true)
if (load ls 0) & (eng ls 4) then
[
Wl("*nCouldn’t load the RAM: using DP0...")
FSInit(2000)
return
]
//don’t worry if the RAM won’t load on a Dolphin or Dorado
@lvSwatContextProc = TFSSwatContextProc
@lvUserFinishProc = TFSCleanupProc
//and move the OverlayReloc down to LoadRam
MoveBlock(LoadRam,OverlayReloc,nRel+1)
OverlayReloc=LoadRam
@#335=OverlayReloc+nRel+1
FSInit(2200)
tridentDisk=TFSInit(prePressZone, true, tridentDriveNumber)
unless tridentDisk then
[ Wl("*nTrident disk not on line: using DP0...")
if eng ge 4 then Wl("(Running the correct microcode?)")
TFSCleanupProc()
]
]

//*********************************************************
and TFSCleanupProc() be
//*********************************************************
[
if tridentDisk then
[
TFSClose(tridentDisk)
tridentDisk = 0
]
@lvSwatContextProc = standardSwatContextProc
@lvUserFinishProc = TurnOffDisplay
TFSSilentBoot()
]

//*********************************************************
and TurnOffDisplay() be
//*********************************************************
[
//Just before the CounterJunta, it is best to turn off the
// display, since the memory through which the display chain
// winds is about to be smashed...
@displayListHead = 0
for i=0 to 30000 loop
@lvUserFinishProc = standardUserFinishProc
]

//*********************************************************
and SwappedOut() be Scream("Called swapped out procedure")
//*********************************************************