DIRECTORY AltoFileDefs: FROM "AltoFileDefs", DiscoDefs: FROM "DiscoDefs" USING [SFD,ScanBuffer], GraphicsDefs: FROM "GraphicsDefs", IODefs: FROM "IODefs", InlineDefs: FROM "InlineDefs", MagicDefs: FROM "MagicDefs", Mopcodes: FROM "MopCodes"; Magic: PROGRAM IMPORTS DiscoDefs, InlineDefs, GraphicsDefs EXPORTS MagicDefs = BEGIN RandomTable: ARRAY [ 0..16) OF CARDINAL _ [1,22222,30303,7345,5525,6666,7777,877,9999,1770,11111,12,1313,7714,15151,1776]; next: CARDINAL _ 1; Random: PUBLIC PROCEDURE RETURNS [CARDINAL] = BEGIN this: CARDINAL _ next; next _ (next+1) MOD 16; RandomTable[this] _ RandomTable[this]+RandomTable[next]; RETURN[RandomTable[this]]; END; Buttons: TYPE = MACHINE DEPENDENT RECORD [ KeyPadAndGarbage: [0..10000B), Red: [0..1], Blue: [0..1], Yellow: [0..1] ]; MouseButtons: POINTER TO Buttons = LOOPHOLE[177030B]; CursorX: POINTER TO CARDINAL = LOOPHOLE[426B]; CursorY: POINTER TO CARDINAL = LOOPHOLE[427B]; GetUserBox: PUBLIC PROCEDURE [xRatio,yRatio: CARDINAL] RETURNS [x,y: CARDINAL,dx,dy: INTEGER] = BEGIN calculatedX,calculatedY: LONG INTEGER; UNTIL MouseButtons.Red = 0 DO ENDLOOP; x _ CursorX^; y _ CursorY^; dx _ dy _ 0; DO WHILE MouseButtons.Red = 0 DO GraphicsDefs.XorArea[x,y,x+dx,y]; GraphicsDefs.XorArea[x+dx,y,x+dx,y+dy]; GraphicsDefs.XorArea[x+dx,y+dy,x,y+dy]; GraphicsDefs.XorArea[x,y+dy,x,y]; dx _ CursorX^ - x; dy _ CursorY^ - y; calculatedX _ (LONG[dy-1]*LONG[xRatio])/LONG[yRatio]; calculatedY _ (LONG[dx+1]*LONG[yRatio])/LONG[xRatio]; IF ABS[ABS[calculatedX]-ABS[dx]] > ABS[ABS[calculatedY]-ABS[dy]] THEN dy _ (IF dy<0 THEN -1 ELSE 1)*InlineDefs.LowHalf[ABS[calculatedY]] ELSE dx _ (IF dx<0 THEN -1 ELSE 1)*InlineDefs.LowHalf[ABS[calculatedX]]; GraphicsDefs.XorArea[x,y,x+dx,y]; GraphicsDefs.XorArea[x+dx,y,x+dx,y+dy]; GraphicsDefs.XorArea[x+dx,y+dy,x,y+dy]; GraphicsDefs.XorArea[x,y+dy,x,y]; ENDLOOP; IF dx < 0 THEN BEGIN x _ x+dx;dx _ ABS[dx];END; IF dy < 0 THEN BEGIN y _ y+dy;dy _ ABS[dy];END; WHILE MouseButtons.Yellow = 0 DO --move origin GraphicsDefs.XorArea[x,y,x+dx,y]; GraphicsDefs.XorArea[x+dx,y,x+dx,y+dy]; GraphicsDefs.XorArea[x+dx,y+dy,x,y+dy]; GraphicsDefs.XorArea[x,y+dy,x,y]; x _ CursorX^; y _ CursorY^; GraphicsDefs.XorArea[x,y,x+dx,y]; GraphicsDefs.XorArea[x+dx,y,x+dx,y+dy]; GraphicsDefs.XorArea[x+dx,y+dy,x,y+dy]; GraphicsDefs.XorArea[x,y+dy,x,y]; ENDLOOP; IF MouseButtons.Blue = 0 THEN RETURN[x,y,dx,dy]; ENDLOOP; END; Menu: PUBLIC PROCEDURE [nItems: CARDINAL,itemList: POINTER TO ARRAY [0..0) OF STRING,font: POINTER TO GraphicsDefs.StrikeFont] RETURNS [index: CARDINAL] = BEGIN stringLen: PUBLIC PROCEDURE [s: STRING] RETURNS [CARDINAL] = BEGIN i: CARDINAL; widthList: POINTER TO ARRAY [0..0) OF CARDINAL _ font.xInSegment; len: CARDINAL _ 0; FOR i IN [0..s.length) DO BEGIN ix: CARDINAL _ LOOPHOLE[s[i],CARDINAL]; len _ len + widthList[ix+1] - widthList[ix]; END; ENDLOOP; RETURN[len]; END; menuWidth: CARDINAL _ 0; fontHeight: CARDINAL _ font.ascent + font.descent; menuHeight: CARDINAL _ nItems * fontHeight; menuBox: GraphicsDefs.Box; b: POINTER TO GraphicsDefs.Box _ @menuBox; menuBitmap: POINTER TO GraphicsDefs.Bitmap _ @menuBox.boxBitmap; Select: PUBLIC PROCEDURE [index: CARDINAL] = BEGIN GraphicsDefs.XorArea[0,index*fontHeight, stringLen[itemList[index]],(index+1)*fontHeight,menuBitmap]; GraphicsDefs.PaintBox[@menuBox]; END; i: CARDINAL; Screen: POINTER TO GraphicsDefs.Bitmap _ GraphicsDefs.GetDefaultBitmapHandle[]; DCB: TYPE = MACHINE DEPENDENT RECORD [ link: POINTER TO DCB, lowResolution: BOOLEAN, inverseVideo: BOOLEAN, offset: [0..77B], width: [0..377B], bits: POINTER, height: CARDINAL ]; DCBHead: POINTER TO POINTER TO DCB = LOOPHOLE[420B]; currentDCB: POINTER TO DCB _ DCBHead^; XOffset,YOffset: CARDINAL _ 0; UNTIL currentDCB = NIL DO IF currentDCB.bits = Screen.bits THEN EXIT; YOffset _ YOffset + currentDCB.height*2; currentDCB _ currentDCB.link; ENDLOOP; IF currentDCB = NIL THEN YOffset _ 0 ELSE XOffset _ currentDCB.offset*16; index _ 177777B; FOR i IN [0..nItems) DO BEGIN sLen: CARDINAL _ stringLen[itemList[i]]; IF sLen > menuWidth THEN menuWidth _ sLen; END; ENDLOOP; GraphicsDefs.CreateBox[@menuBox,menuWidth,menuHeight]; GraphicsDefs.PutArea[0,0,0,menuBitmap.nLines-1,menuBitmap]; GraphicsDefs.PutArea[0,menuBitmap.nLines-1, menuBitmap.nBits-1,menuBitmap.nLines-1,menuBitmap]; GraphicsDefs.PutArea[menuBitmap.nBits-1,menuBitmap.nLines-1, menuBitmap.nBits-1,0,menuBitmap]; GraphicsDefs.PutArea[menuBitmap.nBits-1,0,0,0,menuBitmap]; GraphicsDefs.DisplayBox[@menuBox,CursorX^-XOffset,CursorY^-YOffset]; FOR i IN [0..nItems) DO []_GraphicsDefs.PutText[itemList[i],0,font.ascent+i*fontHeight,font,0, menuBitmap]; ENDLOOP; GraphicsDefs.PaintBox[@menuBox]; WHILE CursorX^-XOffset IN [MAX[20,b.displayX]-20..b.displayX+b.boxBitmap.nBits+20) AND CursorY^-YOffset IN [MAX[20,b.displayY]-20..b.displayY+b.boxBitmap.nLines+20) DO WHILE MouseButtons.Yellow = 0 DO GraphicsDefs.MoveBox[@menuBox,CursorX^-XOffset,CursorY^-YOffset]; ENDLOOP; IF MouseButtons.Red = 0 THEN --selection BEGIN newIndex: CARDINAL _ MIN[nItems-1,(CursorY^-YOffset-menuBox.displayY)/fontHeight]; IF newIndex = index THEN LOOP; IF index IN [0..nItems) THEN Select[index]; index _ newIndex; Select[index]; END; ENDLOOP; GraphicsDefs.DestroyBox[@menuBox,TRUE]; RETURN[index]; END; lastBuffer: POINTER TO UNSPECIFIED _ NIL; wordsLeft: CARDINAL _ 0; InitReadBlock: PUBLIC PROCEDURE = BEGIN wordsLeft _ 0; END; ReadBlock: PUBLIC PROCEDURE[sfd: POINTER,p: POINTER TO UNSPECIFIED,nwords: CARDINAL] RETURNS [POINTER TO UNSPECIFIED] = BEGIN dsfd: POINTER TO DiscoDefs.SFD _ sfd; fa: AltoFileDefs.FA; wordsTransferred: CARDINAL _ 0; thisTransfer: CARDINAL; --IF nwords <= wordsLeft THEN -- BEGIN -- wordsLeft _ wordsLeft - nwords; -- RETURN[lastBuffer+(256-(wordsLeft+nwords))]; -- END; UNTIL nwords = 0 DO thisTransfer _ MIN[wordsLeft,nwords]; InlineDefs.COPY[to: p+wordsTransferred,from: lastBuffer + 256 - wordsLeft,nwords:thisTransfer]; nwords _ nwords - thisTransfer; wordsLeft _ wordsLeft - thisTransfer; wordsTransferred _ wordsTransferred + thisTransfer; IF wordsLeft = 0 THEN BEGIN lastBuffer _ DiscoDefs.ScanBuffer[dsfd,@fa]; wordsLeft _ 256; END; ENDLOOP; wordsTransferred _ wordsTransferred + thisTransfer; RETURN[p]; END; END. (635)\f1 250b5B224b6B460b10B1473b4B2926b80B48b9B