home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 378.lha / MemMometer_V2.1 / mm.c < prev    next >
C/C++ Source or Header  |  1990-05-02  |  35KB  |  1,046 lines

  1. /* : ai=0 bk=0 ts=8 */
  2. #include "mm.h"
  3.  
  4. #define FREEPEN -1L           /* workbench screen default colors */
  5. #define REQ_WINDOW_WIDTH 319L /* width of SFMem warning requester window */
  6. #define REQ_WINDOW_HEIGHT 79L /* height of SFMem warning requester window */
  7.  
  8. #define SOK        0x001f     /* memory allocation control masks */
  9. #define S1         0x0001
  10. #define S2         0x0002
  11. #define S4         0x0004
  12. #define S8         0x0008
  13. #define SA         0x0010
  14. #define C1         0xfffe
  15. #define C2         0xfffd
  16. #define C4         0xfffb
  17. #define C8         0xfff7
  18. #define CA         0xffef
  19. #define AARRRGH    20L
  20.  
  21. #define EXTENSION  16L         /* allocation request increment */
  22.  
  23. #define FRAGS FALSE                          /* frags mode control boolian */
  24. #define WARPS TRUE                     /* warps mode control boolian */
  25. #define EVENMASK 0x7ffffffe           /* used to prevent odd address traps */
  26. #define CLIHEIGHT 200L                             /* window scaling stuff */
  27. #define SIZEGAD 9L
  28. #define DRAGBAR 10L
  29. #define BORDER 2L
  30. #define WINW 16L                                   /* initial window width */
  31. #define WINH (long)(CLIHEIGHT - SIZEGAD - DRAGBAR)   /* initial win height */
  32. #define MINH 81L                              /* shortest allowable window */
  33. #define MAXH 576L                              /* longest allowable window */
  34. #define BART 1L                               /* title bar F text location */
  35. #define BARH (long)(WINH - SIZEGAD - DRAGBAR)                /* bar height */
  36. #define BARS (long)(BARH + 1)        /* number of memory items to allocate */
  37. #define BARB (long)(BARH + DRAGBAR - 1)        /* bottom of mercury column */
  38. #define BARE (long)(BARB + BORDER)              /* bar end E text position */
  39. #define BARW (long)(((WINW - (2 * BORDER)) / 3) - 1)  /* 3 memfragmometers */
  40. #define LEFT BORDER                   /* SLOW : since we're syncopated, we */
  41. #define MIDDLE (LEFT + BARW + 1)      /* SLOW-FAST : do it going from bar  */
  42. #define RIGHT (MIDDLE + BARW + 1)     /* FAST :to bar at an irregular pace */
  43. #define RTEXT - 4L        /* offset for three char E/F text from left edge */
  44. #define STARTVAL 64L    /* start by getting enough storage for a few frags */
  45.  
  46. /* typedef short BOOL */        /* this is in include/exec/types.h */
  47.  
  48. struct IntuitionBase *IntuitionBase=NULL ;
  49. struct Window *window ;
  50. struct IntuiMessage *message;
  51. /* struct IntuiMessage *GetMsg(); */        /* in functions.h */
  52.  
  53. struct GfxBase *GfxBase=NULL ;
  54.  
  55. struct IOStdReq *timermsg=NULL;
  56. struct MsgPort *timerport=NULL;
  57. ULONG  timerbit=NULL;
  58.  
  59.  
  60. extern void InitProjItems();        /* this stuff is in the mminit section */
  61. extern void InitSetupItems();
  62. extern void InitPrioItems();
  63. extern void InitChipItems();
  64. extern void InitChipAItems();
  65. extern void InitSFItems();
  66. extern void InitSFAItems();
  67. extern void InitFastItems();
  68. extern void InitFastAItems();
  69. extern void InitMenu();
  70. extern void StartMenus();
  71.  
  72. BOOL p_mode = FRAGS;          /* preset frags mode = 0, warps mode = 1 */
  73.                               /* note: mode preset used as request for */
  74.                               /*       change to warps mode after the  */
  75.                               /*       first pass with frags mode set! */
  76. long p_rate = 2;              /* preset sample interval, secs see menu */
  77. long p_priority = 0;          /* preset priority, range -128 to +127   */
  78.                               /* note: pri greater than zero is risky! */
  79.                               /* keep in mind AmigaDOS priorities:     */
  80.                               /* input.device 20, FileSystem 10, and   */
  81.                               /* trackdisk.device, CON: 5 also if MM   */
  82.                               /* is started from a CLI without the Run */
  83.                               /* then that CLI inherits MM's priority! */
  84. long p_chip = 512;            /* preset chip mem size, kbytes see menu */
  85. long p_chipa = 0;             /* preset chip mem address, kb  see menu */
  86. long p_sf = 0;                /* preset slowfast mem size, kb see menu */
  87. long p_sfa = 0x3000;          /* preset slowfast mem addr, kb see menu */
  88. long p_fast = 0;              /* preset fast mem size, mbytes see menu */
  89. long p_fasta = 2;             /* preset fast mem addr, mbytes see menu */
  90.  
  91. static BOOL mode;                    /* uninitialized for mode control */
  92. static BOOL mmode;                   /* uninitialized for mode  menu */
  93. static long delayval;                /* uninitialized for delay menu */
  94. static long priority;                /* uninitialized for priority menu */
  95. static long lastpri;                 /* uninitialized for priority incr */
  96. static long cmemsize;                /* uninitialized for chip  menu */
  97. static long cmembase;                /* uninitialized for chipa menu */
  98. static long sfmemsize;               /* uninitialized for sf    menu */
  99. static long sfmembase;               /* uninitialized for sfa   menu */
  100. static long fmemsize;                /* uninitialized for fast  menu */
  101. static long fmembase;                /* uninitialized for fasta menu */
  102.  
  103. static USHORT log ;                  /* memory allocation success flags */
  104. static BOOL things_are_cool = TRUE ; /* tells when to close the window  */
  105. static BOOL intsig = FALSE ;         /* intuition message detector */
  106. static USHORT chgflag = TRUE ;       /* menu request to adjust columns */
  107. static long chip[3], fast[3] ;       /* place to keep mem header pointers */
  108. static ULONG  *chunkv ;              /* demand allocated for frag chunks */
  109. static ULONG  *sizev ;               /* demand allocated for frag sizes */
  110. static ULONG  *csum ;                /* a col's height worth of checksums */
  111. static ULONG  *oldcsum ;             /* same height worth of old checksums */
  112. static USHORT *cell;                 /* 1 cell per pixel height of mercury */
  113. static long xl, xr ;                 /* used to Draw() memometer segments */
  114. static long frags = STARTVAL ;       /* # of demand allocated frag items */
  115. static long warps = BARS ;           /* # of demand allocated column items */
  116. static long barh = BARH ;            /* EVEN #'d height of mercury column */
  117. static long barb = BARB ;            /* bottom position of mercury column */
  118.  
  119. /* struct RastPort *rp ; */          /* wonder why we don't need this... ? */
  120.  
  121.  
  122. static struct TextAttr myfont = {
  123.    (STRPTR) "topaz.font",
  124.    TOPAZ_EIGHTY,
  125.    0,
  126.    0
  127. };
  128. /* E newsize gadget refresh text */ 
  129. static char ebuf[4] = " E " ;
  130. static struct IntuiText e_text = { 
  131.    BLUP, WHTP,
  132.    JAM2, 
  133.    0, BARE,
  134.    &myfont,
  135.    (UBYTE *)ebuf, 
  136.    NULL 
  137. };
  138. /* F title refresh text */
  139. static char fbuf[4] = " F " ;
  140. static struct IntuiText f_text = {
  141.    BLUP, WHTP,
  142.    JAM2,
  143.    0, BART,
  144.    &myfont,
  145.    (UBYTE *)fbuf,
  146.    &e_text
  147. };
  148. static struct NewWindow newwindow = {
  149.    0,                                        /* left edge */
  150.    10,                                       /* top edge */
  151.    WINW,                                     /* width */
  152.    WINH,                                     /* height */
  153.    0,                                        /* detail pen */
  154.    1,                                        /* block pen */
  155.    MENUPICK | NEWSIZE,                       /* messages */
  156. /* WINDOWDEPTH | WINDOWCLOSE */              /* don't use these gads */
  157.    WINDOWDRAG | WINDOWSIZING | SMART_REFRESH,   /* add a few gadgets */
  158.    NULL,                                     /* no custom gadgets */
  159.    NULL,                                     /* default checkmark */
  160.    (UBYTE *)"F",                             /* title */
  161.    NULL,                                     /* initialize this! */
  162.    NULL,                                     /* use screen bitmap */
  163.    WINW, MINH, WINW, MAXH,                   /* min and max sizes */
  164.    WBENCHSCREEN } ;                          /* use workbench screen */
  165.  
  166. void initmenus()
  167. {
  168.    (void) InitProjItems();              /* Initialize the menu items */
  169.    (void) InitSetupItems();
  170.    (void) InitPrioItems();
  171.    (void) InitChipItems();
  172.    (void) InitChipAItems();
  173.    (void) InitSFItems();
  174.    (void) InitSFAItems();
  175.    (void) InitFastItems();
  176.    (void) InitFastAItems();
  177.    (void) InitMenu();
  178.    (void) StartMenus();
  179.    }
  180.  
  181. void handle_MENUPICK( class, code )
  182. unsigned long class;
  183. unsigned int code;
  184. {
  185.     unsigned int menunum, itemnum, subnum;
  186.  
  187.     if (code == MENUNULL) return;
  188.  
  189.     menunum = MENUNUM( code );
  190.     itemnum = ITEMNUM( code );
  191.     subnum  = SUBNUM( code );
  192.     chgflag = TRUE;
  193.     switch( menunum ) {
  194.         case 0:
  195.         switch( itemnum ) {
  196.             case 0:
  197.             WindowToFront(window);
  198.             break;
  199.  
  200.             case 1:
  201.             WindowToBack(window);
  202.             break;
  203.  
  204.             case 2:
  205.             things_are_cool = FALSE;  /* Quit */
  206.             break;
  207.             } /* end of switch ( Project itemnum ) */
  208.         break;
  209.  
  210.         case 1:
  211.         switch( itemnum ) {
  212.             case 0:
  213.             switch( subnum ) {
  214.                 case 0:
  215.                 mode = FRAGS ;  /* Frags mode */
  216.                 break;
  217.  
  218.                 case 1:
  219.                 mmode = TRUE ;  /* Warps request */
  220.                 break;
  221.                 /* end of switch ( Mode subnum ) */
  222.                 }
  223.             break;       
  224.             case 1:
  225.             switch( subnum ) {
  226.                 case 0:
  227.                 delayval = 1;
  228.                 break;
  229.  
  230.                 case 1:
  231.                 delayval = 2;
  232.                 break;
  233.  
  234.                 case 2:
  235.                 delayval = 5;
  236.                 break;
  237.  
  238.                 case 3:
  239.                 delayval = 10;
  240.                 break;
  241.                 /* end of switch ( Freq subnum ) */
  242.                 }
  243.             break;       
  244.             /* end of switch ( Setup itemnum ) */
  245.             }
  246.         break;
  247.  
  248.         case 2:
  249.         switch( itemnum ) {
  250.             case  0:
  251.             priority = lastpri;
  252.             break;
  253.  
  254.             case  1:
  255.             priority = priority - 1;
  256.             break;
  257.  
  258.             case  2:
  259.             priority = priority + 1;
  260.             break;
  261.  
  262.             case  3:
  263.             priority = -99;
  264.             lastpri = priority;
  265.             break;
  266.  
  267.             case  4:
  268.             priority = -75;
  269.             lastpri = priority;
  270.             break;
  271.  
  272.             case  5:
  273.             priority = -50;
  274.             lastpri = priority;
  275.             break;
  276.  
  277.             case  6:
  278.             priority = -25;
  279.             lastpri = priority;
  280.             break;
  281.  
  282.             case  7:
  283.             priority = -20;
  284.             lastpri = priority;
  285.             break;
  286.  
  287.             case  8:
  288.             priority = -15;
  289.             lastpri = priority;
  290.             break;
  291.  
  292.             case  9:
  293.             priority = -10;
  294.             lastpri = priority;
  295.             break;
  296.  
  297.             case 10:
  298.             priority =  -5;
  299.             lastpri = priority;
  300.             break;
  301.  
  302.             case 11:
  303.             priority =   0;
  304.             lastpri = priority;
  305.             break;
  306.  
  307.             case 12:
  308.             priority =   5;
  309.             lastpri = priority;
  310.             break;
  311.  
  312.             case 13:
  313.             priority =  10;
  314.             lastpri = priority;
  315.             break;
  316.  
  317.             case 14:
  318.             priority =  15;
  319.             lastpri = priority;
  320.             break;
  321.  
  322.             case 15:
  323.             priority =  20;
  324.             lastpri = priority;
  325.             break;
  326.             }
  327.             /* end of switch ( Priority itemnum ) */
  328.         break;
  329.  
  330.         case 3:
  331.         switch( itemnum ) {
  332.             case 0:
  333.             cmemsize = 0x000000;
  334.             break;
  335.  
  336.             case 1:
  337.             cmemsize = 0x040000;
  338.             break;
  339.  
  340.             case 2:
  341.             cmemsize = 0x080000;
  342.             break;
  343.  
  344.             case 3:
  345.             cmemsize = 0x100000;
  346.             break;
  347.  
  348.             case 4:
  349.             cmemsize = 0x200000;
  350.             break;
  351.             }
  352.             /* end of switch ( Chip Size itemnum ) */
  353.         break;
  354.  
  355.         case 4:
  356.         switch( itemnum ) {
  357.             case 0:
  358.             cmembase = 0x000000;
  359.             break;
  360.  
  361.             case 1:
  362.             cmembase = 0x040000;
  363.             break;
  364.  
  365.             case 2:
  366.             cmembase = 0x080000;
  367.             break;
  368.  
  369.             case 3:
  370.             cmembase = 0x100000;
  371.             break;
  372.             }
  373.             /* end of switch ( Chip Addr itemnum ) */
  374.         break;
  375.  
  376.         case 5:
  377.         if (mode == WARPS)  mmode = TRUE ;
  378.         switch( itemnum ) {
  379.             case 0:
  380.             sfmemsize = 0x000000;
  381.             break;
  382.  
  383.             case 1:
  384.             sfmemsize = 0x080000;
  385.             break;
  386.  
  387.             case 2:
  388.             sfmemsize = 0x100000;
  389.             break;
  390.  
  391.             case 3:
  392.             sfmemsize = 0x180000;
  393.             break;
  394.             }
  395.             /* end of switch ( SF Size itemnum ) */
  396.         break;
  397.  
  398.         case 6:
  399.         if (mode == WARPS)  mmode = TRUE ;
  400.         switch( itemnum ) {
  401.             case 0:
  402.             sfmembase = 0xc00000;
  403.             break;
  404.  
  405.             case 1:
  406.             sfmembase = 0xc80000;
  407.             break;
  408.  
  409.             case 2:
  410.             sfmembase = 0xd00000;
  411.             break;
  412.  
  413.             case 3:
  414.             sfmembase = 0xd80000;
  415.             break;
  416.             }
  417.             /* end of switch ( SF Addr itemnum ) */
  418.         break;
  419.  
  420.         case 7:
  421.         switch( itemnum ) {
  422.             case 0:
  423.             fmemsize = 0x000000;
  424.             break;
  425.  
  426.             case 1:
  427.             fmemsize = 0x080000;
  428.             break;
  429.  
  430.             case 2:
  431.             fmemsize = 0x100000;
  432.             break;
  433.  
  434.             case 3:
  435.             fmemsize = 0x200000;
  436.             break;
  437.  
  438.             case 4:
  439.             fmemsize = 0x400000;
  440.             break;
  441.  
  442.             case 5:
  443.             fmemsize = 0x600000;
  444.             break;
  445.  
  446.             case 6:
  447.             fmemsize = 0x800000;
  448.             break;
  449.             }
  450.             /* end of switch ( Fast Size itemnum ) */
  451.         break;
  452.  
  453.         case 8:
  454.         if (mode == WARPS)  mmode = TRUE ;
  455.         switch( itemnum ) {
  456.             case 0:
  457.             fmembase = 0x200000;
  458.             break;
  459.  
  460.             case 1:
  461.             fmembase = 0x300000;
  462.             break;
  463.  
  464.             case 2:
  465.             fmembase = 0x400000;
  466.             break;
  467.  
  468.             case 3:
  469.             fmembase = 0x500000;
  470.             break;
  471.  
  472.             case 4:
  473.             fmembase = 0x600000;
  474.             break;
  475.  
  476.             case 5:
  477.             fmembase = 0x700000;
  478.             break;
  479.  
  480.             case 6:
  481.             fmembase = 0x800000;
  482.             break;
  483.  
  484.             case 7:
  485.             fmembase = 0x900000;
  486.             break;
  487.             }
  488.             /* end of switch ( Fast Addr itemnum ) */
  489.         break;
  490.         }
  491.         /* end of switch ( menunum ) */
  492. }
  493.  
  494. void wrack_sploot() /* this subprogram cashes in the chips in bad times */
  495.     {
  496.     if (log != 0) {
  497.         if (log & SA) {
  498.             (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ;
  499.             log = log & CA ;
  500.             }
  501.         if (log & S8) {
  502.             (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ;
  503.             log = log & C8 ;
  504.             }
  505.         if (log & S4)  {
  506.             (void) FreeMem(sizev, (long)(sizeof(long) * frags)) ;
  507.             log = log & C4 ;
  508.             }
  509.         if (log & S2)  {
  510.             (void) FreeMem(chunkv, (long)(sizeof(long) * frags)) ;
  511.             log = log & C2 ;
  512.             }
  513.         if (log & S1) {
  514.             (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ;
  515.             log = log & C1 ;
  516.             }
  517.         frags = 0;
  518.         warps = 0;
  519.         }
  520. }
  521.  
  522. SetTimer(sec, micro, timermsg)
  523. ULONG sec, micro;
  524. struct IOStdReq *timermsg;
  525. /* This routine simply sets the timer to interrupt us after secs.micros */
  526. {
  527.     timermsg->io_Command = TR_ADDREQUEST;    /* add a new timer request */
  528.     timermsg->io_Actual = sec;    /* seconds */
  529.     timermsg->io_Length = micro;    /* microseconds */
  530.     SendIO(timermsg);   /* post a request to the timer */
  531. }
  532.  
  533. void cleanup() {
  534.     if (timerport) {
  535.         Wait(timerbit);
  536.         GetMsg(timerport);
  537.         CloseDevice(timermsg);
  538.         DeleteStdIO(timermsg);
  539.         DeletePort(timerport);
  540.         }
  541.     if (GfxBase)        CloseLibrary(GfxBase) ;
  542.     if (window)         CloseWindow(window) ;
  543.     if (IntuitionBase)  CloseLibrary(IntuitionBase) ;
  544.     wrack_sploot() ;
  545.     exit(AARRRGH) ;
  546. }
  547.  
  548. void inittimer() {
  549.     if(!(timerport = (struct MsgPort *)CreatePort(0L, 0L)))cleanup();
  550.     if(!(timermsg = (struct IOStdReq *)CreateStdIO(timerport)))cleanup();
  551.     if (OpenDevice(TIMERNAME, UNIT_VBLANK, timermsg, 0L))cleanup();
  552.  
  553.     timerbit = 1L << timerport->mp_SigBit ;
  554.     SetTimer(1L, 0L, timermsg); /* set for first message */
  555. }
  556.  
  557. void handle_NEWSIZE() /* short term allocations cashed in then realloc'd */
  558.     {                 /* when user hits gadget but doesn't resize window */
  559.     if (log & SA)  {
  560.         (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ;
  561.         log = log & CA ;
  562.         }
  563.     if (log & S8)  {
  564.         (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ;
  565.         log = log & C8 ;
  566.         }
  567.     if (log & S1)  {
  568.         (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ;
  569.         log = log & C1 ;
  570.     barh = window->Height - SIZEGAD - DRAGBAR ;  /* recalculate height */
  571.     barb = window->Height - SIZEGAD - 1 ; /* get new bar base position */
  572.     warps = barh + 1 ;       /* number of storage cells to be reserved */
  573.     if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * warps,
  574.                                     MEMF_PUBLIC)) != 0L ) log = log | S1;
  575.     if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps,
  576.                                     MEMF_PUBLIC)) != 0L ) log = log | S8;
  577.     if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps,
  578.                                     MEMF_PUBLIC)) != 0L ) log = log | SA;
  579.     if (log != SOK)  {      /* bail out if we didn't get an allocation */
  580.         wrack_sploot() ;
  581.         things_are_cool = FALSE ;     /* tell _main that we're leaving */
  582.         }
  583.     e_text.TopEdge = barb + BORDER ;        /* set the E text position */
  584.     }
  585. }
  586.  
  587. void handle_MESSAGES()  {
  588.     unsigned long class;
  589.     unsigned int code, qual;
  590.  
  591.     /* Wait (1L << window->UserPort->mp_SigBit); this is rediculous! */
  592.     while ((message=(struct IntuiMessage *)GetMsg(window->UserPort))
  593.                                                                 != 0L) {
  594.         class = message->Class ;
  595.         code = message->Code ;
  596.         qual = message->Qualifier ;
  597.         ReplyMsg ;
  598.         switch( class ) {
  599.  
  600.             case NEWSIZE:
  601.             intsig = TRUE ;                     /* resize when done here */
  602.             break ;
  603.  
  604.             case MENUPICK:
  605.             handle_MENUPICK( class, code ) ;    /* do menus ASAP */
  606.             break ;
  607.             }
  608.         }
  609. }
  610.  
  611. void memometer()                /* this subprogram draws the bar graphs */
  612.     {
  613.     long i;
  614.     long y;
  615.  
  616.     (void) handle_MESSAGES() ;  /* go see if the user wants anything */
  617.     i = 0 ;
  618.     while ((i < barh) && (intsig == FALSE)) {
  619.         y = barb - i ;
  620.         SetAPen(window->RPort, (long)cell[i]);
  621.         Move(window->RPort, xl, y);
  622.         Draw(window->RPort, xr, y);
  623.         i++ ;
  624.         }
  625. }
  626.  
  627. void shake()    /* this subprogram slings down the mercury column */
  628.     {
  629.     int i;
  630.  
  631.     for (i = 0; i < barh; i++)  {
  632.         cell[i] = YELP ;
  633.         }
  634. }
  635.  
  636. void lockout()  /* this subprogram renders a whole column in border colors */
  637.     {
  638.     (void) handle_MESSAGES() ;        /* go see if the user wants anything */
  639.     if (intsig == FALSE)  {
  640.         SetAPen(window->RPort, WHTP) ;          /* set in the border color */
  641.         RectFill(window->RPort, xl, (barb - barh + 1), xr, barb) ; /* fill */
  642.         }
  643. }
  644.  
  645. void updatewarps( wf, membase, memseg )  /* this subprogram finds changes */
  646. short wf;
  647. long membase, memseg ;
  648.     {
  649.     register long i ;
  650.     register ULONG r ;
  651.     register ULONG delta ;
  652.     register ULONG *a ;
  653.  
  654.     if (memseg == 0) {
  655.         (void) lockout() ;
  656.         return ;
  657.         }
  658.     else (void) shake() ;
  659.  
  660.     delta = (ULONG)(memseg & EVENMASK) ;  /* try to avoid odd address trap */
  661.     r = (ULONG)(membase & EVENMASK) ;     /* prefer wrong address to death */
  662.     for (i = 0; i < barh; i++)  {
  663.         csum[i] = 0 ;
  664.         }
  665.     for (i = 0; i < barh; i++)  {
  666.         for (a = (ULONG *)r; a < (ULONG *)(r + delta); a++)  {
  667.             csum[i] ^= *a ;
  668.             }
  669.         if (oldcsum[i] != 0)  cell[i] ^= GRNP ;       /* enters with pens  */
  670.         if (csum[i] == oldcsum[i])  cell[i] &= GRNP ; /* all on, condition */
  671.         if (csum[i] == 0)  cell[i] ^= CYNP ;          /* detected clears a */
  672.         if (oldcsum[i] == 0xffffffff) cell[i] = CYNP ;/* pen; at the end a */
  673.         if (csum[i] == 0xffffffff)  cell[i] = GRNP ;  /* logical true sets */
  674.         oldcsum[i] = csum[i] ;                        /* a pen not yet set */
  675.         r += delta ;
  676.         }
  677.     (void) memometer();
  678. }
  679.  
  680. void updatescreen( wf, membase, memseg )
  681. short wf;
  682. long membase, memseg;
  683.     {
  684.     register long size ;
  685.     register struct MemHeader *hdr ;
  686.     register struct MemChunk *chunk ;
  687.     extern struct ExecBase *SysBase ;
  688.     register long *which ;                /* active memlist chunk pointer */
  689.     register long newlimit ;  /* number of chunks, incl 1 null chunk, + 1 */
  690.     register long newfrags ;  /* number of chunks, incl null chunks, + 1  */
  691.     long newsize ;  /* size of next request for chunkv/sizev memory, + 1  */
  692.     int i, j, k, l ;
  693.     int length ;       /* length is number of chunks to be processed, + 1 */
  694.     BOOL cf, nf ;      /* cf is "chip flag" nf is "null chunk found" flag */
  695.  
  696.     if (memseg == 0) {
  697.         (void) lockout() ;
  698.         return;
  699.         }
  700.     else (void) shake() ;
  701.  
  702.     for (i = 0; i < 3; i++) {
  703.         chip[i] = 0;
  704.         fast[i] = 0;
  705.         }
  706.     for (i = 0; i < frags; i++) {
  707.         chunkv[i] = 0;
  708.         sizev[i] = 0;
  709.         }
  710.     newfrags = 0 ;
  711.     newlimit = 0 ;
  712.     nf = FALSE;
  713.     Forbid() ;
  714.     hdr = (struct MemHeader *) SysBase->MemList.lh_Head ;
  715.     while (hdr->mh_Node.ln_Succ) {
  716.         if (hdr->mh_Attributes & MEMF_CHIP) {
  717.             which = chip ;
  718.             cf = TRUE;
  719.             }
  720.         else {
  721.             which = fast ;
  722.             cf = FALSE;
  723.             }
  724.         if (((cf == TRUE) && (wf == 0)) || ((cf == FALSE) && (wf > 0)))  {
  725.             for (chunk = hdr->mh_First; chunk; chunk = chunk->mc_Next) {
  726.                 if (which[1] < frags)  chunkv[which[1]++] = (unsigned long)chunk ;
  727.                 size = chunk->mc_Bytes ;
  728.                 if (which[2] < frags)  sizev[which[2]++] = (unsigned long)size;
  729.                 *which += size ;
  730.                 if (nf == FALSE)  {
  731.                     newlimit++ ;
  732.                     if (chunkv[newfrags] == NULL)  {
  733.                         nf = TRUE;
  734.                         }
  735.                     }
  736.                 newfrags++ ;
  737.             }
  738.         }
  739.         hdr = (struct MemHeader *)hdr->mh_Node.ln_Succ ;
  740.         }
  741.     Permit() ;
  742.     length = frags ;
  743.     if (newlimit < frags)  length = newlimit ;
  744.     for (i = 0; i < length; i++)  {
  745.         chunkv[i] -= membase;   /* chunkv is now array offset from base   */
  746.         sizev[i] += chunkv[i];  /* and sizev is now address of array top  */
  747.         chunkv[i] = chunkv[i] / memseg;  /* this is the number of pixels  */
  748.         sizev[i] = sizev[i] / memseg;       /* and this is the top pixel  */
  749.         if (chunkv[i] < 0) chunkv[i] = 0 ;  /* we do some bounds checking */
  750.         if (sizev[i] < 0) sizev[i] = 0 ;
  751.         if (chunkv[i] >= barh) chunkv[i] = barh - 1 ;
  752.         if (sizev[i] >= barh) sizev[i] = barh - 1 ;
  753.         if (sizev[i] - chunkv[i] < 0)  sizev[i] = chunkv[i] ;
  754.         j = chunkv[i] ; /* from now on it will be less confusing if */
  755.         k = sizev[i] ;  /* we assign some variables for this stuff  */
  756.         if (sizev[i] - chunkv[i] == 0)  {
  757.             cell[j] &= BLUP ;
  758.             }
  759.         else  {
  760.             for (l = j; l < k; l++)  {
  761.                 cell[l] &= BLKP ;
  762.                 }
  763.             }
  764.         }
  765.     (void) memometer();
  766.     newsize = frags ;
  767.     while (newsize < newlimit)  {
  768.         newsize += EXTENSION ;
  769.         }
  770.     if (newlimit > frags)  {
  771.         (void) FreeMem(chunkv, (long)(sizeof(long) * frags));
  772.         if ((chunkv = (unsigned long *)AllocMem((long)sizeof(long) * newsize,
  773.                                         MEMF_PUBLIC)) == 0L )  {
  774.             log = log & C2 ;
  775.             }
  776.         (void) FreeMem(sizev, (long)(sizeof(long) * frags));
  777.         if ((sizev = (unsigned long *)AllocMem((long)sizeof(long) * newsize,
  778.                                         MEMF_PUBLIC)) == 0L ) {
  779.             (void) FreeMem(chunkv, (long)(sizeof(long) * newsize));
  780.             log = log & C4 ;
  781.             }
  782.         if (log != SOK)  {
  783.             wrack_sploot() ;
  784.             things_are_cool = FALSE ;
  785.             }
  786.         else frags = newsize ;
  787.         }
  788. }
  789.  
  790. main() {
  791.     static struct IntuiText bodyText0 =
  792.         {BLUP, WHTP, JAM2, 58, 10, NULL, NULL, NULL};
  793.     static struct IntuiText bodyText1 =
  794.         {BLUP, WHTP, JAM2, 42, 20, NULL, NULL, NULL};
  795.     static struct IntuiText bodyText2 =
  796.         {BLUP, WHTP, JAM2, 50, 30, NULL, NULL, NULL};
  797.     static struct IntuiText positiveText =
  798.         {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL};
  799.     static struct IntuiText negativeText =
  800.         {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL};
  801.     struct IntuiMessage *message;
  802.     ULONG class;
  803.     USHORT code;
  804.     ULONG wakeupbits;
  805.     long syspri;
  806.     char *nptr;
  807.     struct Task *mmtcb;
  808.     char oldpri;
  809.     int t;
  810.     int i;
  811.     USHORT colflags;     /* keeps track of column positions and counts */
  812.     USHORT left;         /* left   column, left edge */
  813.     USHORT middle;       /* middle column, left edge */
  814.     USHORT right;        /* right  column, left edge */
  815.     USHORT barw;         /* width of each mercury column */
  816.     USHORT wf;           /* memometer window current column number */
  817.     long cmemseg;
  818.     long sfmemseg;
  819.     long fmemseg;
  820.     long membase;
  821.     long memseg;
  822.     long memsize;
  823.  
  824.     bodyText0.IText = (UBYTE *) "WARNING! CRASH POSSIBLE";
  825.     bodyText1.IText = (UBYTE *) "MENU MEMORY SELECTIONS MUST";
  826.     bodyText2.IText = (UBYTE *) "REFERENCE EXISTING MEMORY";
  827.     bodyText0.NextText = &bodyText1;
  828.     bodyText1.NextText = &bodyText2;
  829.     positiveText.IText = (UBYTE *) "Risk It";
  830.     negativeText.IText = (UBYTE *) "Retreat";
  831.  
  832.     log = 0 ;
  833.     if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * BARS,
  834.                                         MEMF_PUBLIC)) != 0L ) log = log | S1;
  835.     if ((chunkv = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL,
  836.                                         MEMF_PUBLIC)) != 0L ) log = log | S2;
  837.     if ((sizev = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL,
  838.                                         MEMF_PUBLIC)) != 0L ) log = log | S4;
  839.     if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS,
  840.                                         MEMF_PUBLIC)) != 0L ) log = log | S8;
  841.     if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS,
  842.                                         MEMF_PUBLIC)) != 0L ) log = log | SA;
  843.     if (log != SOK)  {
  844.         wrack_sploot() ;
  845.         exit(AARRRGH) ;
  846.         }
  847.     if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary(
  848.             "intuition.library",33L)) != NULL &&
  849.             (window=OpenWindow(&newwindow)) != NULL)  {
  850.         if ((GfxBase = (struct GfxBase *)OpenLibrary(
  851.                 "graphics.library", 0L)) != NULL)  { 
  852.             (void) initmenus();
  853.             /* rp = window->RPort ; */
  854.             inittimer();
  855.             wf = 0;
  856.             mmode = FALSE ;
  857.             mode = FRAGS ;
  858.             delayval = p_rate ;
  859.             priority = p_priority ;
  860.             if (priority > 0)  priority = 0 ;
  861.             lastpri = priority ;
  862.             syspri = priority ;
  863.             nptr = NULL ;
  864.             mmtcb = FindTask( nptr ) ;
  865.             oldpri = SetTaskPri( mmtcb, syspri ) ;
  866.             cmemsize = p_chip << 10 ;
  867.             cmembase = p_chipa << 10 ;
  868.             sfmemsize = p_sf << 10 ;
  869.             sfmembase = p_sfa << 10 ;
  870.             if (p_fast >= 512)  fmemsize = p_fast << 10 ;
  871.             else fmemsize = p_fast << 20 ;
  872.             fmembase = p_fasta << 20 ;
  873.             while (things_are_cool == TRUE) {
  874.                 if (chgflag != 0)  {
  875.                     chgflag = 0 ;
  876.                     colflags = 0 ;
  877.                     if (cmemsize != 0)  colflags = colflags | (1 << 0) ;
  878.                     if (sfmemsize != 0)  colflags = colflags | (1 << 1) ;
  879.                     if (fmemsize != 0)  colflags = colflags | (1 << 2) ;
  880.                     switch ( colflags ) {
  881.                         case 0:
  882.                         barw = (WINW - (2 * BORDER)) - 1 ;
  883.                         left = LEFT ;
  884.                         middle = 0 ;
  885.                         right = 0 ;
  886.                         f_text.FrontPen = ORNP ;
  887.                         break ;
  888.  
  889.                         case 1:
  890.                         barw = (WINW - (2 * BORDER)) - 1 ;
  891.                         left = LEFT ;
  892.                         middle = 0 ;
  893.                         right = 0 ;
  894.                         f_text.FrontPen = BLUP ;
  895.                         break ;
  896.  
  897.                         case 2:
  898.                         barw = (WINW - (2 * BORDER)) - 1 ;
  899.                         left = 0 ;
  900.                         middle = LEFT ;
  901.                         right = 0 ;
  902.                         f_text.FrontPen = CYNP ;
  903.                         break ;
  904.  
  905.                         case 3:
  906.                         barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  907.                         left = LEFT ;
  908.                         middle = (left + barw + 1) ;
  909.                         right = 0 ;
  910.                         f_text.FrontPen = BLUP ;
  911.                         break ;
  912.  
  913.                         case 4:
  914.                         barw = (WINW - (2 * BORDER)) - 1 ;
  915.                         left = 0 ;
  916.                         middle = 0;
  917.                         right = LEFT ;
  918.                         f_text.FrontPen = YELP ;
  919.                         break ;
  920.  
  921.                         case 5:
  922.                         barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  923.                         left = LEFT ;
  924.                         middle = 0 ;
  925.                         right = (left + barw + 1) ;
  926.                         f_text.FrontPen = CYNP ;
  927.                         break ;
  928.  
  929.                         case 6:
  930.                         barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  931.                         left = 0 ;
  932.                         middle = LEFT ;
  933.                         right = (middle + barw + 1) ;
  934.                         f_text.FrontPen = YELP ;
  935.                         break ;
  936.  
  937.                         case 7:
  938.                         barw = ((WINW - (2 * BORDER)) / 3 ) - 1 ;
  939.                         left = LEFT ;
  940.                         middle = (left + barw + 1) ;
  941.                         right = (middle + barw + 1) ;
  942.                         f_text.FrontPen = BLUP ;
  943.                         break ;
  944.                         }  /* end of switch ( colflags ) */
  945.                     }  /* end of if ( chgflag ) */
  946.                 cmemseg = cmemsize / barh ;
  947.                 sfmemseg = sfmemsize / barh ;
  948.                 fmemseg = fmemsize / barh ;
  949.                 if (mmode == TRUE && ((sfmemsize != 0) ||
  950.                                       (fmembase != 0x200000)))  {
  951.                     /* Keep your eyes open here.  If we get a negative    */
  952.                     /* response from the requester, that means either the */
  953.                     /* user retreated, or a no-requester function such as */
  954.                     /* noreq or KillReq has selected the negative option. */
  955.                     /* If such functions select the positive option they  */
  956.                     /* force acceptance of the crash risk with SFmemory.  */
  957.  
  958.                     mode = AutoRequest(window, &bodyText0, &positiveText,
  959.                                &negativeText, 0L, 0L, 319L, 79L) ;
  960.                     }
  961.                 if (mmode == TRUE && ((sfmemsize != 0) ||
  962.                                       (fmembase != 0x200000)))  {
  963.                     if (mode == FRAGS)  {      /* user Retreat select  */
  964.                         sfmemseg = 0 ;         /* results in execution */
  965.                         sfmemsize = 0 ;        /* of this code segment */
  966.                         fmembase = 0x200000 ;  /* resetting internals  */
  967.                         }
  968.                     }
  969.                 switch ( wf ) {
  970.                     case 0:
  971.                     xl = left ;
  972.                     membase = cmembase ;
  973.                     memseg = cmemseg ;
  974.                     memsize = cmemsize ;
  975.                     break;
  976.  
  977.                     case 1:
  978.                     xl = middle ;
  979.                     membase = sfmembase ;
  980.                     memseg = sfmemseg ;
  981.                     memsize = sfmemsize ;
  982.                     break;
  983.  
  984.                     case 2:
  985.                     xl = right ;
  986.                     membase = fmembase ;
  987.                     memseg = fmemseg ;
  988.                     memsize = fmemsize ;
  989.                     break;
  990.                     }  /* end of switch ( wf ) */
  991.                 xr = xl + barw ;
  992.                 if (mmode == TRUE)  {
  993.                     mode = WARPS ;
  994.                     mmode = FALSE ;
  995.                     }
  996.                 if (xl != 0)  {
  997.                     if (mode == WARPS)  {
  998.                         (void) updatewarps( wf, membase, memseg ) ;
  999.                         e_text.FrontPen = YELP ;
  1000.                         }
  1001.                     if (mode == FRAGS)  {
  1002.                         (void) updatescreen( wf, membase, memseg ) ;
  1003.                         e_text.FrontPen = BLUP ;
  1004.                         }
  1005.                     }
  1006.                 if (intsig == TRUE)  {
  1007.                     handle_NEWSIZE() ;
  1008.                     intsig = FALSE ;
  1009.                     }
  1010.                 if (syspri != priority)  {
  1011.                     syspri = priority ;
  1012.                     nptr = NULL;
  1013.                     mmtcb = FindTask( nptr ) ;
  1014.                     oldpri = SetTaskPri( mmtcb, syspri ) ;
  1015.                     }
  1016.                 if (wf == 2)  {
  1017.                     PrintIText(window->RPort,&f_text,RTEXT,0L) ;
  1018.                     wakeupbits = Wait(timerbit) ;
  1019.                     if (wakeupbits & timerbit)  {
  1020.                         GetMsg(timerport);
  1021.                         SetTimer(delayval, 0L, timermsg);
  1022.                         }
  1023.                     }
  1024.                 wf++ ;
  1025.                 if (wf >= 3)  wf = 0 ;
  1026.                 } /* end of while ( things_are_cool) */
  1027.  
  1028.             if (timerport) {
  1029.                 Wait(timerbit);
  1030.                 GetMsg(timerport);
  1031.                 CloseDevice(timermsg);
  1032.                 DeleteStdIO(timermsg);
  1033.                 DeletePort(timerport);
  1034.                 }
  1035.  
  1036.             if (GfxBase)    CloseLibrary(GfxBase) ;
  1037.             }
  1038.         if (window)         CloseWindow(window) ;
  1039.         if (IntuitionBase)  CloseLibrary(IntuitionBase) ;
  1040.         }
  1041.     wrack_sploot() ;
  1042. }
  1043.  
  1044. _cli_parse() {}
  1045. _wb_parse() {}
  1046.