grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / prefs / MonEd / moned.c
blobf026ab9b3dcea77897d7d9291d6e7b00d805a66b
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
17 #include <exec/types.h>
18 #include <exec/memory.h>
19 #include <exec/execbase.h>
21 #include <dos/dos.h>
22 #include <dos/dosextens.h>
23 #include <dos/stdio.h> // dos stdio
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>
32 #include "moned_globals.h" // my private data
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>
43 #include <stdio.h> // and the thing we all use!
44 #include <stdlib.h>
45 #include <string.h>
47 #include "compiler.h"
49 #define D(x)
50 #define DIDCMP(x)
51 #define DMSG(x)
53 #define TOOLS_IDCMP ARROWIDCMP | BUTTONIDCMP | CHECKBOXIDCMP |\
54 INTEGERIDCMP | LISTVIEWIDCMP | MXIDCMP |\
55 CYCLEIDCMP | PALETTEIDCMP | SCROLLERIDCMP |\
56 SLIDERIDCMP | STRINGIDCMP
58 BOOL Monitor_Editable = TRUE;
61 ULONG IClass;
62 UWORD Qualifier, Code, Prev_Code;
63 struct Gadget *IObject;
64 APTR MainVisualInfo;
65 struct TextAttr thinpaz8 = {
66 ( STRPTR )"thinpaz.font", 8, 0x00, 0x00 };
67 struct TextAttr Topaz80 = {
68 ( STRPTR )"topaz.font", 8, 0x00, 0x00 };
70 struct Screen *MainScreen;
71 struct TextFont *thinpazfont8;
72 struct TextAttr *default_font;
74 struct MonitorSpec *currmonitor;
75 struct MonitorSpec oldmonitor;
76 struct SpecialMonitor oldspecial;
78 #include "moned_rev.h"
80 UBYTE verstr[]={ VERSTAG };
85 * --- All my requesters use these tags
87 struct TagItem ReqTags[] = {
88 {WA_Left, 50l},
89 {WA_Top, 50l},
90 {WA_Width, 330l},
91 {WA_Height, 186l},
92 {WA_IDCMP, IDCMP_CLOSEWINDOW | TOOLS_IDCMP | IDCMP_VANILLAKEY | IDCMP_REFRESHWINDOW},
93 {WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET| WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_RMBTRAP | WFLG_SMART_REFRESH | WFLG_GIMMEZEROZERO},
94 {WA_Gadgets, 0l},
95 {WA_Title, 0l},
96 {WA_AutoAdjust, TRUE},
97 {WA_CustomScreen, 0l},
98 {TAG_DONE} };
101 * --- window gadget ID's
103 #define GD_HBSTRT 1
104 #define GD_HSSTRT 2
105 #define GD_HSSTOP 3
106 #define GD_HBSTOP 4
107 #define GD_VBSTRT 5
108 #define GD_VSSTRT 6
109 #define GD_VSSTOP 7
110 #define GD_VBSTOP 8
111 #define GD_TOTROWS 9
112 #define GD_TOTCLKS 10
113 #define GD_SAVE 50
114 #define GD_USE 51
115 #define GD_CANCEL 52
116 #define GD_JUMP 53
124 * --- Program gadget pointers that needs to be changed.
126 struct Window *sp_Wnd = NULL;
127 struct Gadget
128 *sp_HBSTRT,
129 *sp_HSSTRT,
130 *sp_HSSTOP,
131 *sp_HBSTOP,
132 *sp_VBSTRT,
133 *sp_VSSTRT,
134 *sp_VSSTOP,
135 *sp_VBSTOP,
136 *sp_TOTROWS,
137 *sp_TOTCLKS;
139 struct Gadget *sp_GList = NULL;
140 struct Gadget *g;
141 struct NewGadget ng;
142 UBYTE *sp_Title = "MonitorSpec Ed V3a (Raul. A. Sobon)";
145 * --- TagItems for the slider gadgets.
147 struct TagItem sp_HsyncTags[] = {
148 {GTSL_LevelFormat, (IPTR)"%03lx"},
149 {GTSL_MaxLevelLen, 3L},
150 {GTSL_Min, 0L},
151 {GTSL_Max, 64L},
152 {GA_Disabled, FALSE},
153 {TAG_DONE} };
155 struct TagItem sp_VsyncTags[] = {
156 {GTSL_LevelFormat, (IPTR)"%04lx"},
157 {GTSL_MaxLevelLen, 4L},
158 {GTSL_Min, 0L},
159 {GTSL_Max, 8000L},
160 {GA_Disabled, FALSE},
161 {TAG_DONE} };
163 struct TagItem sp_RowTags[] = {
164 {GTSL_LevelFormat, (IPTR)"%03lx"},
165 {GTSL_MaxLevelLen, 3L},
166 {GTSL_Min, 0L},
167 {GTSL_Max, 768L},
168 {GA_Disabled, FALSE},
169 {TAG_DONE} };
171 struct TagItem sp_TotClkTags[] = {
172 {GTSL_LevelFormat, (IPTR)"%03lx"},
173 {GTSL_MaxLevelLen, 3L},
174 {GTSL_Min, 1L},
175 {GTSL_Max, 768L},
176 {GA_Disabled, FALSE},
177 {TAG_DONE} };
180 ULONG version=30;
188 VOID __stdargs ShowFault(LONG code,char *header)
190 struct EasyStruct EasyStruct;
192 char ErrorString[80];
194 EasyStruct.es_StructSize = sizeof(struct EasyStruct);
195 EasyStruct.es_Flags = 0;
196 EasyStruct.es_Title = "MonitorSpec Ed";
197 EasyStruct.es_GadgetFormat = "Ok";
199 if(!code)
200 EasyStruct.es_TextFormat = header;
201 else
203 Fault(code,header,ErrorString,80);
205 EasyStruct.es_TextFormat = ErrorString;
208 EasyRequest(NULL,&EasyStruct,NULL,NULL);
213 void SetAllProps( void ){
214 if( currmonitor ){
215 if( currmonitor->ms_Special ){
216 GT_SetGadgetAttrs( sp_HBSTRT, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->hblank.asi_Start , TAG_DONE );
217 GT_SetGadgetAttrs( sp_HSSTRT, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->hsync.asi_Start , TAG_DONE );
218 GT_SetGadgetAttrs( sp_HSSTOP, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->hsync.asi_Stop , TAG_DONE );
219 GT_SetGadgetAttrs( sp_HBSTOP, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->hblank.asi_Stop , TAG_DONE );
220 GT_SetGadgetAttrs( sp_VBSTRT, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->vblank.asi_Start , TAG_DONE );
221 GT_SetGadgetAttrs( sp_VSSTRT, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->vsync.asi_Start , TAG_DONE );
222 GT_SetGadgetAttrs( sp_VSSTOP, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->vsync.asi_Stop , TAG_DONE );
223 GT_SetGadgetAttrs( sp_VBSTOP, sp_Wnd, NULL, GTSL_Level, currmonitor->ms_Special->vblank.asi_Stop , TAG_DONE );
225 GT_SetGadgetAttrs( sp_TOTROWS, sp_Wnd, NULL, GTSL_Level,currmonitor->total_rows , TAG_DONE );
226 GT_SetGadgetAttrs( sp_TOTCLKS, sp_Wnd, NULL, GTSL_Level,currmonitor->total_colorclocks , TAG_DONE );
232 * --- Reads a message from the window message port.
233 * --- Returns TRUE if a message was read and puts the
234 * --- message data in the globals. Return FALSE if there
235 * --- was no message at the port.
237 long ReadIMsg( struct Window *iwnd )
239 struct IntuiMessage *imsg;
241 if ((imsg = GT_GetIMsg( iwnd->UserPort ))) {
242 IClass = imsg->Class;
243 Qualifier = imsg->Qualifier;
244 Code = imsg->Code;
245 IObject = imsg->IAddress;
246 DMSG(printf("Got message, IClass 0x%08X, Qualifier 0x%04X, Code %u, IObject %p\n", IClass, Qualifier, Code, IObject));
248 GT_ReplyIMsg( imsg );
250 return TRUE;
252 return FALSE;
258 * --- Clears all message from a message port.
260 void ClearMsgPort( struct MsgPort *mport )
262 struct IntuiMessage *msg;
264 while ((msg = GT_GetIMsg( mport ))) GT_ReplyIMsg( msg );
272 * --- Open lots of libraries that I need.
274 long OpenLibraries( void ){
276 if ( !(IconBase = (struct Library *) OpenLibrary((UBYTE *) "icon.library" , 36l ))) {
277 WriteStr("\ticon.library\n");
278 return FALSE;
281 if ( !(GfxBase = (struct GfxBase *) OpenLibrary((UBYTE *) "graphics.library" , 36l ))) {
282 WriteStr("\tgraphics.library\n");
283 return FALSE;
286 if ( !(DosBase = (struct DosBase *) OpenLibrary((UBYTE *) "dos.library", 36l ))) {
287 WriteStr("\tdos.library\n");
288 return FALSE;
291 if ( !(IntuitionBase = (struct IntuitionBase *) OpenLibrary((UBYTE *) "intuition.library", 36l ))) {
292 WriteStr("\tintuition.library\n");
293 return FALSE;
296 if ( !(AslBase = (struct Library *) OpenLibrary((UBYTE *) "asl.library", 37l ))) {
297 WriteStr("\tasl.library\n");
298 return FALSE;
301 if ( !(GadToolsBase = (struct Library *) OpenLibrary((UBYTE *) "gadtools.library", 36l ))) {
302 WriteStr("\tgadtools.library\n");
303 return FALSE;
306 if ( !(DiskFontBase = (struct Library *) OpenLibrary((UBYTE *) "diskfont.library", 36l ))) {
307 WriteStr("\tdiskfont.library\n");
308 return FALSE;
311 return TRUE;
318 * --- Close the libraries which are opened by me.
320 void CloseLibraries( void ){
321 if (DiskFontBase) CloseLibrary( (struct Library *) DiskFontBase );
322 if (GadToolsBase) CloseLibrary( (struct Library *) GadToolsBase );
323 if (AslBase) CloseLibrary( (struct Library *) AslBase );
324 if (IntuitionBase) CloseLibrary( (struct Library *) IntuitionBase );
325 if (DosBase) CloseLibrary( (struct Library *) DosBase );
326 if (GfxBase) CloseLibrary( (struct Library *) GfxBase );
327 if (IconBase) CloseLibrary( (struct Library *) IconBase );
331 void SaveMonitor( void ){
332 if( currmonitor ){
333 CopyMem( currmonitor, &oldmonitor, sizeof( struct MonitorSpec) );
334 if( currmonitor->ms_Special )
335 CopyMem( currmonitor->ms_Special, &oldspecial, sizeof( struct SpecialMonitor ) );
340 void RestoreMonitor( void ){
341 if( currmonitor ){
342 CopyMem( &oldmonitor, currmonitor, sizeof( struct MonitorSpec) );
343 if( currmonitor->ms_Special )
344 CopyMem( &oldspecial, currmonitor->ms_Special, sizeof( struct SpecialMonitor ) );
353 static UBYTE mon[16];
356 void SaveDetails( void ){
357 struct DiskObject *diskobj;
358 UBYTE tt[6][16]={
359 "TOTROWS=0x00",
360 "TOTCLKS=0x00",
361 "HBSTRT=0x00",
362 "HBSTOP=0x00",
363 "VBSTRT=0x00",
364 "VBSTOP=0x00" };
365 UBYTE *txtptrs[8];
366 UBYTE **oldtxtptrs;
367 UBYTE monname[35];
369 if( currmonitor ){
370 sprintf( monname,"DEVS:Monitors/%s",mon );
371 if ((diskobj=GetDiskObject( monname ))){
372 oldtxtptrs = diskobj->do_ToolTypes;
374 sprintf( &tt[0][10],"%02x",currmonitor->total_rows);
375 sprintf( &tt[1][10],"%02x",currmonitor->total_colorclocks);
376 txtptrs[0] = &tt[0][0];
377 txtptrs[1] = &tt[1][0];
379 if( currmonitor->ms_Special ){
380 sprintf( &tt[2][9],"%02x", currmonitor->ms_Special->hblank.asi_Start );
381 sprintf( &tt[3][9],"%02x", currmonitor->ms_Special->hblank.asi_Stop );
382 sprintf( &tt[4][9],"%02x", currmonitor->ms_Special->vblank.asi_Start );
383 sprintf( &tt[5][9],"%02x", currmonitor->ms_Special->vblank.asi_Stop );
384 txtptrs[2] = &tt[2][0];
385 txtptrs[3] = &tt[3][0];
386 txtptrs[4] = &tt[4][0];
387 txtptrs[5] = &tt[5][0];
388 txtptrs[6] = NULL;
390 else
391 txtptrs[2] = NULL;
393 diskobj->do_ToolTypes = txtptrs;
394 if( !PutDiskObject( monname, diskobj ) )
395 ShowFault(IoErr(),"icon.library/PutDiskObject()");
397 diskobj->do_ToolTypes = oldtxtptrs;
398 FreeDiskObject( diskobj );
400 else
401 ShowFault(IoErr(),"icon.library/GetDiskObject()");
403 else
404 ShowFault(0, "Invalid monitor in use");
413 void UpDateMonitor( void ){
414 if( currmonitor ){
415 if( currmonitor->ms_Special ){
416 if( currmonitor->ms_Special->do_monitor ) {
417 currmonitor->ms_Special->do_monitor(currmonitor);
418 MakeScreen( (struct Screen *)MainScreen );
419 RethinkDisplay();
427 #define PICASSO_MONITOR_ID 0x000f1000
428 #define EGS24_MONITOR_ID 0x04001000
430 void UpDateDisplay( void ){
431 UBYTE tstr[40];
432 ULONG rows=0,clks=0,fps,scan,mode;
434 if( currmonitor ){
435 rows = currmonitor->total_rows;
436 clks = currmonitor->total_colorclocks;
438 if( rows && clks )
439 fps = abs(1000000000/(rows*clks*280));
440 else
441 fps = 0;
442 scan = fps*rows;
444 mode = GetVPModeID(&IntuitionBase->ActiveScreen->ViewPort)&MONITOR_ID_MASK;
446 switch( (ULONG)(mode) ) {
447 case NTSC_MONITOR_ID: sprintf(mon,"NTSC");break;
448 case PAL_MONITOR_ID: sprintf(mon,"PAL");break;
449 case VGA_MONITOR_ID: sprintf(mon,"Multiscan");break;
450 case A2024_MONITOR_ID: sprintf(mon,"A2024");break;
451 case PROTO_MONITOR_ID: sprintf(mon,"PROTO");break;
452 case EURO72_MONITOR_ID: sprintf(mon,"EURO72");break;
453 case EURO36_MONITOR_ID: sprintf(mon,"EURO36");break;
454 case SUPER72_MONITOR_ID: sprintf(mon,"SUPER72");break;
455 case DBLNTSC_MONITOR_ID:
456 if( version >= 39 ) sprintf(mon,"DBLNTSC"); else sprintf(mon,"DoubleNTSC");
457 break;
458 case DBLPAL_MONITOR_ID:
459 if( version >= 39 ) sprintf(mon,"DBLPAL"); else sprintf(mon,"DoublePAL");
460 break;
461 case PICASSO_MONITOR_ID: sprintf(mon,"PICASSO");break;
462 case EGS24_MONITOR_ID: sprintf(mon,"EGS-SPECTRUM");break;
463 case DEFAULT_MONITOR_ID: sprintf(mon,"PAL");break;
464 default: sprintf(mon,"CUSTOM(%4x)",mode);break;
467 sprintf(tstr,"%s: %02d.%02d Khz, %02d Hz ",mon,scan/1000,(scan%1000)*10,fps );
468 if( sp_Wnd ){
469 SetAPen( sp_Wnd->RPort, 2 );
470 Move( sp_Wnd->RPort, 9, 136 );
471 Text( sp_Wnd->RPort, tstr, strlen(tstr) );
472 // printf( "*** %s",tstr );
474 else
475 printf( "%s.\n", tstr );
477 UpDateMonitor();
485 /**********************************************************************
487 * Draw3DOutBox
488 * Description : just like normal bevelbox except inside color is selectable
489 * plus it looks MONUMENTAL!
490 * ¯¯¯¯¯¯¯¯¯¯¯
491 * Returns : NULL
492 * Globals : usual
495 void Draw3DBox(
496 struct RastPort *rp, // window rastport to draw into
497 UWORD xpos, // X coordinate to place MEGA-BEVEL
498 UWORD ypos, // Y coordinate to place MEGA-BEVEL
499 UWORD xsize, // X size of MEGA-BEVEL
500 UWORD ysize, // X size of MEGA-BEVEL
501 UWORD shine_pen, // top-left pen
502 UWORD body_pen, // central pen
503 UWORD shadow_pen // bot-right pen
506 #define LineDraw(x,y,x2,y2) Move( rp, x , y); \
507 Draw( rp, x2, y2 )
509 xsize--;ysize--;
511 if( body_pen == 0xffff )
512 SetAPen( rp, shine_pen );
513 else {
514 SetAPen( rp, body_pen );
515 RectFill( rp, xpos, ypos, xpos+xsize, ypos+ysize);
518 LineDraw( xpos, ypos, xpos+1, ypos+1 );
519 LineDraw( xpos+xsize-1, ypos+ysize-1, xpos+xsize, ypos+ysize );
521 SetAPen( rp, shine_pen );
522 LineDraw( xpos+0, ypos+0, xpos+xsize-1, ypos );
523 LineDraw( xpos+0, ypos+1, xpos+xsize-2, ypos+1 );
524 LineDraw( xpos+0, ypos+0, xpos, ypos+ysize-1 );
525 LineDraw( xpos+1, ypos+0, xpos+1, ypos+ysize-2 );
527 SetAPen( rp, shadow_pen );
528 LineDraw( xpos+1, ypos+ysize-0, xpos+xsize-1, ypos+ysize-0 );
529 LineDraw( xpos+2, ypos+ysize-1, xpos+xsize-2, ypos+ysize-1 );
530 LineDraw( xpos+xsize-0, ypos+1, xpos+xsize-0, ypos+ysize-1 );
531 LineDraw( xpos+xsize-1, ypos+2, xpos+xsize-1, ypos+ysize-2 );
533 SetAPen( rp, 2 );
534 if( shine_pen == shadow_pen ){
535 SetAPen( rp, shine_pen );
536 LineDraw( xpos, ypos+ysize, xpos+1, ypos+ysize-1 );
537 LineDraw( xpos+xsize-1, ypos+1, xpos+xsize, ypos );
539 else
540 if(shine_pen > shadow_pen ){
541 LineDraw( xpos+0, ypos+0, xpos+2, ypos+0 );
542 LineDraw( xpos+0, ypos+0, xpos+0, ypos+2 );
544 else {
545 LineDraw( xpos+xsize, ypos+ysize, xpos+xsize-2, ypos+ysize );
546 LineDraw( xpos+xsize, ypos+ysize, xpos+xsize-0, ypos+ysize-2 );
555 /**********************************************************************
557 * Draw3DLine
558 * Description : just like normal line except its 3D (sorta!) (horizontal)
559 * plus it looks MONUMENTAL!
560 * ¯¯¯¯¯¯¯¯¯¯¯
561 * Returns : NULL
562 * Globals : usual
565 void Draw3DLine(
566 struct RastPort *rp, // window rastport to draw into
567 UWORD xpos, // X coordinate to place MEGA-BEVEL
568 UWORD ypos, // Y coordinate to place MEGA-BEVEL
569 UWORD xsize, // X size of MEGA-BEVEL
570 UWORD shine_pen, // top-left pen
571 UWORD shadow_pen // bot-right pen
574 xsize--;
576 SetAPen( rp, shine_pen );
577 LineDraw( xpos+0, ypos+0, xpos+xsize, ypos+0 );
578 SetAPen( rp, shadow_pen );
579 LineDraw( xpos+0, ypos+1, xpos+xsize, ypos+1 );
584 long OpenDisplay( void ){
585 WORD offy,x1,y1,w,h;
587 ReqTags[7].ti_Data = (ULONG)sp_Title;
588 ReqTags[9].ti_Data = (Tag)MainScreen;
590 if ( ! (thinpazfont8 = OpenDiskFont( &thinpaz8 )) ) {
591 thinpazfont8 = OpenDiskFont( &Topaz80 );
592 default_font = &Topaz80;
593 } else
594 default_font = &thinpaz8;
595 D(printf("Font: %p\n", thinpazfont8));
597 currmonitor = GfxBase->current_monitor;
598 D(printf("Current monitor: %p\n", currmonitor));
600 SaveMonitor();
602 if ( currmonitor ){
603 sp_RowTags[4].ti_Data = FALSE;
604 sp_TotClkTags[4].ti_Data = FALSE;
605 Monitor_Editable = TRUE;
607 else {
608 sp_RowTags[4].ti_Data = TRUE;
609 sp_TotClkTags[4].ti_Data = TRUE;
610 Monitor_Editable = FALSE;
613 if ( currmonitor && currmonitor->ms_Special ){
614 sp_HsyncTags[4].ti_Data = FALSE;
615 sp_VsyncTags[4].ti_Data = FALSE;
616 Monitor_Editable = TRUE;
618 else {
619 sp_HsyncTags[4].ti_Data = TRUE;
620 sp_VsyncTags[4].ti_Data = TRUE;
621 Monitor_Editable = FALSE;
624 D(printf("Monitor is editable: %d\n", Monitor_Editable));
627 if ( ! ( MainVisualInfo = GetVisualInfo( MainScreen, TAG_DONE )))
628 return( 2L );
629 D(printf("VisualInfo %p\n", MainVisualInfo));
631 #define YSTEP 12
633 if ((g = CreateContext( &sp_GList ))) {
634 D(printf("GadTools context: %p\n", g));
636 ng.ng_LeftEdge = 89;
637 ng.ng_TopEdge = 5;
638 ng.ng_Width = 216;
639 ng.ng_Height = 10;
640 ng.ng_GadgetText = "HBSTRT: ";
641 ng.ng_TextAttr = default_font;
642 ng.ng_GadgetID = GD_HBSTRT;
643 ng.ng_Flags = PLACETEXT_LEFT | NG_HIGHLABEL;
644 ng.ng_VisualInfo = MainVisualInfo;
645 ng.ng_UserData = NULL;
646 sp_HBSTRT = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_HsyncTags );
647 D(printf("HBSTRT gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
649 ng.ng_TopEdge += YSTEP;
650 ng.ng_GadgetText = "HSSTRT: ";
651 ng.ng_GadgetID = GD_HSSTRT;
652 sp_HSSTRT = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_HsyncTags );
653 D(printf("HSSTRT gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
655 ng.ng_TopEdge += YSTEP;
656 ng.ng_GadgetText = "HSSTOP: ";
657 ng.ng_GadgetID = GD_HSSTOP;
658 sp_HSSTOP = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_HsyncTags );
659 D(printf("HSSTOP gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
661 ng.ng_TopEdge += YSTEP;
662 ng.ng_GadgetText = "HBSTOP: ";
663 ng.ng_GadgetID = GD_HBSTOP;
664 sp_HBSTOP = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_HsyncTags );
665 D(printf("HBSTOP gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
667 ng.ng_TopEdge += YSTEP;
668 ng.ng_GadgetText = "TOTCLKS: ";
669 ng.ng_GadgetID = GD_TOTCLKS;
670 sp_TOTCLKS = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_TotClkTags );
671 D(printf("TOTCLKS gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
673 ng.ng_TopEdge += YSTEP;
674 ng.ng_GadgetText = "VBSTRT: ";
675 ng.ng_GadgetID = GD_VBSTRT;
676 sp_VBSTRT = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_VsyncTags );
677 D(printf("VBSTRT gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
679 ng.ng_TopEdge += YSTEP;
680 ng.ng_GadgetText = "VSSTRT: ";
681 ng.ng_GadgetID = GD_VSSTRT;
682 sp_VSSTRT = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_VsyncTags );
683 D(printf("VSSTRT gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
685 ng.ng_TopEdge += YSTEP;
686 ng.ng_GadgetText = "VSSTOP: ";
687 ng.ng_GadgetID = GD_VSSTOP;
688 sp_VSSTOP = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_VsyncTags );
689 D(printf("VSSTOP gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
691 ng.ng_TopEdge += YSTEP;
692 ng.ng_GadgetText = "VBSTOP: ";
693 ng.ng_GadgetID = GD_VBSTOP;
694 sp_VBSTOP = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_VsyncTags );
695 D(printf("VBSTOP gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
697 ng.ng_TopEdge += YSTEP;
698 ng.ng_GadgetText = "TOTROWS: ";
699 ng.ng_GadgetID = GD_TOTROWS;
700 sp_TOTROWS = g = CreateGadgetA( SLIDER_KIND, g, &ng, sp_RowTags );
701 D(printf("TOTROWS gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
704 y1= ng.ng_TopEdge = 142;
705 x1= ng.ng_LeftEdge = 89;
706 w= ng.ng_Width = 50;
707 h= ng.ng_Height = 14;
708 ng.ng_Flags = PLACETEXT_IN;
709 ng.ng_GadgetText = "_USE";
710 ng.ng_GadgetID = GD_USE;
711 g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, (Tag)'_', TAG_DONE );
712 D(printf("USE gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
714 ng.ng_LeftEdge = 144;
715 ng.ng_GadgetText = "_SAVE";
716 ng.ng_GadgetID = GD_SAVE;
717 g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, (Tag)'_', TAG_DONE );
718 D(printf("SAVE gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
720 ng.ng_LeftEdge = 199;
721 ng.ng_GadgetText = "_CANCEL";
722 ng.ng_GadgetID = GD_CANCEL;
723 g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, (Tag)'_', TAG_DONE );
724 D(printf("CANCEL gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
726 ng.ng_LeftEdge = 254;
727 ng.ng_GadgetText = "_JUMP";
728 ng.ng_GadgetID = GD_JUMP;
729 g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, (Tag)'_', TAG_DONE );
730 D(printf("JUMP gadget: %p, at (%d, %d)\n", g, ng.ng_LeftEdge, ng.ng_TopEdge));
733 if ( g ) {
734 //ReqTags[6].ti_Data = (Tag)sp_GList;
735 offy = MainScreen->WBorTop + MainScreen->RastPort.TxHeight + MainScreen->WBorBottom;
736 ReqTags[3].ti_Data = 164+offy;
737 D(printf("Opening window, size %ld x %ld...\n", ReqTags[2].ti_Data, ReqTags[3].ti_Data));
738 if ((sp_Wnd = OpenWindowTagList( NULL, ReqTags ))) {
739 D(printf("Window %p\n", sp_Wnd));
740 SetFont( sp_Wnd->RPort, thinpazfont8 );
741 if( MainScreen->BitMap.Depth > 2 ) {
742 Draw3DBox( sp_Wnd->RPort, 0, 0, sp_Wnd->Width-sp_Wnd->BorderLeft-sp_Wnd->BorderRight,
743 sp_Wnd->Height-sp_Wnd->BorderTop-sp_Wnd->BorderBottom, 2, 3, 1 );
745 Draw3DLine( sp_Wnd->RPort, 1, 125,sp_Wnd->Width-sp_Wnd->BorderLeft-sp_Wnd->BorderRight-3, 1, 2 );
747 SetAPen( sp_Wnd->RPort, 2 );
748 SetBPen( sp_Wnd->RPort, 3 );
750 AddGList( sp_Wnd, sp_GList, 0, -1, NULL);
751 RefreshGList( sp_GList, sp_Wnd, 0, 0);
752 GT_RefreshWindow( sp_Wnd, NULL );
753 SetAllProps();
754 UpDateDisplay();
756 Draw3DBox( sp_Wnd->RPort, x1-2, y1-2, w+4, h+4, 1, 0xffff, 1 );
758 else
759 return 0;
762 return 1;
769 void CloseDisplay( void ) {
771 if ( thinpazfont8 )
772 CloseFont( thinpazfont8 );
774 if ( MainVisualInfo ) {
775 FreeVisualInfo( MainVisualInfo );
776 MainVisualInfo = NULL;
778 if ( sp_Wnd ) CloseWindow( sp_Wnd );
779 if ( sp_GList ) FreeGadgets( sp_GList );
785 LONG xtoi( UBYTE *txt ){
786 LONG n;
788 sscanf( txt,"%x",&n );
790 return n;
796 // ----------------------------------------------------------------------------------------------
797 int main( int argc,char *argv[] )
799 BOOL running = TRUE;
802 if( !OpenLibraries() ) {
803 ShowFault(0, "Libraries cant be opened!");
804 CloseLibraries();
805 exit(5);
808 version=IntuitionBase->LibNode.lib_Version;
810 MainScreen = (struct Screen *)(IntuitionBase->ActiveScreen);
812 if( argc>1 ) {
813 BOOL update = TRUE;
814 currmonitor = GfxBase->current_monitor;
815 SaveMonitor();
817 if( *argv[1] == '?' ){
818 puts( "Moned3a, © 1994 Raul Sobon / PRoJeCT-23");
819 puts( " moned HBSTRT=0xnnn HBSTOP=0xnnn HBSTOP=0xnnn");
820 puts( " HSSTRT=0xnnn HSSTOP=0xnnn VBSTRT=0xnnn");
821 puts( " VBSTOP=0xnnn VSSTRT=0xnnn VSSTOP=0xnnn");
822 // puts( " MAXOSC=0xnnn VIDOSC=0xnnn xxxxxx=0xnnn");
823 puts( "NOTE: each item is optional and can be in any order and nnn is a hex number.");
825 else
826 if( currmonitor ){
827 WORD count = argc,lp=1;
828 UBYTE *cmd,*num;
830 while( count >1 ){
831 cmd = argv[ lp ];
832 num = cmd+9;
833 //printf("str=<%s> n=<%s>=%d\n",cmd,num,xtoi( num ) );
834 if( currmonitor->ms_Special ){
835 if( !strnicmp( "HBSTRT=0x", cmd , 9 ) ) currmonitor->ms_Special->hblank.asi_Start=xtoi( num );
836 else if( !strnicmp( "HBSTOP=0x", cmd , 9 ) ) currmonitor->ms_Special->hblank.asi_Stop=xtoi( num );
837 else if( !strnicmp( "HSSTRT=0x", cmd , 9 ) ) currmonitor->ms_Special->hsync.asi_Start=xtoi( num );
838 else if( !strnicmp( "HSSTOP=0x", cmd , 9 ) ) currmonitor->ms_Special->hsync.asi_Stop=xtoi( num );
839 else if( !strnicmp( "VBSTRT=0x", cmd , 9 ) ) currmonitor->ms_Special->vblank.asi_Start=xtoi( num );
840 else if( !strnicmp( "VBSTOP=0x", cmd , 9 ) ) currmonitor->ms_Special->vblank.asi_Stop=xtoi( num );
841 else if( !strnicmp( "VSSTRT=0x", cmd , 9 ) ) currmonitor->ms_Special->vsync.asi_Start=xtoi( num );
842 else if( !strnicmp( "VSSTOP=0x", cmd , 9 ) ) currmonitor->ms_Special->vsync.asi_Stop=xtoi( num );
843 else update = FALSE;
845 if( !strnicmp( "TOTROW=0x", cmd , 9 ) ) {
846 currmonitor->total_rows=xtoi( num ); update = TRUE; }
847 else if( !strnicmp( "TOTCLK=0x", cmd , 9 ) ) {
848 currmonitor->total_colorclocks=xtoi( num ); update = TRUE; }
849 // else if( !strnicmp( "MAXOSC=0x", cmd , 9 ) ) {
850 // currmonitor->ms_maxoscan=xtoi( num ); update = TRUE; }
851 // else if( !strnicmp( "VIDOSC=0x", cmd , 9 ) ) {
852 // currmonitor->ms_videoscan=xtoi( num ); update = TRUE; }
854 lp++; count--;
856 if( update ) {
857 UpDateDisplay();
858 // printf("Display updated.\n");
860 else
861 printf("argument <%s> invalid?\n",cmd);
864 else
865 if( OpenDisplay() ) {
866 do {
867 WaitPort( sp_Wnd->UserPort );
869 while ( ReadIMsg( sp_Wnd )) {
871 switch ( IClass ) {
873 case IDCMP_ACTIVEWINDOW:
874 DIDCMP(printf("Window activate\n"));
875 ClearMsgPort( sp_Wnd->UserPort );
876 break;
878 case IDCMP_REFRESHWINDOW:
879 DIDCMP(printf("Window refresh\n"));
880 GT_BeginRefresh( sp_Wnd );
881 GT_EndRefresh( sp_Wnd, TRUE );
882 break;
884 case IDCMP_CLOSEWINDOW:
885 DIDCMP(printf("Window close\n"));
886 goto Cancel;
887 break;
889 case IDCMP_VANILLAKEY:
890 DIDCMP(printf("Keypress\n"));
891 switch ( Code ) {
892 case '[':
893 if( Monitor_Editable ){
894 GT_SetGadgetAttrs(sp_TOTCLKS,sp_Wnd,0,GTSL_Level, --currmonitor->total_colorclocks,TAG_DONE);
895 UpDateDisplay();
897 break;
898 case ']':
899 if( Monitor_Editable ){
900 GT_SetGadgetAttrs(sp_TOTCLKS,sp_Wnd,0,GTSL_Level, ++currmonitor->total_colorclocks,TAG_DONE);
901 UpDateDisplay();
903 break;
905 case '{':
906 if( Monitor_Editable ){
907 GT_SetGadgetAttrs(sp_TOTROWS,sp_Wnd,0,GTSL_Level, --currmonitor->total_rows,TAG_DONE);
908 UpDateDisplay();
910 break;
911 case '}':
912 if( Monitor_Editable ){
913 GT_SetGadgetAttrs(sp_TOTROWS,sp_Wnd,0,GTSL_Level, ++currmonitor->total_rows,TAG_DONE);
914 UpDateDisplay();
916 break;
918 case 's':
919 goto Save;
921 case 13 :
922 case 'u':
923 goto Use;
925 case 'c':
926 goto Cancel;
928 case 'j':
929 goto Jump;
931 break;
933 case IDCMP_MOUSEMOVE:
934 DIDCMP(printf("Mouse move\n"));
935 switch ( IObject->GadgetID ) {
936 case GD_HBSTRT:
937 if( currmonitor->ms_Special ){
938 currmonitor->ms_Special->hblank.asi_Start = Code;
939 UpDateMonitor();
941 break;
942 case GD_HSSTRT:
943 if( currmonitor->ms_Special ){
944 currmonitor->ms_Special->hsync.asi_Start = Code;
945 UpDateMonitor();
947 break;
948 case GD_HSSTOP:
949 if( currmonitor->ms_Special ){
950 currmonitor->ms_Special->hsync.asi_Stop = Code;
951 UpDateMonitor();
953 break;
954 case GD_HBSTOP:
955 if( currmonitor->ms_Special ){
956 currmonitor->ms_Special->hblank.asi_Stop = Code;
957 UpDateMonitor();
959 break;
961 case GD_VBSTRT:
962 if( currmonitor->ms_Special ){
963 currmonitor->ms_Special->vblank.asi_Start = Code;
964 UpDateMonitor();
966 break;
967 case GD_VSSTRT:
968 if( currmonitor->ms_Special ){
969 currmonitor->ms_Special->vsync.asi_Start = Code;
970 UpDateMonitor();
972 break;
973 case GD_VSSTOP:
974 if( currmonitor->ms_Special ){
975 currmonitor->ms_Special->vsync.asi_Stop = Code;
976 UpDateMonitor();
978 break;
979 case GD_VBSTOP:
980 if( currmonitor->ms_Special ){
981 currmonitor->ms_Special->vblank.asi_Stop = Code;
982 UpDateMonitor();
984 break;
986 case GD_TOTROWS:
987 currmonitor->total_rows = Code;
988 UpDateDisplay();
989 break;
990 case GD_TOTCLKS:
991 currmonitor->total_colorclocks = Code;
992 UpDateDisplay();
993 break;
995 break;
997 case IDCMP_GADGETUP:
998 DIDCMP(printf("Gadget up\n"));
999 switch ( IObject->GadgetID ) {
1000 case GD_SAVE:
1001 Save:
1002 if( Monitor_Editable ){
1003 SaveDetails();
1004 running = FALSE;
1006 break;
1008 case GD_USE :
1009 Use:
1010 running = FALSE;
1011 break;
1013 case GD_CANCEL:
1014 Cancel:
1015 RestoreMonitor();
1016 UpDateDisplay();
1017 running = FALSE;
1018 break;
1020 case GD_JUMP:
1021 Jump:
1022 RestoreMonitor();
1023 UpDateDisplay();
1024 MainScreen = (struct Screen *)(MainScreen->NextScreen);
1025 if ( !MainScreen )
1026 MainScreen = (struct Screen *)(IntuitionBase->FirstScreen);
1027 CloseDisplay();
1028 ScreenToFront( MainScreen );
1029 OpenDisplay();
1030 break;
1032 break;
1036 while ( running );
1037 CloseDisplay();
1040 CloseLibraries();
1042 return 0;