(*
                     IntuiSup library interface

              Para usar con Modula-2 Software Construction Set                
   -----------------------------------------------------------------------

	por:   Mauricio Hunt R.
               Apt 856 - 2150, Moravia,
               San Jose, Costa Rica
               Central America

   -----------------------------------------------------------------------

        Intuisup library por:

	Torsten Jürgeleit
	Am Sandberg 4
	W-5270 Gummersbach
	Germany

   Gracias Torsten !
*)

IMPLEMENTATION MODULE IntuiSupInterface;

FROM SYSTEM    IMPORT ADDRESS, INLINE, SETREG, ADR, REG, LONG, LONGWORD;
FROM Intuition IMPORT IDCMPFlags, IDCMPFlagsSet, ImagePtr, ScreenPtr, 
                  WindowPtr, NewWindow, MenuPtr, MenuItemPtr, IntuiMessagePtr,
                  GadgetPtr;
FROM Text      IMPORT TextAttrPtr, TextFontPtr;
FROM DiskFont  IMPORT AvailFontsHeaderPtr;
FROM Lists     IMPORT ListPtr;
FROM Ports     IMPORT MsgPortPtr;
FROM Libraries IMPORT OpenLibrary, CloseLibrary, LibraryPtr;

CONST
  D0=0;  D1=1;  D2=2;  D3=3;  D4=4;  D5=5;  D6=6;  D7=7;
  A0=8;  A1=9;  A2=10; A3=11; A4=12; A5=13; A6=14; A7=15;

  JSRA6     = 4EAEH;

  LVOIGetRenderInfo          = -30;
  LVOIFreeRenderInfo         = -36;
  LVOIOpenWindow             = -42;
  LVOIClearRenderWindow      = -48;
  LVOICloseWindow            = -54;
  LVOIAvailFonts             = -60;
  LVOIAskFont                = -66;
  LVOIOpenFont               = -72;
  LVOIDisplayTexts           = -78;
  LVOIPrintText              = -84;
  LVOIConvertUnsignedDec     = -90;
  LVOIConvertSignedDec       = -96;
  LVOIConvertHex             = -102;
  LVOIConvertBin             = -108;
  LVOIDisplayBorders         = -114;
  LVOIDrawBorder             = -120;
  LVOICreateGadgets          = -126;
  LVOIFreeGadgets            = -132;
  LVOIDisplayGadgets         = -138;
  LVOIRefreshGadgets         = -144;
  LVOIModifyGadget           = -150;
  LVOISetGadgetAttributes    = -156;
  LVOIActivateInputGadget    = -162;
  LVOIGadgetAddress          = -168;
  LVOIRemoveGadgets          = -174;
  LVOIGetMsg                 = -180;
  LVOIReplyMsg               = -186;
  LVOIAutoRequest            = -192;
  LVOIDisplayRequester       = -198;
  LVOIRemoveRequester        = -204;
  LVOICreateMenu             = -210;
  LVOIAttachMenu             = -216;
  LVOIMenuItemAddress        = -222;
  LVOIRemoveMenu             = -228;
  LVOIFreeMenu               = -234;
  LVOIOpenTextFile           = -240;
  LVOIReadTextLine           = -246;
  LVOICloseTextFile          = -252;
  LVOIBuildLanguageTextArray = -258;
  LVOIGetLanguageText        = -264;
  LVOIFreeLanguageTextArray  = -270;
  LVOIChangeMousePointer     = -276;
  LVOIRestoreMousePointer    = -282;
  LVOIMoveMousePointer       = -288;

PROCEDURE IGetRenderInfo(screen : ScreenPtr; flags : CARDINAL):ADDRESS;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,screen);
  SETREG(D0,LONG(flags));
  INLINE(JSRA6,LVOIGetRenderInfo);
  RETURN ADDRESS(REG(D0));
END IGetRenderInfo;

PROCEDURE IFreeRenderInfo(ri:ADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  INLINE(JSRA6,LVOIFreeRenderInfo);
END IFreeRenderInfo;

PROCEDURE IOpenWindow(ri:ADDRESS; nw:NewWindow; flags:CARDINAL):WindowPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,ADR(nw));
  SETREG(D0,LONG(flags));
  INLINE(JSRA6,LVOIOpenWindow);
  RETURN WindowPtr(REG(D0))
END IOpenWindow;

PROCEDURE IClearRenderWindow(ri:ADDRESS; win:WindowPtr; 
                             leftedge, topedge, width, height,
                             flags:LONGCARD);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,win);
  SETREG(D0,leftedge);
  SETREG(D1,topedge);
  SETREG(D2,width);
  SETREG(D3,height);
  SETREG(D4,flags);
  INLINE(JSRA6,LVOIClearRenderWindow);
