home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma28.dms / ma28.adf / MonED / moned.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  26KB  |  1,014 lines

  1. /*
  2. **    $VER: MonED  Release V3 (29.01.94)
  3. **
  4. **    Monitor Specs Editor , for changing monitor spec details such as syncs!
  5. **
  6. **  Programmed by : Raul A. Sobon.
  7. **
  8. **    (C) Copyright 1993 PRoJeCT-23, Inc.
  9. **        All Rights Reserved
  10. **
  11. **
  12. **
  13. **
  14. */
  15.  
  16.  
  17. #include <exec/types.h>
  18. #include <exec/memory.h>
  19. #include <exec/execbase.h>
  20.  
  21. #include <dos/dos.h>
  22. #include <dos/dosextens.h>
  23. #include <dos/stdio.h>                // dos stdio
  24.  
  25. #include <graphics/gfxbase.h>
  26. #include <graphics/monitor.h>
  27. #include <graphics/modeid.h>
  28. #include <intuition/classes.h>
  29. #include <intuition/gadgetclass.h>
  30. #include <intuition/intuitionbase.h>
  31.  
  32. #include "MonED_globals.h"            // my private data
  33.  
  34. #include <proto/exec.h>                // use amiga library stuff
  35. #include <proto/dos.h>
  36. #include <proto/graphics.h>
  37. #include <proto/intuition.h>
  38. #include <proto/gadtools.h> 
  39. #include <proto/diskfont.h> 
  40. #include <proto/asl.h>
  41. #include <proto/icon.h>
  42.  
  43. #include <stdio.h>                    // and the thing we all use!
  44. #include <stdlib.h>
  45. #include <string.h>
  46. #include <dos.h>
  47.  
  48. #define TOOLS_IDCMP            ARROWIDCMP | BUTTONIDCMP | CHECKBOXIDCMP |\
  49.                              INTEGERIDCMP | LISTVIEWIDCMP | MXIDCMP |\
  50.                              CYCLEIDCMP | PALETTEIDCMP | SCROLLERIDCMP |\
  51.                              SLIDERIDCMP | STRINGIDCMP
  52.  
  53. extern    void DOMonitor( APTR );
  54.  
  55.  
  56. BOOL    Monitor_Editable = TRUE;
  57.  
  58.  
  59. ULONG            IClass;
  60. UWORD            Qualifier, Code, Prev_Code;
  61. struct Gadget    *IObject;
  62. APTR            MainVisualInfo;
  63. struct TextAttr thinpaz8 = {
  64.     ( STRPTR )"thinpaz.font", 8, 0x00, 0x00 };
  65. struct TextAttr    Topaz80 = {
  66.     ( STRPTR )"topaz.font", 8, 0x00, 0x00 };
  67.  
  68. struct Screen    *MainScreen;
  69. struct TextFont    *thinpazfont8;
  70.  
  71. struct    MonitorSpec    *currmonitor;
  72. struct    MonitorSpec    oldmonitor;
  73. struct    SpecialMonitor    oldspecial;
  74.  
  75. #include    "MonED_rev.h"
  76. static    UBYTE    verstr[]={ VERSTAG };
  77.  
  78.  
  79.  
  80. /*
  81.  * --- All my requesters use these tags
  82.  */
  83. struct TagItem                ReqTags[] = {
  84.     WA_Left,                50l,
  85.     WA_Top,                    50l,
  86.     WA_Width,                330l,
  87.     WA_Height,                186l,
  88.     WA_IDCMP,                IDCMP_CLOSEWINDOW | TOOLS_IDCMP | IDCMP_VANILLAKEY | IDCMP_REFRESHWINDOW,
  89.     WA_Flags,                WFLG_DRAGBAR | WFLG_DEPTHGADGET| WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_RMBTRAP | WFLG_SMART_REFRESH | WFLG_GIMMEZEROZERO,
  90.     WA_Gadgets,                0l,
  91.     WA_Title,                0l,
  92.     WA_AutoAdjust,            TRUE,
  93.     WA_CustomScreen,        0l,
  94.     TAG_DONE };
  95.  
  96. /*
  97.  * --- window gadget ID's
  98.  */
  99. #define GD_HBSTRT    1
  100. #define GD_HSSTRT    2
  101. #define GD_HSSTOP    3
  102. #define GD_HBSTOP    4
  103. #define GD_VBSTRT    5
  104. #define GD_VSSTRT    6
  105. #define GD_VSSTOP    7
  106. #define GD_VBSTOP    8
  107. #define GD_TOTROWS    9
  108. #define GD_TOTCLKS    10
  109. #define GD_SAVE        50
  110. #define GD_USE        51
  111. #define GD_CANCEL    52
  112. #define GD_JUMP        53
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. /*
  120.  * --- Program gadget pointers that needs to be changed.
  121.  */
  122. struct Window            *sp_Wnd    = NULL;
  123. struct Gadget
  124.                         *sp_HBSTRT,
  125.                         *sp_HSSTRT,
  126.                         *sp_HSSTOP,
  127.                         *sp_HBSTOP,
  128.                         *sp_VBSTRT,
  129.                         *sp_VSSTRT,
  130.                         *sp_VSSTOP,
  131.                         *sp_VBSTOP,
  132.                         *sp_TOTROWS,
  133.                         *sp_TOTCLKS;
  134.  
  135. struct Gadget            *sp_GList = NULL;
  136. struct Gadget            *g;
  137. struct NewGadget        ng;
  138. UBYTE                    *sp_Title = "MonitorSpec Ed V3a (Raul. A. Sobon)";
  139.  
  140. /*
  141.  * --- TagItems for the slider gadgets.
  142.  */
  143. struct TagItem  sp_HsyncTags[] = {
  144.     GTSL_LevelFormat,        (ULONG)"%03lx",
  145.     GTSL_MaxLevelLen,        3L,
  146.     GTSL_Min,                0L,
  147.     GTSL_Max,                64L,
  148.     GA_Disabled,            FALSE,
  149.     TAG_DONE };
  150.  
  151. struct TagItem  sp_VsyncTags[] = {
  152.     GTSL_LevelFormat,        (ULONG)"%04lx",
  153.     GTSL_MaxLevelLen,        4L,
  154.     GTSL_Min,                0L,
  155.     GTSL_Max,                8000L,
  156.     GA_Disabled,            FALSE,
  157.     TAG_DONE };
  158.  
  159. struct TagItem  sp_RowTags[] = {
  160.     GTSL_LevelFormat,        (ULONG)"%03lx",
  161.     GTSL_MaxLevelLen,        3L,
  162.     GTSL_Min,                0L,
  163.     GTSL_Max,                768L,
  164.     GA_Disabled,            FALSE,
  165.     TAG_DONE };
  166.  
  167. struct TagItem  sp_TotClkTags[] = {
  168.     GTSL_LevelFormat,        (ULONG)"%03lx",
  169.     GTSL_MaxLevelLen,        3L,
  170.     GTSL_Min,                1L,
  171.     GTSL_Max,                768L,
  172.     GA_Disabled,            FALSE,
  173.     TAG_DONE };
  174.  
  175.  
  176. ULONG        version=30;
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. VOID __stdargs ShowFault(LONG code,char *header)
  185. {
  186.     struct EasyStruct EasyStruct;
  187.  
  188.     char ErrorString[80];
  189.  
  190.     EasyStruct.es_StructSize = sizeof(struct EasyStruct);
  191.     EasyStruct.es_Flags = NULL;
  192.     EasyStruct.es_Title = "MonitorSpec Ed";
  193.     EasyStruct.es_GadgetFormat = "Ok";
  194.  
  195.     if(!code)
  196.         EasyStruct.es_TextFormat = header;
  197.     else
  198.     {
  199.         Fault(code,header,ErrorString,80);
  200.  
  201.         EasyStruct.es_TextFormat = ErrorString;
  202.     }
  203.  
  204.     EasyRequest(NULL,&EasyStruct,NULL,NULL);
  205. }
  206.  
  207.  
  208.  
  209. void SetAllProps( void ){
  210.     if( currmonitor ){
  211.         if( currmonitor->ms_Special ){
  212.             GT_SetGadgetAttrs( sp_HBSTRT, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->hblank.asi_Start , TAG_DONE );
  213.             GT_SetGadgetAttrs( sp_HSSTRT, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->hsync.asi_Start , TAG_DONE );
  214.             GT_SetGadgetAttrs( sp_HSSTOP, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->hsync.asi_Stop , TAG_DONE );
  215.             GT_SetGadgetAttrs( sp_HBSTOP, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->hblank.asi_Stop , TAG_DONE );
  216.             GT_SetGadgetAttrs( sp_VBSTRT, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->vblank.asi_Start , TAG_DONE );
  217.             GT_SetGadgetAttrs( sp_VSSTRT, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->vsync.asi_Start , TAG_DONE );
  218.             GT_SetGadgetAttrs( sp_VSSTOP, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->vsync.asi_Stop , TAG_DONE );
  219.             GT_SetGadgetAttrs( sp_VBSTOP, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->vblank.asi_Stop , TAG_DONE );
  220.         }
  221.         GT_SetGadgetAttrs( sp_TOTROWS, sp_Wnd, NULL, GTSL_Level,currmonitor->total_rows , TAG_DONE );
  222.         GT_SetGadgetAttrs( sp_TOTCLKS, sp_Wnd, NULL, GTSL_Level,currmonitor->total_colorclocks , TAG_DONE );
  223.     }
  224. }
  225.  
  226.  
  227. /*
  228.  * --- Reads a message from the window message port.
  229.  * --- Returns TRUE if a message was read and puts the
  230.  * --- message data in the globals. Return FALSE if there
  231.  * --- was no message at the port.
  232.  */
  233. long ReadIMsg( struct Window *iwnd )
  234. {
  235.     struct IntuiMessage *imsg;
  236.  
  237.     if ( imsg = GT_GetIMsg( iwnd->UserPort )) {
  238.  
  239.         IClass      =    imsg->Class;
  240.         Qualifier    =    imsg->Qualifier;
  241.         Code        =    imsg->Code;
  242.         IObject     =    imsg->IAddress;
  243.  
  244.         GT_ReplyIMsg( imsg );
  245.  
  246.         return TRUE;
  247.     }
  248.     return FALSE;
  249. }
  250.  
  251.  
  252.  
  253. /*
  254.  * --- Clears all message from a message port.
  255.  */
  256. void ClearMsgPort( struct MsgPort *mport )
  257. {
  258.     struct IntuiMessage  *msg;
  259.  
  260.     while ( msg = GT_GetIMsg( mport )) GT_ReplyIMsg( msg );
  261. }
  262.  
  263.  
  264.  
  265.  
  266.  
  267. /*
  268.  * --- Open lots of libraries that I need.
  269.  */
  270. long OpenLibraries( void ){
  271.  
  272.     if ( !(IconBase = (struct Library *) OpenLibrary((UBYTE *) "icon.library" , 36l ))) {
  273.         WriteStr("\ticon.library\n");
  274.         return FALSE;
  275.         }
  276.  
  277.     if ( !(GfxBase = (struct GfxBase *) OpenLibrary((UBYTE *) "graphics.library" , 36l ))) {
  278.         WriteStr("\tgraphics.library\n");
  279.         return FALSE;
  280.         }
  281.  
  282.     if ( !(DosBase = (struct DosBase *) OpenLibrary((UBYTE *) "dos.library", 36l ))) {
  283.         WriteStr("\tdos.library\n");
  284.         return FALSE;
  285.         }
  286.  
  287.     if ( !(IntuitionBase = (struct IntuitionBase *) OpenLibrary((UBYTE *) "intuition.library", 36l ))) {
  288.         WriteStr("\tintuition.library\n");
  289.         return FALSE;
  290.         }
  291.  
  292.     if ( !(AslBase = (struct Library *) OpenLibrary((UBYTE *) "asl.library", 37l ))) {
  293.         WriteStr("\tasl.library\n");
  294.         return FALSE;
  295.         }
  296.  
  297.     if ( !(GadToolsBase = (struct Library *) OpenLibrary((UBYTE *) "gadtools.library", 36l ))) {
  298.         WriteStr("\tgadtools.library\n");
  299.         return FALSE;
  300.         }
  301.  
  302.     if ( !(DiskFontBase = (struct Library *) OpenLibrary((UBYTE *) "diskfont.library", 36l ))) {
  303.         WriteStr("\tdiskfont.library\n");
  304.         return FALSE;
  305.         }
  306.  
  307.     return TRUE;
  308. }
  309.  
  310.  
  311.  
  312.  
  313. /*
  314.  * --- Close the libraries which are opened by me.
  315.  */
  316. void CloseLibraries( void ){
  317.     if (DiskFontBase)    CloseLibrary( (struct Library *) DiskFontBase );
  318.     if (GadToolsBase)    CloseLibrary( (struct Library *) GadToolsBase );
  319.     if (AslBase)        CloseLibrary( (struct Library *) AslBase );
  320.     if (IntuitionBase)    CloseLibrary( (struct Library *) IntuitionBase );
  321.     if (DosBase)        CloseLibrary( (struct Library *) DosBase );
  322.     if (GfxBase)        CloseLibrary( (struct Library *) GfxBase );
  323.     if (IconBase)        CloseLibrary( (struct Library *) IconBase );
  324. }
  325.  
  326.  
  327. void SaveMonitor( void ){
  328.     if( currmonitor ){
  329.         CopyMem(  currmonitor, &oldmonitor, sizeof( struct MonitorSpec) );
  330.         if( currmonitor->ms_Special )
  331.             CopyMem(  currmonitor->ms_Special, &oldspecial, sizeof( struct SpecialMonitor ) );
  332.     }
  333. }
  334.  
  335.  
  336. void RestoreMonitor( void ){
  337.     if( currmonitor ){
  338.         CopyMem(  &oldmonitor, currmonitor,  sizeof( struct MonitorSpec) );
  339.         if( currmonitor->ms_Special )
  340.             CopyMem(  &oldspecial, currmonitor->ms_Special, sizeof( struct SpecialMonitor ) );
  341.     }
  342. }
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349. static    UBYTE    mon[16];
  350.  
  351.  
  352. void SaveDetails( void ){
  353.     struct    DiskObject *diskobj;
  354.     UBYTE    tt[6][16]={
  355.                         "TOTROWS=0x00",
  356.                         "TOTCLKS=0x00",
  357.                          "HBSTRT=0x00",
  358.                         "HBSTOP=0x00",
  359.                         "VBSTRT=0x00",
  360.                         "VBSTOP=0x00"  };
  361.     UBYTE    *txtptrs[8];
  362.     UBYTE    **oldtxtptrs;
  363.     UBYTE    monname[35];
  364.  
  365.     if( currmonitor ){
  366.         sprintf( monname,"DEVS:Monitors/%s",mon );
  367.         if ( diskobj=GetDiskObject( monname ) ){
  368.             oldtxtptrs = diskobj->do_ToolTypes;
  369.  
  370.             sprintf( &tt[0][10],"%02x",currmonitor->total_rows);
  371.             sprintf( &tt[1][10],"%02x",currmonitor->total_colorclocks);
  372.             txtptrs[0] = &tt[0][0];
  373.             txtptrs[1] = &tt[1][0];
  374.  
  375.             if( currmonitor->ms_Special ){
  376.                 sprintf( &tt[2][9],"%02x", currmonitor->ms_Special->hblank.asi_Start );
  377.                 sprintf( &tt[3][9],"%02x", currmonitor->ms_Special->hblank.asi_Stop );
  378.                 sprintf( &tt[4][9],"%02x", currmonitor->ms_Special->vblank.asi_Start );
  379.                 sprintf( &tt[5][9],"%02x", currmonitor->ms_Special->vblank.asi_Stop );
  380.                 txtptrs[2] = &tt[2][0];
  381.                 txtptrs[3] = &tt[3][0];
  382.                 txtptrs[4] = &tt[4][0];
  383.                 txtptrs[5] = &tt[5][0];
  384.                 txtptrs[6] = NULL;
  385.             }
  386.             else
  387.                 txtptrs[2] = NULL;
  388.  
  389.             diskobj->do_ToolTypes = txtptrs;
  390.             if( !PutDiskObject( monname, diskobj ) )
  391.                 ShowFault(IoErr(),"icon.library/PutDiskObject()");
  392.  
  393.             diskobj->do_ToolTypes = oldtxtptrs;
  394.             FreeDiskObject( diskobj );
  395.         }
  396.         else
  397.             ShowFault(IoErr(),"icon.library/GetDiskObject()");
  398.     }
  399.     else
  400.         ShowFault(NULL,"Invalid monitor in use");
  401. }
  402.  
  403.  
  404.  
  405.  
  406.  
  407.  
  408.  
  409. void UpDateMonitor( void ){
  410.     if( currmonitor ){
  411.         if( currmonitor->ms_Special ){
  412.             if( currmonitor->ms_Special->do_monitor ) {
  413.                 DOMonitor( currmonitor );
  414.                 MakeScreen( (struct Screen *)MainScreen );
  415.                 RethinkDisplay();
  416.             }
  417.         }
  418.     }
  419. }
  420.  
  421.  
  422.  
  423. #define    PICASSO_MONITOR_ID    0x000f1000
  424. #define    EGS24_MONITOR_ID    0x04001000
  425.  
  426. void UpDateDisplay( void ){
  427.     UBYTE    tstr[40];
  428.     ULONG    rows=0,clks=0,fps,scan,mode;
  429.  
  430.     if( currmonitor ){
  431.         rows = currmonitor->total_rows;
  432.         clks = currmonitor->total_colorclocks;
  433.     }
  434.     if( rows && clks )
  435.         fps = abs(1000000000/(rows*clks*280));
  436.     else
  437.         fps = 0;
  438.     scan = fps*rows;
  439.  
  440.     mode = GetVPModeID(&IntuitionBase->ActiveScreen->ViewPort)&MONITOR_ID_MASK;
  441.  
  442.     switch( (ULONG)(mode) ) {
  443.         case NTSC_MONITOR_ID:        sprintf(mon,"NTSC");break;
  444.         case PAL_MONITOR_ID:        sprintf(mon,"PAL");break;
  445.         case VGA_MONITOR_ID:        sprintf(mon,"Multiscan");break;
  446.         case A2024_MONITOR_ID:        sprintf(mon,"A2024");break;
  447.         case PROTO_MONITOR_ID:        sprintf(mon,"PROTO");break;
  448.         case EURO72_MONITOR_ID:        sprintf(mon,"EURO72");break;
  449.         case EURO36_MONITOR_ID:        sprintf(mon,"EURO36");break;
  450.         case SUPER72_MONITOR_ID:    sprintf(mon,"SUPER72");break;
  451.         case DBLNTSC_MONITOR_ID:
  452.             if( version >= 39 )    sprintf(mon,"DBLNTSC"); else     sprintf(mon,"DoubleNTSC");
  453.             break;
  454.         case DBLPAL_MONITOR_ID:
  455.             if( version >= 39 )    sprintf(mon,"DBLPAL"); else     sprintf(mon,"DoublePAL");
  456.             break;
  457.         case PICASSO_MONITOR_ID:    sprintf(mon,"PICASSO");break;
  458.         case EGS24_MONITOR_ID:        sprintf(mon,"EGS-SPECTRUM");break;
  459.         case DEFAULT_MONITOR_ID:    sprintf(mon,"PAL");break;
  460.         default:                    sprintf(mon,"CUSTOM(%4x)",mode);break;
  461.     }
  462.  
  463.     sprintf(tstr,"%s:  %02d.%02d Khz, %02d Hz       ",mon,scan/1000,(scan%1000)*10,fps );
  464.     if( sp_Wnd ){
  465.         SetAPen( sp_Wnd->RPort, 2 );
  466.         Move( sp_Wnd->RPort, 9, 136 );
  467.         Text( sp_Wnd->RPort, tstr, strlen(tstr) );
  468. //        printf( "*** %s",tstr );
  469.     }
  470.     else
  471.         printf( "%s.\n", tstr );
  472.  
  473.     UpDateMonitor();
  474. }
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481. /**********************************************************************
  482.  *
  483.  *                        Draw3DOutBox
  484.  *    Description : just like normal bevelbox except inside color is selectable
  485.  *                  plus it looks MONUMENTAL!
  486.  *                                ¯¯¯¯¯¯¯¯¯¯¯
  487.  *  Returns        : NULL
  488.  *    Globals        : usual
  489.  *
  490.  */
  491. void Draw3DBox(
  492.     struct    RastPort *rp,        // window rastport to draw into
  493.     UWORD    xpos,                // X coordinate to place MEGA-BEVEL
  494.     UWORD    ypos,                // Y coordinate to place MEGA-BEVEL
  495.     UWORD    xsize,                // X size of MEGA-BEVEL
  496.     UWORD    ysize,                // X size of MEGA-BEVEL
  497.     UWORD    shine_pen,            // top-left pen
  498.     UWORD    body_pen,            // central pen
  499.     UWORD    shadow_pen            // bot-right pen
  500. ){
  501.  
  502. #define    LineDraw(x,y,x2,y2)    Move( rp, x , y); \
  503.                             Draw( rp, x2, y2 )
  504.  
  505.     xsize--;ysize--;
  506.  
  507.     if( body_pen == 0xffff )
  508.         SetAPen( rp, shine_pen );
  509.     else {
  510.         SetAPen( rp, body_pen );
  511.         RectFill( rp, xpos, ypos, xpos+xsize, ypos+ysize);
  512.     }
  513.  
  514.     LineDraw( xpos, ypos, xpos+1, ypos+1 );
  515.     LineDraw( xpos+xsize-1, ypos+ysize-1, xpos+xsize, ypos+ysize );
  516.  
  517.     SetAPen( rp, shine_pen );
  518.     LineDraw( xpos+0, ypos+0, xpos+xsize-1, ypos );
  519.     LineDraw( xpos+0, ypos+1, xpos+xsize-2, ypos+1 );
  520.     LineDraw( xpos+0, ypos+0, xpos, ypos+ysize-1 );
  521.     LineDraw( xpos+1, ypos+0, xpos+1, ypos+ysize-2 );
  522.  
  523.     SetAPen( rp, shadow_pen );
  524.     LineDraw( xpos+1, ypos+ysize-0, xpos+xsize-1, ypos+ysize-0 );
  525.     LineDraw( xpos+2, ypos+ysize-1, xpos+xsize-2, ypos+ysize-1 );
  526.     LineDraw( xpos+xsize-0, ypos+1, xpos+xsize-0, ypos+ysize-1 );
  527.     LineDraw( xpos+xsize-1, ypos+2, xpos+xsize-1, ypos+ysize-2 );
  528.  
  529.     SetAPen( rp, 2 );
  530.     if( shine_pen == shadow_pen ){
  531.         SetAPen( rp, shine_pen );
  532.         LineDraw( xpos, ypos+ysize, xpos+1, ypos+ysize-1 );
  533.         LineDraw( xpos+xsize-1, ypos+1, xpos+xsize, ypos );
  534.     }
  535.     else
  536.     if(shine_pen > shadow_pen ){
  537.         LineDraw( xpos+0, ypos+0, xpos+2, ypos+0 );
  538.         LineDraw( xpos+0, ypos+0, xpos+0, ypos+2 );
  539.     }
  540.     else {
  541.         LineDraw( xpos+xsize, ypos+ysize, xpos+xsize-2, ypos+ysize );
  542.         LineDraw( xpos+xsize, ypos+ysize, xpos+xsize-0, ypos+ysize-2 );
  543.     }
  544. }
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551. /**********************************************************************
  552.  *
  553.  *                        Draw3DLine
  554.  *    Description : just like normal line except its 3D (sorta!) (horizontal)
  555.  *                  plus it looks MONUMENTAL!
  556.  *                                ¯¯¯¯¯¯¯¯¯¯¯
  557.  *  Returns        : NULL
  558.  *    Globals        : usual
  559.  *
  560.  */
  561. void Draw3DLine(
  562.     struct    RastPort *rp,        // window rastport to draw into
  563.     UWORD    xpos,                // X coordinate to place MEGA-BEVEL
  564.     UWORD    ypos,                // Y coordinate to place MEGA-BEVEL
  565.     UWORD    xsize,                // X size of MEGA-BEVEL
  566.     UWORD    shine_pen,            // top-left pen
  567.     UWORD    shadow_pen            // bot-right pen
  568. ){
  569.  
  570.     xsize--;
  571.  
  572.     SetAPen( rp, shine_pen );
  573.     LineDraw( xpos+0, ypos+0, xpos+xsize, ypos+0 );
  574.     SetAPen( rp, shadow_pen );
  575.     LineDraw( xpos+0, ypos+1, xpos+xsize, ypos+1 );
  576. }
  577.  
  578.  
  579.  
  580. long OpenDisplay( void ){
  581.     WORD    offy,x1,y1,w,h;
  582.  
  583.     ReqTags[7].ti_Data = (ULONG)sp_Title;
  584.     ReqTags[9].ti_Data = (Tag)MainScreen;
  585.  
  586.     if ( ! (thinpazfont8  = OpenDiskFont( &thinpaz8 )) ) {
  587.             thinpazfont8  = OpenDiskFont( &Topaz80 );
  588.         }
  589.  
  590.     currmonitor = GfxBase->current_monitor;
  591.  
  592.     SaveMonitor();
  593.  
  594.     if ( currmonitor ){
  595.         sp_RowTags[4].ti_Data = FALSE;
  596.         sp_TotClkTags[4].ti_Data = FALSE;
  597.         Monitor_Editable = TRUE;
  598.     }
  599.     else {
  600.         sp_RowTags[4].ti_Data = TRUE;
  601.         sp_TotClkTags[4].ti_Data = TRUE;
  602.         Monitor_Editable = FALSE;
  603.     }
  604.  
  605.     if ( currmonitor && currmonitor->ms_Special ){
  606.         sp_HsyncTags[4].ti_Data = FALSE;
  607.         sp_VsyncTags[4].ti_Data = FALSE;
  608.         Monitor_Editable = TRUE;
  609.     }
  610.     else {
  611.         sp_HsyncTags[4].ti_Data = TRUE;
  612.         sp_VsyncTags[4].ti_Data = TRUE;
  613.         Monitor_Editable = FALSE;
  614.     }
  615.  
  616.         
  617.  
  618.     if ( ! ( MainVisualInfo = GetVisualInfo( MainScreen, TAG_DONE )))
  619.         return( 2L );
  620.  
  621. #define YSTEP 12
  622.  
  623.     if ( g = CreateContext( &sp_GList )) {
  624.  
  625.         ng.ng_LeftEdge        =    89;
  626.         ng.ng_TopEdge        =    5;
  627.         ng.ng_Width            =    216;
  628.         ng.ng_Height        =    10;
  629.         ng.ng_GadgetText    =    "HBSTRT:    ";
  630.         ng.ng_TextAttr        =    &thinpaz8;
  631.         ng.ng_GadgetID        =    GD_HBSTRT;
  632.         ng.ng_Flags            =    PLACETEXT_LEFT | NG_HIGHLABEL;
  633.         ng.ng_VisualInfo    =    MainVisualInfo;
  634.         ng.ng_UserData        =    NULL;
  635.         sp_HBSTRT = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_HsyncTags );
  636.  
  637.         ng.ng_TopEdge        +=    YSTEP;
  638.         ng.ng_GadgetText    =    "HSSTRT:    ";
  639.         ng.ng_GadgetID      =    GD_HSSTRT;
  640.         sp_HSSTRT = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_HsyncTags );
  641.  
  642.         ng.ng_TopEdge        +=    YSTEP;
  643.         ng.ng_GadgetText    =    "HSSTOP:    ";
  644.         ng.ng_GadgetID      =    GD_HSSTOP;
  645.         sp_HSSTOP = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_HsyncTags );
  646.  
  647.         ng.ng_TopEdge        +=    YSTEP;
  648.         ng.ng_GadgetText    =    "HBSTOP:    ";
  649.         ng.ng_GadgetID      =    GD_HBSTOP;
  650.         sp_HBSTOP = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_HsyncTags );
  651.  
  652.         ng.ng_TopEdge        +=    YSTEP;
  653.         ng.ng_GadgetText    =    "TOTCLKS:    ";
  654.         ng.ng_GadgetID      =    GD_TOTCLKS;
  655.         sp_TOTCLKS = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_TotClkTags );
  656.  
  657.         ng.ng_TopEdge        +=    YSTEP;
  658.         ng.ng_GadgetText    =    "VBSTRT:    ";
  659.         ng.ng_GadgetID      =    GD_VBSTRT;
  660.         sp_VBSTRT = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_VsyncTags );
  661.  
  662.         ng.ng_TopEdge        +=    YSTEP;
  663.         ng.ng_GadgetText    =    "VSSTRT:    ";
  664.         ng.ng_GadgetID      =    GD_VSSTRT;
  665.         sp_VSSTRT = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_VsyncTags );
  666.  
  667.         ng.ng_TopEdge        +=    YSTEP;
  668.         ng.ng_GadgetText    =    "VSSTOP:    ";
  669.         ng.ng_GadgetID      =    GD_VSSTOP;
  670.         sp_VSSTOP = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_VsyncTags );
  671.  
  672.         ng.ng_TopEdge        +=    YSTEP;
  673.         ng.ng_GadgetText    =    "VBSTOP:    ";
  674.         ng.ng_GadgetID      =    GD_VBSTOP;
  675.         sp_VBSTOP = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_VsyncTags );
  676.  
  677.         ng.ng_TopEdge        +=    YSTEP;
  678.         ng.ng_GadgetText    =    "TOTROWS:    ";
  679.         ng.ng_GadgetID      =    GD_TOTROWS;
  680.         sp_TOTROWS = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_RowTags );
  681.  
  682.  
  683.  
  684.     y1=    ng.ng_TopEdge        =    142;
  685.     x1=    ng.ng_LeftEdge        =    89;
  686.     w=    ng.ng_Width            =    50;
  687.     h=    ng.ng_Height        =    14;
  688.         ng.ng_Flags             =    PLACETEXT_IN;
  689.         ng.ng_GadgetText    =    "_USE";
  690.         ng.ng_GadgetID      =    GD_USE;
  691.         g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, (Tag)'_', TAG_DONE );
  692.  
  693.         ng.ng_LeftEdge      =    144;
  694.         ng.ng_GadgetText    =    "_SAVE";
  695.         ng.ng_GadgetID          =    GD_SAVE;
  696.         g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, (Tag)'_', TAG_DONE );
  697.  
  698.         ng.ng_LeftEdge      =    199;
  699.         ng.ng_GadgetText    =    "_CANCEL";
  700.         ng.ng_GadgetID      =    GD_CANCEL;
  701.         g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, (Tag)'_', TAG_DONE );
  702.  
  703.         ng.ng_LeftEdge      =    254;
  704.         ng.ng_GadgetText    =    "_JUMP";
  705.         ng.ng_GadgetID      =    GD_JUMP;
  706.         g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, (Tag)'_', TAG_DONE );
  707.  
  708.  
  709.         if ( g ) {
  710.             //ReqTags[6].ti_Data    =    (Tag)sp_GList;
  711.             offy = MainScreen->WBorTop + MainScreen->RastPort.TxHeight + 1;
  712.             ReqTags[3].ti_Data = 164+offy;
  713.             if ( sp_Wnd = OpenWindowTagList( NULL, ReqTags )) {
  714.                 SetFont( sp_Wnd->RPort, thinpazfont8 );
  715.                 if( MainScreen->BitMap.Depth > 2 ) {
  716.                     Draw3DBox( sp_Wnd->RPort, 0, 0,    sp_Wnd->Width-sp_Wnd->BorderLeft-sp_Wnd->BorderRight,
  717.                         sp_Wnd->Height-sp_Wnd->BorderTop-sp_Wnd->BorderBottom, 2, 3, 1 );
  718.  
  719.                     Draw3DLine( sp_Wnd->RPort, 1, 125,sp_Wnd->Width-sp_Wnd->BorderLeft-sp_Wnd->BorderRight-3, 1, 2 );
  720.  
  721.                     SetAPen( sp_Wnd->RPort, 2 );
  722.                     SetBPen( sp_Wnd->RPort, 3 );
  723.                 }
  724.                 AddGList( sp_Wnd, sp_GList,NULL,NULL,NULL);
  725.                 RefreshGList( sp_GList, sp_Wnd,NULL,NULL);
  726.                 GT_RefreshWindow( sp_Wnd, NULL );
  727.                 SetAllProps();
  728.                 UpDateDisplay();
  729.  
  730.                 Draw3DBox( sp_Wnd->RPort, x1-2, y1-2, w+4, h+4, 1, 0xffff, 1 );
  731.  
  732.             }
  733.             else
  734.                 return NULL;
  735.         }
  736.     }
  737.     return 1;
  738. }
  739.  
  740.  
  741.  
  742.  
  743.  
  744. void CloseDisplay( void ) {
  745.  
  746.     if ( thinpazfont8 )
  747.         CloseFont( thinpazfont8 );
  748.  
  749.     if ( MainVisualInfo ) {
  750.         FreeVisualInfo( MainVisualInfo );
  751.         MainVisualInfo = NULL;
  752.     }
  753.     if ( sp_Wnd )        CloseWindow( sp_Wnd );
  754.     if ( sp_GList )        FreeGadgets( sp_GList );
  755. }
  756.  
  757.  
  758.  
  759.  
  760. LONG xtoi( UBYTE *txt ){
  761.     LONG n;
  762.  
  763.     sscanf( txt,"%x",&n );
  764.  
  765.     return n;
  766. }
  767.  
  768.  
  769.  
  770.  
  771. // ----------------------------------------------------------------------------------------------
  772. int main( int argc,char *argv[] )
  773. {
  774.     BOOL                 running  = TRUE;
  775.  
  776.  
  777.     if( !OpenLibraries() ) {
  778.         ShowFault(NULL,"Libraries cant be opened!");
  779.         CloseLibraries();
  780.         Exit(5);
  781.     }
  782.  
  783.     version=IntuitionBase->LibNode.lib_Version;
  784.  
  785.     MainScreen = (struct Screen *)(IntuitionBase->ActiveScreen);
  786.  
  787.     if( argc>1 ) {
  788.         BOOL update = TRUE;
  789.         currmonitor = GfxBase->current_monitor;
  790.         SaveMonitor();
  791.  
  792.         if( *argv[1] == '?' ){
  793.             puts( "Moned3a, © 1994 Raul Sobon / PRoJeCT-23");
  794.             puts( " moned HBSTRT=0xnnn HBSTOP=0xnnn HBSTOP=0xnnn");
  795.             puts( "       HSSTRT=0xnnn HSSTOP=0xnnn VBSTRT=0xnnn");
  796.             puts( "       VBSTOP=0xnnn VSSTRT=0xnnn VSSTOP=0xnnn");
  797.         //    puts( "       MAXOSC=0xnnn VIDOSC=0xnnn xxxxxx=0xnnn");
  798.             puts( "NOTE: each item is optional and can be in any order and nnn is a hex number.");
  799.         }
  800.         else
  801.         if( currmonitor ){
  802.             WORD count = argc,lp=1;
  803.             UBYTE *cmd,*num;
  804.  
  805.             while( count >1 ){
  806.                 cmd = argv[ lp ];
  807.                 num = cmd+9;
  808. //printf("str=<%s>  n=<%s>=%d\n",cmd,num,xtoi( num ) );
  809.                 if( currmonitor->ms_Special ){
  810.                     if( !strnicmp( "HBSTRT=0x", cmd , 9 ) )    currmonitor->ms_Special->hblank.asi_Start=xtoi( num );
  811.                     else if( !strnicmp( "HBSTOP=0x", cmd , 9 ) )    currmonitor->ms_Special->hblank.asi_Stop=xtoi( num );
  812.                     else if( !strnicmp( "HSSTRT=0x", cmd , 9 ) )    currmonitor->ms_Special->hsync.asi_Start=xtoi( num );
  813.                     else if( !strnicmp( "HSSTOP=0x", cmd , 9 ) )    currmonitor->ms_Special->hsync.asi_Stop=xtoi( num );
  814.                     else if( !strnicmp( "VBSTRT=0x", cmd , 9 ) )    currmonitor->ms_Special->vblank.asi_Start=xtoi( num );
  815.                     else if( !strnicmp( "VBSTOP=0x", cmd , 9 ) )    currmonitor->ms_Special->vblank.asi_Stop=xtoi( num );
  816.                     else if( !strnicmp( "VSSTRT=0x", cmd , 9 ) )    currmonitor->ms_Special->vsync.asi_Start=xtoi( num );
  817.                     else if( !strnicmp( "VSSTOP=0x", cmd , 9 ) )    currmonitor->ms_Special->vsync.asi_Stop=xtoi( num );
  818.                     else update = FALSE;
  819.                 }
  820.                 if( !strnicmp( "TOTROW=0x", cmd , 9 ) )    {
  821.                             currmonitor->total_rows=xtoi( num ); update = TRUE; }
  822.                 else    if( !strnicmp( "TOTCLK=0x", cmd , 9 ) ) {
  823.                             currmonitor->total_colorclocks=xtoi( num ); update = TRUE; }
  824.         //        else    if( !strnicmp( "MAXOSC=0x", cmd , 9 ) ) {
  825.         //                    currmonitor->ms_maxoscan=xtoi( num ); update = TRUE; }
  826.         //        else    if( !strnicmp( "VIDOSC=0x", cmd , 9 ) ) {
  827.         //                    currmonitor->ms_videoscan=xtoi( num ); update = TRUE; }
  828.  
  829.                 lp++; count--;
  830.             }
  831.             if( update ) {
  832.                 UpDateDisplay();
  833.         //        printf("Display updated.\n");
  834.             }
  835.             else
  836.                 printf("argument <%s> invalid?\n",cmd);
  837.         }
  838.     }
  839.     else
  840.     if( OpenDisplay() ) {
  841.         do {
  842.             WaitPort( sp_Wnd->UserPort );
  843.  
  844.             while ( ReadIMsg( sp_Wnd )) {
  845.  
  846.                 switch ( IClass ) {
  847.  
  848.                     case    IDCMP_ACTIVEWINDOW:
  849.                         ClearMsgPort( sp_Wnd->UserPort );
  850.                         break;
  851.  
  852.                     case    IDCMP_REFRESHWINDOW:
  853.                         GT_BeginRefresh( sp_Wnd );
  854.                         GT_EndRefresh( sp_Wnd, TRUE );
  855.                         break;
  856.  
  857.                     case    IDCMP_CLOSEWINDOW:
  858.                         goto Cancel;
  859.                         break;
  860.  
  861.                     case    IDCMP_VANILLAKEY:
  862.                         switch ( Code ) {
  863.                             case    '[':
  864.                                 if( Monitor_Editable ){
  865.                                     GT_SetGadgetAttrs(sp_TOTCLKS,sp_Wnd,0,GTSL_Level,currmonitor->total_colorclocks--,TAG_DONE);
  866.                                     UpDateDisplay();
  867.                                 }
  868.                                 break;
  869.                             case    ']':
  870.                                 if( Monitor_Editable ){
  871.                                     GT_SetGadgetAttrs(sp_TOTCLKS,sp_Wnd,0,GTSL_Level,currmonitor->total_colorclocks++,TAG_DONE);
  872.                                     UpDateDisplay();
  873.                                 }
  874.                                 break;
  875.  
  876.                             case    '{':
  877.                                 if( Monitor_Editable ){
  878.                                     GT_SetGadgetAttrs(sp_TOTROWS,sp_Wnd,0,GTSL_Level,currmonitor->total_rows--,TAG_DONE);
  879.                                     UpDateDisplay();
  880.                                 }
  881.                                 break;
  882.                             case    '}':
  883.                                 if( Monitor_Editable ){
  884.                                     GT_SetGadgetAttrs(sp_TOTROWS,sp_Wnd,0,GTSL_Level,currmonitor->total_rows++,TAG_DONE);
  885.                                     UpDateDisplay();
  886.                                 }
  887.                                 break;
  888.  
  889.                             case    's':
  890.                                 goto Save;
  891.  
  892.                             case    13 :
  893.                             case    'u':
  894.                                 goto Use;
  895.  
  896.                             case    'c':
  897.                                 goto Cancel;
  898.  
  899.                             case    'j':
  900.                                 goto Jump;
  901.                         }
  902.                         break;
  903.  
  904.                     case    IDCMP_MOUSEMOVE:
  905.                         switch ( IObject->GadgetID ) {
  906.                             case    GD_HBSTRT:
  907.                                 if( currmonitor->ms_Special ){
  908.                                     currmonitor->ms_Special->hblank.asi_Start = Code;
  909.                                     UpDateMonitor();
  910.                                 }
  911.                                 break;
  912.                             case    GD_HSSTRT:
  913.                                 if( currmonitor->ms_Special ){
  914.                                     currmonitor->ms_Special->hsync.asi_Start = Code;
  915.                                     UpDateMonitor();
  916.                                 }
  917.                                 break;
  918.                             case    GD_HSSTOP:
  919.                                 if( currmonitor->ms_Special ){
  920.                                     currmonitor->ms_Special->hsync.asi_Stop = Code;
  921.                                     UpDateMonitor();
  922.                                 }
  923.                                 break;
  924.                             case    GD_HBSTOP:
  925.                                 if( currmonitor->ms_Special ){
  926.                                     currmonitor->ms_Special->hblank.asi_Stop = Code;
  927.                                     UpDateMonitor();
  928.                                 }
  929.                                 break;
  930.  
  931.                             case    GD_VBSTRT:
  932.                                 if( currmonitor->ms_Special ){
  933.                                     currmonitor->ms_Special->vblank.asi_Start = Code;
  934.                                     UpDateMonitor();
  935.                                 }
  936.                                 break;
  937.                             case    GD_VSSTRT:
  938.                                 if( currmonitor->ms_Special ){
  939.                                     currmonitor->ms_Special->vsync.asi_Start = Code;
  940.                                     UpDateMonitor();
  941.                                 }
  942.                                 break;
  943.                             case    GD_VSSTOP:
  944.                                 if( currmonitor->ms_Special ){
  945.                                     currmonitor->ms_Special->vsync.asi_Stop = Code;
  946.                                     UpDateMonitor();
  947.                                 }
  948.                                 break;
  949.                             case    GD_VBSTOP:
  950.                                 if( currmonitor->ms_Special ){
  951.                                     currmonitor->ms_Special->vblank.asi_Stop = Code;
  952.                                     UpDateMonitor();
  953.                                 }
  954.                                 break;
  955.  
  956.                             case    GD_TOTROWS:
  957.                                 currmonitor->total_rows = Code;
  958.                                 UpDateDisplay();
  959.                                 break;
  960.                             case    GD_TOTCLKS:
  961.                                 currmonitor->total_colorclocks = Code;
  962.                                 UpDateDisplay();
  963.                                 break;
  964.                         }
  965.                         break;
  966.  
  967.                     case    IDCMP_GADGETUP:
  968.                             switch ( IObject->GadgetID ) {
  969.                                 case    GD_SAVE:
  970.                                     Save:
  971.                                     if( Monitor_Editable ){
  972.                                         SaveDetails();
  973.                                         running = FALSE;
  974.                                     }
  975.                                     break;
  976.  
  977.                                 case    GD_USE :
  978.                                     Use:
  979.                                     running = FALSE;
  980.                                     break;
  981.  
  982.                                 case    GD_CANCEL:
  983.                                     Cancel:
  984.                                     RestoreMonitor();
  985.                                     UpDateDisplay();
  986.                                     running = FALSE;
  987.                                     break;
  988.  
  989.                                 case    GD_JUMP:
  990.                                     Jump:
  991.                                     RestoreMonitor();
  992.                                     UpDateDisplay();
  993.                                     MainScreen = (struct Screen *)(MainScreen->NextScreen);
  994.                                     if ( !MainScreen )
  995.                                         MainScreen = (struct Screen *)(IntuitionBase->FirstScreen);
  996.                                     CloseDisplay();
  997.                                     ScreenToFront( MainScreen );
  998.                                     OpenDisplay();
  999.                                     break;                      
  1000.                             }
  1001.                     break;
  1002.                 }
  1003.             }
  1004.         }
  1005.         while ( running );
  1006.         CloseDisplay();
  1007.     }
  1008.  
  1009.     CloseLibraries();
  1010.  
  1011.     Exit( NULL );
  1012. }
  1013.  
  1014.