END IClearRenderWindow;

PROCEDURE ICloseWindow(win:WindowPtr; morewindows:BOOLEAN);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,win);
  SETREG(D0,LONG(morewindows));
  INLINE(JSRA6,LVOICloseWindow);
END ICloseWindow;

PROCEDURE IAvailFonts(ri:ADDRESS):AvailFontsHeaderPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  INLINE(JSRA6,LVOIAvailFonts);
  RETURN AvailFontsHeaderPtr(REG(D0))
END IAvailFonts;

PROCEDURE IAskFont(ri:ADDRESS; ta:TextAttrPtr):TextAttrPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,ta);
  INLINE(JSRA6,LVOIAskFont);
  RETURN TextAttrPtr(REG(D0))
END IAskFont;

PROCEDURE IOpenFont(ri:ADDRESS; ta:TextAttrPtr):TextFontPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,ta);
  INLINE(JSRA6,LVOIOpenFont);
  RETURN TextFontPtr(REG(D0))
END IOpenFont;

PROCEDURE IDisplayTexts(ri:ADDRESS; win:WindowPtr; td:TextDataPtr;
                        hoffset:INTEGER; voffset:INTEGER;
                        languagetextarray:DADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,win);
  SETREG(A2,td);
  SETREG(D0,LONG(hoffset));
  SETREG(D1,LONG(voffset));
  SETREG(A3,languagetextarray);
  INLINE(JSRA6,LVOIDisplayTexts)
END IDisplayTexts;

PROCEDURE IPrintText(ri:ADDRESS; win:WindowPtr; text:ADDRESS;
                     leftedge, topedge, type:CARDINAL; flags:LONGCARD;
                     textattr : TextAttrPtr):CARDINAL;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,win);
  SETREG(A2,text);
  SETREG(D0,LONG(leftedge));
  SETREG(D1,LONG(topedge));
  SETREG(D2,LONG(type));
  SETREG(D3,flags);
  SETREG(A3,textattr);
  INLINE(JSRA6,LVOIPrintText);
  RETURN CARDINAL(REG(D0))
END IPrintText;

PROCEDURE IConvertUnsignedDec(num:LONGCARD; buffer:ADDRESS; flags:CARDINAL):CARDINAL;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(D0,num);
  SETREG(A0,buffer);
  SETREG(D1,LONG(flags));
  INLINE(JSRA6,LVOIConvertUnsignedDec);
  RETURN CARDINAL(REG(D0));
END IConvertUnsignedDec;

PROCEDURE IConvertSignedDec(num:LONGINT; buffer:ADDRESS; flags:CARDINAL):CARDINAL;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(D0,num);
  SETREG(A0,buffer);
  SETREG(D1,LONG(flags));
  INLINE(JSRA6,LVOIConvertSignedDec);
  RETURN CARDINAL(REG(D0));
END IConvertSignedDec;

PROCEDURE IConvertHex(num:LONGCARD; buffer:ADDRESS; flags:CARDINAL):CARDINAL;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(D0,num);
  SETREG(A0,buffer);
  SETREG(D1,LONG(flags));
  INLINE(JSRA6,LVOIConvertHex);
  RETURN CARDINAL(REG(D0));
END IConvertHex;

PROCEDURE IConvertBin(num:LONGCARD; buffer:ADDRESS; flags:CARDINAL):CARDINAL;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(D0,num);
  SETREG(A0,buffer);
  SETREG(D1,LONG(flags));
  INLINE(JSRA6,LVOIConvertBin);
  RETURN CARDINAL(REG(D0));
END IConvertBin;

PROCEDURE IDisplayBorders(ri:ADDRESS; win:WindowPtr; bd:ADDRESS;
                          hoffset, voffset:INTEGER);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,win);
  SETREG(A2,bd);
  SETREG(D0,LONG(hoffset));
  SETREG(D1,LONG(voffset));
  INLINE(JSRA6,LVOIDisplayBorders);
END IDisplayBorders;

PROCEDURE IDrawBorder(ri:ADDRESS; win:WindowPtr; leftedge, topedge,
                      width, height, type:LONGCARD);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,win);
  SETREG(D0,leftedge);
  SETREG(D1,topedge);
  SETREG(D2,width);
  SETREG(D3,height);
  SETREG(D4,type);
  INLINE(JSRA6,LVOIDrawBorder)
END IDrawBorder;

PROCEDURE ICreateGadgets(ri:ADDRESS; gd:GadgetDataPtr; 
                         hoffset, voffset:INTEGER;
                         languagetextarray:DADDRESS):ADDRESS;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,gd);
  SETREG(D0,LONG(hoffset));
  SETREG(D1,LONG(voffset));
  SETREG(A2,languagetextarray);
  INLINE(JSRA6,LVOICreateGadgets);
  RETURN ADDRESS(REG(D0))
END ICreateGadgets;

PROCEDURE IFreeGadgets(gl:ADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,gl);
  INLINE(JSRA6,LVOIFreeGadgets);
END IFreeGadgets;

PROCEDURE IDisplayGadgets(win:WindowPtr; gl:ADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,win);
  SETREG(A1,gl);
  INLINE(JSRA6,LVOIDisplayGadgets);
END IDisplayGadgets;

PROCEDURE IRefreshGadgets(gl:ADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,gl);
  INLINE(JSRA6,LVOIRefreshGadgets)
END IRefreshGadgets;

PROCEDURE IModifyGadget(gl:ADDRESS; dataentry:CARDINAL; leftedge, 
                        topedge:INTEGER; width, height : CARDINAL);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,gl);
  SETREG(D0,LONG(dataentry));
  SETREG(D1,LONG(leftedge));
  SETREG(D2,LONG(topedge));
  SETREG(D3,LONG(width));
  SETREG(D4,LONG(height));
  INLINE(JSRA6,LVOIModifyGadget);
END IModifyGadget;

PROCEDURE ISetGadgetAttributes(gl:ADDRESS; dataentry:CARDINAL;
                              flagmask, flagbits:LONGCARD;
                              data1, data2:LONGINT; data3:ADDRESS):LONGCARD;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,gl);
  SETREG(D0,LONG(dataentry));
  SETREG(D1,flagmask);
  SETREG(D2,flagbits);
  SETREG(D3,data1);
  SETREG(D4,data2);
  SETREG(A1,data3);
  INLINE(JSRA6,LVOISetGadgetAttributes);
  RETURN LONGCARD(REG(D0))
END ISetGadgetAttributes;

PROCEDURE IActivateInputGadget(gl:ADDRESS; dataentry:CARDINAL);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,gl);
  SETREG(D0,LONG(dataentry));
  INLINE(JSRA6,LVOIActivateInputGadget);
END IActivateInputGadget;

PROCEDURE IGadgetAddress(gl:ADDRESS; dataentry:CARDINAL):GadgetPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,gl);
  SETREG(D0,LONG(dataentry));
  INLINE(JSRA6,LVOIGadgetAddress);
  RETURN GadgetPtr(REG(D0))
END IGadgetAddress;

PROCEDURE IRemoveGadgets(gl:ADDRESS):WindowPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,gl);
  INLINE(JSRA6,LVOIRemoveGadgets);
  RETURN WindowPtr(REG(D0))
END IRemoveGadgets;

PROCEDURE IGetMsg(uport:MsgPortPtr):IntuiMessagePtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,uport);
  INLINE(JSRA6,LVOIGetMsg);
  RETURN IntuiMessagePtr(REG(D0))
END IGetMsg;

PROCEDURE IReplyMsg(imsg:IntuiMessagePtr);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,imsg);
  INLINE(JSRA6,LVOIReplyMsg);
END IReplyMsg;

PROCEDURE IAutoRequest(reqwin:WindowPtr; title,  bodytext, postext, 
                       negtext:ADDRESS; posidcmpflags,
                       negidcmpflags:IDCMPFlagsSet; reqflags:CARDINAL;
                       languagetextarray:DADDRESS):BOOLEAN;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,reqwin);
  SETREG(A1,title);
  SETREG(A2,bodytext);
  SETREG(A3,postext);
  SETREG(D0,negtext);
  SETREG(D1,posidcmpflags);
  SETREG(D2,negidcmpflags);
  SETREG(D3,LONG(reqflags));
  SETREG(D4,languagetextarray);
  INLINE(JSRA6,LVOIAutoRequest);
  RETURN BOOLEAN(REG(D0))
END IAutoRequest;

PROCEDURE IDisplayRequester(reqwin:WindowPtr; rd:RequesterDataPtr;
                            languagetextarray:DADDRESS):ADDRESS;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,reqwin);
  SETREG(A1,rd);
  SETREG(A2,languagetextarray);
  INLINE(JSRA6,LVOIDisplayRequester);
  RETURN ADDRESS(REG(D0))
END IDisplayRequester;

PROCEDURE IRemoveRequester(rl:ADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,rl);
  INLINE(JSRA6,LVOIRemoveRequester);
END IRemoveRequester;

PROCEDURE ICreateMenu(ri:ADDRESS; win:WindowPtr; md:MenuDataPtr;
                      ta:TextAttrPtr; languagetextarray:DADDRESS):ADDRESS;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ri);
  SETREG(A1,win);
  SETREG(A2,md);
  SETREG(A3,ta);
  SETREG(D0,languagetextarray);
  INLINE(JSRA6,LVOICreateMenu);
  RETURN ADDRESS(REG(D0))
END ICreateMenu;

PROCEDURE IAttachMenu(win:WindowPtr; ml:ADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,win);
  SETREG(A1,ml);
  INLINE(JSRA6,LVOIAttachMenu)
END IAttachMenu;

PROCEDURE IMenuItemAddress(ml:ADDRESS; menunum:CARDINAL):MenuItemPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ml);
  SETREG(D0,LONG(menunum));
  INLINE(JSRA6,LVOIMenuItemAddress);
  RETURN MenuItemPtr(REG(D0))
END IMenuItemAddress;

PROCEDURE IRemoveMenu(ml:ADDRESS):WindowPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ml);
  INLINE(JSRA6,LVOIRemoveMenu);
  RETURN WindowPtr(REG(D0))
END IRemoveMenu;

PROCEDURE IFreeMenu(ml:ADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,ml);
  INLINE(JSRA6,LVOIFreeMenu);
END IFreeMenu;

PROCEDURE IOpenTextFile(name:ADDRESS; readbuffersize, linebuffersize,
                        flags:CARDINAL):FileDataPtr;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,name);
  SETREG(D0,LONG(readbuffersize));
  SETREG(D1,LONG(linebuffersize));
  SETREG(D2,LONG(flags));
  INLINE(JSRA6,LVOIOpenTextFile);
  RETURN FileDataPtr(REG(D0))
END IOpenTextFile;

PROCEDURE IReadTextLine(fd:FileDataPtr):INTEGER;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,fd);
  INLINE(JSRA6,LVOIReadTextLine);
  RETURN INTEGER(REG(D0))
END IReadTextLine;

PROCEDURE ICloseTextFile(fd:FileDataPtr);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,fd);
  INLINE(JSRA6,LVOICloseTextFile);
END ICloseTextFile;

PROCEDURE IBuildLanguageTextArray(name:ADDRESS; entries:CARDINAL):DADDRESS;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,name);
  SETREG(D0,LONG(entries));
  INLINE(JSRA6,LVOIBuildLanguageTextArray);
  RETURN DADDRESS(REG(D0))
END IBuildLanguageTextArray;

PROCEDURE IGetLanguageText(text:ADDRESS; textarray:DADDRESS):ADDRESS;

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,text);
  SETREG(A1,textarray);
  INLINE(JSRA6,LVOIGetLanguageText);
  RETURN ADDRESS(REG(D0))
END IGetLanguageText;

PROCEDURE IFreeLanguageTextArray(textarray:DADDRESS);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,textarray);
  INLINE(JSRA6,LVOIFreeLanguageTextArray);
END IFreeLanguageTextArray;

PROCEDURE IChangeMousePointer(win:WindowPtr; pd:PointerDataPtr);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,win);
  SETREG(A1,pd);
  INLINE(JSRA6,LVOIChangeMousePointer);
END IChangeMousePointer;

PROCEDURE IRestoreMousePointer(win:WindowPtr);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,win);
  INLINE(JSRA6,LVOIRestoreMousePointer);
END IRestoreMousePointer;

PROCEDURE IMoveMousePointer(win:WindowPtr; x,y:INTEGER; button:BOOLEAN);

BEGIN
  SETREG(A6,IntuiSupBase);
  SETREG(A0,win);
  SETREG(D0,LONG(x));
  SETREG(D1,LONG(y));
  SETREG(D2,LONG(button));
  INLINE(JSRA6,LVOIMoveMousePointer);
END IMoveMousePointer;

(* ------------------------- Funciones de apoyo --------------------------*)

PROCEDURE InputAutoActive(next,prev:LONGINT):LONGINT;
 (* macro *)

BEGIN
  RETURN next*M+prev
END InputAutoActive;

PROCEDURE InitIntuiSupLibNoVer():BOOLEAN;

VAR
  result :BOOLEAN;

BEGIN
  result := FALSE;
  IntuiSupBase := OpenLibrary(ADR(IntuiSupName),0);
  IF (IntuiSupBase # NIL) THEN
     result := TRUE
  END;
  RETURN result
END InitIntuiSupLibNoVer;

PROCEDURE InitIntuiSupLib():BOOLEAN;

VAR
  result :BOOLEAN;

BEGIN
  result := FALSE;
  IntuiSupBase := OpenLibrary(ADR(IntuiSupName),IntuiSupVersion);
  IF (IntuiSupBase # NIL) THEN
     result := TRUE
  END;
  RETURN result
END InitIntuiSupLib;

PROCEDURE CloseIntuiSupLib();

BEGIN
  CloseLibrary(IntuiSupBase^);
  IntuiSupBase := NIL;
END CloseIntuiSupLib;

BEGIN
  IntuiSupBase := NIL
END IntuiSupInterface.
