Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!news.larc.nasa.gov!amiga-request From: amiga-request@ab20.larc.nasa.gov (Amiga Sources/Binaries Moderator) Newsgroups: comp.sources.amiga Subject: v91i121: MemMometer 2.20 - memory gauge, Part02/02 Message-ID: Date: 14 Jun 91 22:30:41 GMT References: Reply-To: hull@hao.ucar.edu (Howard Hull) Lines: 2058 Approved: tadguy@uunet.UU.NET (Tad Guy) X-Mail-Submissions-To: amiga@uunet.uu.net X-Post-Discussions-To: comp.sys.amiga.misc Submitted-by: hull@hao.ucar.edu (Howard Hull) Posting-number: Volume 91, Issue 121 Archive-name: utilities/memometer-2.20/part02 #!/bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'mm.c' <<'END_OF_FILE' X/* : ai=0 bk=0 ts=8 */ X#include "mm.h" X X#define FREEPEN -1L /* workbench screen default colors */ X#define REQ_WINDOW_WIDTH 319L /* width of warning requester window */ X#define REQ_WINDOW_HEIGHT 79L /* height of warning requester window */ X X#define SOK 0x001f /* memory allocation control masks */ X#define S1 0x0001 X#define S2 0x0002 X#define S4 0x0004 X#define S8 0x0008 X#define SA 0x0010 X#define C1 0xfffe X#define C2 0xfffd X#define C4 0xfffb X#define C8 0xfff7 X#define CA 0xffef X#define AARRRGH 20L /* hang 20, cats, we're startin ta curl! */ X X#define EXTENSION 16L /* allocation request increment */ X X#define FRAGS FALSE /* frags mode control boolian */ X#define WARPS TRUE /* warps mode control boolian */ X#define EVENMASK 0x7ffffffe /* used to prevent odd address traps */ X#define CLIHEIGHT 200L /* window scaling stuff */ X#define SIZEGAD 9L X#define DRAGBAR 10L X#define BORDER 2L X#define WINW 16L /* initial window width */ X#define WINH (long)(CLIHEIGHT - SIZEGAD - DRAGBAR) /* initial win height */ X#define MINH 81L /* shortest allowable window */ X#define MAXH 576L /* longest allowable window */ X#define BART 1L /* title bar F text location */ X#define BARH (long)(WINH - SIZEGAD - DRAGBAR) /* bar height */ X#define BARS (long)(BARH + 1) /* number of memory items to allocate */ X#define BARB (long)(BARH + DRAGBAR - 1) /* bottom of mercury column */ X#define BARE (long)(BARB + BORDER) /* bar end E text position */ X#define BARW (long)(((WINW - (2 * BORDER)) / 3) - 1) /* 3 memfragmometers */ X#define LEFT BORDER /* SLOW : since we're syncopated, we */ X#define MIDDLE (LEFT + BARW + 1) /* SLOW-FAST : do it going from bar */ X#define RIGHT (MIDDLE + BARW + 1) /* FAST :to bar at an irregular pace */ X#define RTEXT - 4L /* offset for three char E/F text from left edge */ X#define STARTVAL 64L /* start by getting enough storage for a few frags */ X#define TMARK 100000L /* timer granule in microseconds */ X#define TICKIES (long)(1000000/TMARK) /* number of TMARKS per second */ X X/* typedef short BOOL */ /* this is in include/exec/types.h */ X Xstruct IntuitionBase *IntuitionBase=NULL ; Xstruct Window *window ; Xstruct IntuiMessage *message; X/* struct IntuiMessage *GetMsg(); */ /* in functions.h */ X Xstruct GfxBase *GfxBase=NULL ; X Xstruct IOStdReq *timermsg=NULL; Xstruct MsgPort *timerport=NULL; XULONG timerbit=NULL; X X Xextern void InitProjItems(); /* this stuff is in the mminit section */ Xextern void InitSetupItems(); Xextern void InitPrioItems(); Xextern void InitChipItems(); Xextern void InitChipAItems(); Xextern void InitSFItems(); Xextern void InitSFAItems(); Xextern void InitFastItems(); Xextern void InitFastAItems(); Xextern void InitMenu(); Xextern void StartMenus(); X XBOOL p_mode = FRAGS; /* preset frags mode = 0, warps mode = 1 */ X /* note: mode preset used as request for */ X /* change to warps mode after the */ X /* first pass with frags mode set! */ Xlong p_rate = 2; /* preset sample interval, secs see menu */ Xlong p_priority = 0; /* preset priority, range -128 to +127 */ X /* note: pri greater than zero is risky! */ X /* keep in mind AmigaDOS priorities: */ X /* input.device 20, FileSystem 10, and */ X /* trackdisk.device, CON: 5 also if MM */ X /* is started from a CLI without the Run */ X /* then that CLI inherits MM's priority! */ Xlong p_chip = 512; /* preset chip mem size, kbytes see menu */ Xlong p_chipa = 0; /* preset chip mem address, kb see menu */ Xlong p_sf = 0; /* preset slowfast mem size, kb see menu */ Xlong p_sfa = 2048; /* preset slowfast mem addr, kb see menu */ Xlong p_fast = 0; /* preset fast mem size, mbytes see menu */ Xlong p_fasta = -1; /* preset fast mem addr, mbytes see menu */ X /* zero or neg fasta is offset below the */ X /* A3000 fast ram ceiling, aka 0x7000000 */ X Xstatic BOOL mode; /* uninitialized for mode control */ Xstatic BOOL mmode; /* uninitialized for mode menu */ Xstatic long delayval; /* uninitialized for delay menu */ Xstatic long priority; /* uninitialized for priority menu */ Xstatic long lastpri; /* uninitialized for priority incr */ Xstatic long cmemsize; /* uninitialized for chip menu */ Xstatic long cmembase; /* uninitialized for chipa menu */ Xstatic long sfmemsize; /* uninitialized for sf menu */ Xstatic long sfmembase; /* uninitialized for sfa menu */ Xstatic long fmemsize; /* uninitialized for fast menu */ Xstatic long fmembase; /* uninitialized for fasta menu */ X Xstatic USHORT log ; /* memory allocation success flags */ Xstatic BOOL things_are_cool = TRUE ; /* tells when to close the window */ Xstatic BOOL intsig = FALSE ; /* intuition message detector */ Xstatic USHORT chgflag = TRUE ; /* menu request to adjust columns */ Xstatic long chip[3], fast[3] ; /* place to keep mem header pointers */ Xstatic ULONG *chunkv ; /* demand allocated for frag chunks */ Xstatic ULONG *sizev ; /* demand allocated for frag sizes */ Xstatic ULONG *csum ; /* a col's height worth of checksums */ Xstatic ULONG *oldcsum ; /* same height worth of old checksums */ Xstatic USHORT *cell; /* 1 cell per pixel height of mercury */ Xstatic long xl, xr ; /* used to Draw() memmometer segments */ Xstatic long frags = STARTVAL ; /* # of demand allocated frag items */ Xstatic long warps = BARS ; /* # of demand allocated column items */ Xstatic long barh = BARH ; /* EVEN #'d height of mercury column */ Xstatic long barb = BARB ; /* bottom position of mercury column */ Xstatic short ticker = TICKIES ; /* initialized delay tick variable */ X X/* struct RastPort *rp ; */ /* wonder why we don't need this... ? */ X X Xstatic struct TextAttr myfont = { X (STRPTR) "topaz.font", X TOPAZ_EIGHTY, X 0, X 0 X}; X/* E newsize gadget refresh text */ Xstatic char ebuf[4] = " E " ; Xstatic struct IntuiText e_text = { X BLUP, WHTP, X JAM2, X 0, BARE, X &myfont, X (UBYTE *)ebuf, X NULL X}; X/* F title refresh text */ Xstatic char fbuf[4] = " F " ; Xstatic struct IntuiText f_text = { X BLUP, WHTP, X JAM2, X 0, BART, X &myfont, X (UBYTE *)fbuf, X &e_text X}; Xstatic struct NewWindow newwindow = { X 0, /* left edge */ X 10, /* top edge */ X WINW, /* width */ X WINH, /* height */ X 0, /* detail pen */ X 1, /* block pen */ X MENUPICK | NEWSIZE, /* messages */ X/* WINDOWDEPTH | WINDOWCLOSE */ /* don't use these gads */ X WINDOWDRAG | WINDOWSIZING | NOCAREREFRESH, /* add a few gadgets */ X NULL, /* no custom gadgets */ X NULL, /* default checkmark */ X (UBYTE *)"F", /* title */ X NULL, /* initialize this! */ X NULL, /* use screen bitmap */ X WINW, MINH, WINW, MAXH, /* min and max sizes */ X WBENCHSCREEN } ; /* use workbench screen */ X Xvoid initmenus() X{ X (void) InitProjItems(); /* Initialize the menu items */ X (void) InitSetupItems(); X (void) InitPrioItems(); X (void) InitChipItems(); X (void) InitChipAItems(); X (void) InitSFItems(); X (void) InitSFAItems(); X (void) InitFastItems(); X (void) InitFastAItems(); X (void) InitMenu(); X (void) StartMenus(); X } X Xvoid handle_MENUPICK( class, code ) Xunsigned long class; Xunsigned int code; X{ X unsigned int menunum, itemnum, subnum; X X if (code == MENUNULL) return; X X menunum = MENUNUM( code ); X itemnum = ITEMNUM( code ); X subnum = SUBNUM( code ); X chgflag = TRUE; X switch( menunum ) { X case 0: X switch( itemnum ) { X case 0: X WindowToFront(window); X break; X X case 1: X WindowToBack(window); X break; X X case 2: X things_are_cool = FALSE; /* Quit */ X break; X } /* end of switch ( Project itemnum ) */ X break; X X case 1: X switch( itemnum ) { X case 0: X switch( subnum ) { X case 0: X mode = FRAGS ; /* Frags mode */ X break; X X case 1: X mmode = TRUE ; /* Warps request */ X break; X /* end of switch ( Mode subnum ) */ X } X break; X case 1: X switch( subnum ) { X case 0: X delayval = 1; X break; X X case 1: X delayval = 2; X break; X X case 2: X delayval = 5; X break; X X case 3: X delayval = 10; X break; X /* end of switch ( Freq subnum ) */ X } X break; X /* end of switch ( Setup itemnum ) */ X } X break; X X case 2: X switch( itemnum ) { X case 0: X priority = lastpri; X break; X X case 1: X priority = priority - 1; X break; X X case 2: X priority = priority + 1; X break; X X case 3: X priority = -99; X lastpri = priority; X break; X X case 4: X priority = -75; X lastpri = priority; X break; X X case 5: X priority = -50; X lastpri = priority; X break; X X case 6: X priority = -25; X lastpri = priority; X break; X X case 7: X priority = -20; X lastpri = priority; X break; X X case 8: X priority = -15; X lastpri = priority; X break; X X case 9: X priority = -10; X lastpri = priority; X break; X X case 10: X priority = -5; X lastpri = priority; X break; X X case 11: X priority = 0; X lastpri = priority; X break; X X case 12: X priority = 5; X lastpri = priority; X break; X X case 13: X priority = 10; X lastpri = priority; X break; X X case 14: X priority = 15; X lastpri = priority; X break; X X case 15: X priority = 20; X lastpri = priority; X break; X } X /* end of switch ( Priority itemnum ) */ X break; X X case 3: X switch( itemnum ) { X case 0: X cmemsize = 0x000000; X break; X X case 1: X cmemsize = 0x040000; X break; X X case 2: X cmemsize = 0x080000; X break; X X case 3: X cmemsize = 0x100000; X break; X X case 4: X cmemsize = 0x200000; X break; X } X /* end of switch ( Chip Size itemnum ) */ X break; X X case 4: X switch( itemnum ) { X case 0: X cmembase = 0x000000; X break; X X case 1: X cmembase = 0x040000; X break; X X case 2: X cmembase = 0x080000; X break; X X case 3: X cmembase = 0x100000; X break; X } X /* end of switch ( Chip Addr itemnum ) */ X break; X X case 5: X if (mode == WARPS) mmode = TRUE ; X switch( itemnum ) { X case 0: X sfmemsize = 0x000000; X break; X X case 1: X sfmemsize = 0x040000; X break; X X case 2: X sfmemsize = 0x080000; X break; X X case 3: X sfmemsize = 0x0C0000; X break; X X case 4: X sfmemsize = 0x100000; X break; X X case 5: X sfmemsize = 0x180000; X break; X X case 6: X sfmemsize = 0x200000; X break; X X case 7: X sfmemsize = 0x300000; X break; X X case 8: X sfmemsize = 0x400000; X break; X X case 9: X sfmemsize = 0x600000; X break; X X case 10: X sfmemsize = 0x800000; X break; X } X /* end of switch ( SF Size itemnum ) */ X break; X X case 6: X if (mode == WARPS) mmode = TRUE ; X switch( itemnum ) { X case 0: X sfmembase = 0x200000; X break; X X case 1: X sfmembase = 0x240000; X break; X X case 2: X sfmembase = 0x280000; X break; X X case 3: X sfmembase = 0x2C0000; X break; X X case 4: X sfmembase = 0x300000; X break; X X case 5: X sfmembase = 0x400000; X break; X X case 6: X sfmembase = 0x500000; X break; X X case 7: X sfmembase = 0x600000; X break; X X case 8: X sfmembase = 0x700000; X break; X X case 9: X sfmembase = 0x800000; X break; X X case 10: X sfmembase = 0x900000; X break; X X case 11: X sfmembase = 0xC00000; X break; X X case 12: X sfmembase = 0xC40000; X break; X X case 13: X sfmembase = 0xC80000; X break; X X case 14: X sfmembase = 0xCC0000; X break; X X case 15: X sfmembase = 0xD00000; X break; X } X /* end of switch ( SF Addr itemnum ) */ X break; X X case 7: X if (mode == WARPS) mmode = TRUE ; X switch( itemnum ) { X case 0: X fmemsize = 0x000000; X break; X X case 1: X fmemsize = 0x040000; X break; X X case 2: X fmemsize = 0x080000; X break; X X case 3: X fmemsize = 0x0C0000; X break; X X case 4: X fmemsize = 0x100000; X break; X X case 5: X fmemsize = 0x200000; X break; X X case 6: X fmemsize = 0x300000; X break; X X case 7: X fmemsize = 0x400000; X break; X X case 8: X fmemsize = 0x600000; X break; X X case 9: X fmemsize = 0x800000; X break; X X case 10: X fmemsize = 0xa000000; X break; X X case 11: X fmemsize = 0xc00000; X break; X X case 12: X fmemsize = 0xd00000; X break; X X case 13: X fmemsize = 0xe00000; X break; X X case 14: X fmemsize = 0xf00000; X break; X X case 15: X fmemsize = 0x1000000; X break; X } X /* end of switch ( Fast Size itemnum ) */ X break; X X case 8: X if (mode == WARPS) mmode = TRUE ; X switch( itemnum ) { X case 0: X fmembase = 0x200000; X break; X X case 1: X fmembase = 0x300000; X break; X X case 2: X fmembase = 0x400000; X break; X X case 3: X fmembase = 0x500000; X break; X X case 4: X fmembase = 0x600000; X break; X X case 5: X fmembase = 0x800000; X break; X X case 6: X fmembase = 0x7f0000; X break; X X case 7: X fmembase = 0x7e0000; X break; X X case 8: X fmembase = 0x7d00000; X break; X X case 9: X fmembase = 0x7c00000; X break; X X case 10: X fmembase = 0x7a00000; X break; X X case 11: X fmembase = 0x7800000; X break; X X case 12: X fmembase = 0x7600000; X break; X X case 13: X fmembase = 0x7400000; X break; X X case 14: X fmembase = 0x7200000; X break; X X case 15: X fmembase = 0x7000000; X break; X } X /* end of switch ( Fast Addr itemnum ) */ X break; X } X /* end of switch ( menunum ) */ X} X Xvoid wrack_sploot() /* this subprogram cashes in the chips in bad times */ X { X if (log != 0) { X if (log & SA) { X (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ; X log = log & CA ; X } X if (log & S8) { X (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ; X log = log & C8 ; X } X if (log & S4) { X (void) FreeMem(sizev, (long)(sizeof(long) * frags)) ; X log = log & C4 ; X } X if (log & S2) { X (void) FreeMem(chunkv, (long)(sizeof(long) * frags)) ; X log = log & C2 ; X } X if (log & S1) { X (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ; X log = log & C1 ; X } X frags = 0; X warps = 0; X } X} X XSetTimer(sec, micro, timermsg) XULONG sec, micro; Xstruct IOStdReq *timermsg; X/* This routine simply sets the timer to interrupt us after secs.micros */ X{ X timermsg->io_Command = TR_ADDREQUEST; /* add a new timer request */ X timermsg->io_Actual = sec; /* seconds */ X timermsg->io_Length = micro; /* microseconds */ X SendIO(timermsg); /* post a request to the timer */ X} X Xvoid cleanup() { X if (timerport) { X Wait(timerbit); X GetMsg(timerport); X CloseDevice(timermsg); X DeleteStdIO(timermsg); X DeletePort(timerport); X } X if (GfxBase) CloseLibrary(GfxBase) ; X if (window) CloseWindow(window) ; X if (IntuitionBase) CloseLibrary(IntuitionBase) ; X wrack_sploot() ; X exit(AARRRGH) ; X} X Xvoid inittimer() { X if(!(timerport = (struct MsgPort *)CreatePort(0L, 0L)))cleanup(); X if(!(timermsg = (struct IOStdReq *)CreateStdIO(timerport)))cleanup(); X if (OpenDevice(TIMERNAME, UNIT_VBLANK, timermsg, 0L))cleanup(); X X timerbit = 1L << timerport->mp_SigBit ; X SetTimer(1L, 0L, timermsg); /* set for first message */ X} X Xvoid handle_NEWSIZE() /* short term allocations cashed in then realloc'd */ X { /* when user hits gadget but doesn't resize window */ X if (log & SA) { X (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ; X log = log & CA ; X } X if (log & S8) { X (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ; X log = log & C8 ; X } X if (log & S1) { X (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ; X log = log & C1 ; X barh = window->Height - SIZEGAD - DRAGBAR ; /* recalculate height */ X barb = window->Height - SIZEGAD - 1 ; /* get new bar base position */ X warps = barh + 1 ; /* number of storage cells to be reserved */ X if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * warps, X MEMF_PUBLIC)) != 0L ) log = log | S1; X if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps, X MEMF_PUBLIC)) != 0L ) log = log | S8; X if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps, X MEMF_PUBLIC)) != 0L ) log = log | SA; X if (log != SOK) { /* bail out if we didn't get an allocation */ X wrack_sploot() ; X things_are_cool = FALSE ; /* tell _main that we're leaving */ X } X e_text.TopEdge = barb + BORDER ; /* set the E text position */ X intsig = FALSE ; X } X} X Xvoid handle_MESSAGES() { X unsigned long class; X unsigned int code, qual; X X /* Wait (1L << window->UserPort->mp_SigBit); this is rediculous! */ X while ((message=(struct IntuiMessage *)GetMsg(window->UserPort)) X != 0L) { X class = message->Class ; X code = message->Code ; X qual = message->Qualifier ; X ReplyMsg ; X ticker = 0 ; /* cut short the timer to expedite service */ X switch( class ) { X case MENUPICK: X handle_MENUPICK( class, code ) ; /* do menus ASAP */ X break ; X X case NEWSIZE: X intsig = TRUE ; /* resize when done here */ X break ; X } X } X} X Xvoid memmometer() /* this subprogram draws the bar graphs */ X { X long i; X long y; X X (void) handle_MESSAGES() ; /* go see if the user wants anything */ X i = 0 ; X while ((i < barh) && (intsig == FALSE)) { X y = barb - i ; X SetAPen(window->RPort, (long)cell[i]); X Move(window->RPort, xl, y); X Draw(window->RPort, xr, y); X i++ ; X } X} X Xvoid shake() /* this subprogram slings down the mercury column */ X { X int i; X X for (i = 0; i < barh; i++) { X cell[i] = YELP ; X } X} X Xvoid lockout() /* this subprogram renders a whole column in border colors */ X { X (void) handle_MESSAGES() ; /* go see if the user wants anything */ X if (intsig == FALSE) { X SetAPen(window->RPort, WHTP) ; /* set in the border color */ X RectFill(window->RPort, xl, (barb - barh + 1), xr, barb) ; /* fill */ X } X} X Xvoid updatewarps( wf, membase, memseg ) /* this subprogram finds changes */ Xshort wf; Xlong membase, memseg ; X { X register long i ; X register ULONG r ; X register ULONG delta ; X register ULONG *a ; X X if (memseg == 0) { X (void) lockout() ; X return ; X } X else (void) shake() ; X X delta = (ULONG)(memseg & EVENMASK) ; /* try to avoid odd address trap */ X r = (ULONG)(membase & EVENMASK) ; /* prefer wrong address to death */ X for (i = 0; i < barh; i++) { X csum[i] = 0 ; X } X for (i = 0; i < barh; i++) { X for (a = (ULONG *)r; a < (ULONG *)(r + delta); a++) { X csum[i] ^= *a ; X } X if (oldcsum[i] != 0) cell[i] ^= GRNP ; /* enters with pens */ X if (csum[i] == oldcsum[i]) cell[i] &= GRNP ; /* all on, condition */ X if (csum[i] == 0) cell[i] ^= CYNP ; /* detected clears a */ X if (oldcsum[i] == 0xffffffff) cell[i] = CYNP ;/* pen; at the end a */ X if (csum[i] == 0xffffffff) cell[i] = GRNP ; /* logical true sets */ X oldcsum[i] = csum[i] ; /* a pen not yet set */ X r += delta ; X } X (void) memmometer(); X} X Xvoid updatescreen( wf, membase, memseg ) Xshort wf; Xlong membase, memseg; X { X register long size ; X register struct MemHeader *hdr ; X register struct MemChunk *chunk ; X extern struct ExecBase *SysBase ; X register long *which ; /* active memlist chunk pointer */ X register long newlimit ; /* number of chunks, incl 1 null chunk, + 1 */ X register long newfrags ; /* number of chunks, incl null chunks, + 1 */ X long newsize ; /* size of next request for chunkv/sizev memory, + 1 */ X int i, j, k, l ; X int length ; /* length is number of chunks to be processed, + 1 */ X BOOL cf, nf ; /* cf is "chip flag" nf is "null chunk found" flag */ X X if (memseg == 0) { X (void) lockout() ; X return; X } X else (void) shake() ; X X for (i = 0; i < 3; i++) { X chip[i] = 0; X fast[i] = 0; X } X for (i = 0; i < frags; i++) { X chunkv[i] = 0; X sizev[i] = 0; X } X newfrags = 0 ; X newlimit = 0 ; X nf = FALSE; X Forbid() ; X hdr = (struct MemHeader *) SysBase->MemList.lh_Head ; X while (hdr->mh_Node.ln_Succ) { X if (hdr->mh_Attributes & MEMF_CHIP) { X which = chip ; X cf = TRUE; X } X else { X which = fast ; X cf = FALSE; X } X if (((cf == TRUE) && (wf == 0)) || ((cf == FALSE) && (wf > 0))) { X for (chunk = hdr->mh_First; chunk; chunk = chunk->mc_Next) { X if (which[1] < frags) chunkv[which[1]++] = (unsigned long)chunk ; X size = chunk->mc_Bytes ; X if (which[2] < frags) sizev[which[2]++] = (unsigned long)size; X *which += size ; X if (nf == FALSE) { X newlimit++ ; X if (chunkv[newfrags] == NULL) { X nf = TRUE; X } X } X newfrags++ ; X } X } X hdr = (struct MemHeader *)hdr->mh_Node.ln_Succ ; X } X Permit() ; X length = frags ; X if (newlimit < frags) length = newlimit ; X for (i = 0; i < length; i++) { X chunkv[i] -= membase; /* chunkv is now array offset from base */ X sizev[i] += chunkv[i]; /* and sizev is now address of array top */ X chunkv[i] = chunkv[i] / memseg; /* this is the number of pixels */ X sizev[i] = sizev[i] / memseg; /* and this is the top pixel */ X if (chunkv[i] < 0) chunkv[i] = 0 ; /* we do some bounds checking */ X if (sizev[i] < 0) sizev[i] = 0 ; X if (chunkv[i] >= barh) chunkv[i] = barh - 1 ; X if (sizev[i] >= barh) sizev[i] = barh - 1 ; X if (sizev[i] - chunkv[i] < 0) sizev[i] = chunkv[i] ; X j = chunkv[i] ; /* from now on it will be less confusing if */ X k = sizev[i] ; /* we assign some variables for this stuff */ X if (sizev[i] - chunkv[i] == 0) { X cell[j] &= BLUP ; X } X else { X for (l = j; l < k; l++) { X cell[l] &= BLKP ; X } X } X } X (void) memmometer(); X newsize = frags ; X while (newsize < newlimit) { X newsize += EXTENSION ; X } X if (newlimit > frags) { X (void) FreeMem(chunkv, (long)(sizeof(long) * frags)); X if ((chunkv = (unsigned long *)AllocMem((long)sizeof(long) * newsize, X MEMF_PUBLIC)) == 0L ) { X log = log & C2 ; X } X (void) FreeMem(sizev, (long)(sizeof(long) * frags)); X if ((sizev = (unsigned long *)AllocMem((long)sizeof(long) * newsize, X MEMF_PUBLIC)) == 0L ) { X (void) FreeMem(chunkv, (long)(sizeof(long) * newsize)); X log = log & C4 ; X } X if (log != SOK) { X wrack_sploot() ; X things_are_cool = FALSE ; X } X else frags = newsize ; X } X} X Xmain() { X static struct IntuiText bodyText0 = X {BLUP, WHTP, JAM2, 58, 10, NULL, NULL, NULL}; X static struct IntuiText bodyText1 = X {BLUP, WHTP, JAM2, 42, 20, NULL, NULL, NULL}; X static struct IntuiText bodyText2 = X {BLUP, WHTP, JAM2, 50, 30, NULL, NULL, NULL}; X static struct IntuiText positiveText = X {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL}; X static struct IntuiText negativeText = X {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL}; X struct IntuiMessage *message; X ULONG class; X USHORT code; X ULONG wakeupbits; X long syspri; X char *nptr; X struct Task *mmtcb; X char oldpri; X int t; X int i; X USHORT colflags; /* keeps track of column positions and counts */ X USHORT left; /* left column, left edge */ X USHORT middle; /* middle column, left edge */ X USHORT right; /* right column, left edge */ X USHORT barw; /* width of each mercury column */ X USHORT wf; /* memmometer window current column number */ X long cmemseg; X long sfmemseg; X long fmemseg; X long membase; X long memseg; X long memsize; X X bodyText0.IText = (UBYTE *) "WARNING! CRASH POSSIBLE"; X bodyText1.IText = (UBYTE *) "MENU MEMORY SELECTIONS MUST"; X bodyText2.IText = (UBYTE *) "REFERENCE EXISTING MEMORY"; X bodyText0.NextText = &bodyText1; X bodyText1.NextText = &bodyText2; X positiveText.IText = (UBYTE *) "Risk It"; X negativeText.IText = (UBYTE *) "Retreat"; X X log = 0 ; X if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * BARS, X MEMF_PUBLIC)) != 0L ) log = log | S1; X if ((chunkv = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL, X MEMF_PUBLIC)) != 0L ) log = log | S2; X if ((sizev = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL, X MEMF_PUBLIC)) != 0L ) log = log | S4; X if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS, X MEMF_PUBLIC)) != 0L ) log = log | S8; X if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS, X MEMF_PUBLIC)) != 0L ) log = log | SA; X if (log != SOK) { X wrack_sploot() ; X exit(AARRRGH) ; X } X if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary( X "intuition.library",33L)) != NULL && X (window=OpenWindow(&newwindow)) != NULL) { X if ((GfxBase = (struct GfxBase *)OpenLibrary( X "graphics.library", 0L)) != NULL) { X (void) initmenus(); X /* rp = window->RPort ; */ X inittimer(); X wf = 0; X mmode = FALSE ; X mode = FRAGS ; X delayval = p_rate ; X priority = p_priority ; X if (priority > 0) priority = 0 ; X lastpri = priority ; X syspri = priority ; X nptr = NULL ; X mmtcb = FindTask( nptr ) ; X oldpri = SetTaskPri( mmtcb, syspri ) ; X cmemsize = p_chip << 10 ; X cmembase = p_chipa << 10 ; X sfmemsize = p_sf << 10 ; X sfmembase = p_sfa << 10 ; X if (p_fast >= 256) fmemsize = p_fast << 10 ; X else fmemsize = p_fast << 20 ; X if (p_fasta <= 0) fmembase = 0x8000000 - ((-1 * p_fasta) << 20) ; X else fmembase = p_fasta << 20 ; X while (things_are_cool == TRUE) { X if (chgflag != 0) { X chgflag = 0 ; X colflags = 0 ; X if (cmemsize != 0) colflags = colflags | (1 << 0) ; X if (sfmemsize != 0) colflags = colflags | (1 << 1) ; X if (fmemsize != 0) colflags = colflags | (1 << 2) ; X switch ( colflags ) { X case 0: X barw = (WINW - (2 * BORDER)) - 1 ; X left = LEFT ; X middle = 0 ; X right = 0 ; X f_text.FrontPen = ORNP ; X break ; X X case 1: X barw = (WINW - (2 * BORDER)) - 1 ; X left = LEFT ; X middle = 0 ; X right = 0 ; X f_text.FrontPen = BLUP ; X break ; X X case 2: X barw = (WINW - (2 * BORDER)) - 1 ; X left = 0 ; X middle = LEFT ; X right = 0 ; X f_text.FrontPen = CYNP ; X break ; X X case 3: X barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ; X left = LEFT ; X middle = (left + barw + 1) ; X right = 0 ; X f_text.FrontPen = BLUP ; X break ; X X case 4: X barw = (WINW - (2 * BORDER)) - 1 ; X left = 0 ; X middle = 0; X right = LEFT ; X f_text.FrontPen = YELP ; X break ; X X case 5: X barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ; X left = LEFT ; X middle = 0 ; X right = (left + barw + 1) ; X f_text.FrontPen = CYNP ; X break ; X X case 6: X barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ; X left = 0 ; X middle = LEFT ; X right = (middle + barw + 1) ; X f_text.FrontPen = YELP ; X break ; X X case 7: X barw = ((WINW - (2 * BORDER)) / 3 ) - 1 ; X left = LEFT ; X middle = (left + barw + 1) ; X right = (middle + barw + 1) ; X f_text.FrontPen = BLUP ; X break ; X } /* end of switch ( colflags ) */ X } /* end of if ( chgflag ) */ X cmemseg = cmemsize / barh ; X sfmemseg = sfmemsize / barh ; X fmemseg = fmemsize / barh ; X if (mmode == TRUE && ((sfmemsize != 0) || X (fmemsize != 0))) { X /* Keep your eyes open here. If we get a negative */ X /* response from the requester, that means either the */ X /* user retreated, or a no-requester function such as */ X /* noreq or KillReq has selected the negative option. */ X /* If such functions select the positive option they */ X /* force acceptance of the crash risk for Warps mode. */ X X mode = AutoRequest(window, &bodyText0, &positiveText, X &negativeText, 0L, 0L, 319L, 79L) ; X if (mode == FALSE) { /* user Retreat selection */ X sfmemseg = 0 ; /* results in execution of */ X sfmemsize = 0 ; /* this code segment which */ X fmemseg = 0 ; /* resets to safer values */ X fmemsize = 0 ; /* resets to safer values */ X } X } X switch ( wf ) { X case 0: X xl = left ; X membase = cmembase ; X memseg = cmemseg ; X memsize = cmemsize ; X break; X X case 1: X xl = middle ; X membase = sfmembase ; X memseg = sfmemseg ; X memsize = sfmemsize ; X break; X X case 2: X xl = right ; X membase = fmembase ; X memseg = fmemseg ; X memsize = fmemsize ; X break; X } /* end of switch ( wf ) */ X xr = xl + barw ; X if (mmode == TRUE) { X mode = WARPS ; X mmode = FALSE ; X } X if (xl != 0) { X if (intsig == TRUE) { X handle_NEWSIZE() ; X } X if (mode == WARPS) { X (void) updatewarps( wf, membase, memseg ) ; X e_text.FrontPen = YELP ; X } X if (mode == FRAGS) { X (void) updatescreen( wf, membase, memseg ) ; X e_text.FrontPen = BLUP ; X } X } X if (syspri != priority) { X syspri = priority ; X nptr = NULL; X mmtcb = FindTask( nptr ) ; X oldpri = SetTaskPri( mmtcb, syspri ) ; X } X if (wf == 2) { X PrintIText(window->RPort,&f_text,RTEXT,0L) ; X while ( ticker > 0 ) { X wakeupbits = Wait(timerbit) ; X if (wakeupbits & timerbit) { X GetMsg(timerport); X SetTimer(0L, TMARK, timermsg); X } X /* quick like, go see if the user wants anything */ X (void) handle_MESSAGES() ; X ticker-- ; X } X ticker = delayval * TICKIES ; X } X wf++ ; X if (wf >= 3) wf = 0 ; X if (intsig == TRUE) { X handle_NEWSIZE() ; X } X } /* end of while ( things_are_cool) */ X X if (timerport) { X Wait(timerbit); X GetMsg(timerport); X CloseDevice(timermsg); X DeleteStdIO(timermsg); X DeletePort(timerport); X } X X if (GfxBase) CloseLibrary(GfxBase) ; X } X if (window) CloseWindow(window) ; X if (IntuitionBase) CloseLibrary(IntuitionBase) ; X } X wrack_sploot() ; X} X X_cli_parse() {} X_wb_parse() {} END_OF_FILE if test 38693 -ne `wc -c <'mm.c'`; then echo shar: \"'mm.c'\" unpacked with wrong size! fi # end of 'mm.c' fi if test -f 'mminit.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'mminit.c'\" else echo shar: Extracting \"'mminit.c'\" \(27558 characters\) sed "s/^X//" >'mminit.c' <<'END_OF_FILE' X/* : ai=0 bk=0 ts=8 */ X#include "mm.h" X X#define PROJMAX 3 /* number of project menu items */ X#define SETUPMAX 2 /* number of setup menu items */ X#define MODEMAX 2 X#define FREQMAX 4 /* number of frequency menu items */ X#define PRIOMAX 16 /* number of priority menu items */ X#define CHIPMAX 5 /* number of chip mem size menu items */ X#define CHIPAMAX 6 /* number of chip mem base addr menu items */ X#define SFMAX 11 /* number of sf mem size menu items */ X#define SFAMAX 16 /* number of sf mem base addr menu items */ X#define FASTMAX 16 /* number of fast mem size menu items */ X#define FASTAMAX 16 /* number of fast mem base addr menu items */ X#define MAXMENU 9 /* total number of top level menus */ X Xextern BOOL p_mode; /* preset frags mode = 0, warps mode = 1 */ Xextern long p_rate; /* preset sample interval, secs see menu */ Xextern long p_priority; /* preset priority, range -100 to +100 */ Xextern long p_chip; /* preset chip mem size, kbytes see menu */ Xextern long p_chipa; /* preset chip mem address, kb see menu */ Xextern long p_sf; /* preset slowfast mem size, kb see menu */ Xextern long p_sfa; /* preset slowfast mem addr, kb see menu */ Xextern long p_fast; /* preset fast mem size, mbytes see menu */ Xextern long p_fasta; /* preset fast mem addr, mbytes see menu */ X X/******************************************************/ X/* Structure declarations for the menu sections */ X/******************************************************/ X Xstruct MenuItem ProjItem[PROJMAX]; Xstruct IntuiText ProjText[PROJMAX]; Xstruct MenuItem SetupItem[SETUPMAX]; Xstruct IntuiText SetupText[SETUPMAX]; Xstruct MenuItem ModeItem[MODEMAX]; Xstruct IntuiText ModeText[MODEMAX]; Xstruct MenuItem FreqItem[FREQMAX]; Xstruct IntuiText FreqText[FREQMAX]; Xstruct MenuItem PrioItem[PRIOMAX]; Xstruct IntuiText PrioText[PRIOMAX]; Xstruct MenuItem ChipItem[CHIPMAX]; Xstruct IntuiText ChipText[CHIPMAX]; Xstruct MenuItem ChipAItem[CHIPAMAX]; Xstruct IntuiText ChipAText[CHIPAMAX]; Xstruct MenuItem SFItem[SFMAX]; Xstruct IntuiText SFText[SFMAX]; Xstruct MenuItem SFAItem[SFAMAX]; Xstruct IntuiText SFAText[SFAMAX]; Xstruct MenuItem FastItem[FASTMAX]; Xstruct IntuiText FastText[FASTMAX]; Xstruct MenuItem FastAItem[FASTAMAX]; Xstruct IntuiText FastAText[FASTAMAX]; Xstruct Menu menu[MAXMENU]; X X/*****************************************************************/ X/* The following function initializes the structure arrays */ X/* needed to provide the Project menu topic. */ X/* this was left retro-compatible with Manx 3.4a (nplus1) */ X/*****************************************************************/ Xvoid InitProjItems() X { X int n,nplus1; X X/* initialize each menu item and IntuiText with loop */ Xfor( n=0; n 11) { X PrioText[n].FrontPen = ORNP; X PrioText[n].BackPen = REDP; X } X PrioText[n].DrawMode = JAM2; X PrioText[n].LeftEdge = 0; X PrioText[n].TopEdge = 1; X PrioText[n].ITextFont = NULL; X PrioText[n].NextText = NULL; X } XPrioItem[PRIOMAX-1].NextItem = NULL; X X/* select priority item checked */ Xswitch (p_priority) { X case -99: n = 3; break; X case -75: n = 4; break; X case -50: n = 5; break; X case -25: n = 6; break; X case -20: n = 7; break; X case -15: n = 8; break; X case -10: n = 9; break; X case -5: n = 10; break; X case 0: n = 11; break; X case 5: n = 12; break; X case 10: n = 13; break; X case 15: n = 14; break; X case 20: n = 15; break; X default: n = 11; p_priority = 0; X } XPrioItem[n].Flags |= CHECKED; X XPrioText[ 0].IText = (UBYTE *)" NORM "; XPrioText[ 1].IText = (UBYTE *)" DECR "; XPrioText[ 2].IText = (UBYTE *)" INCR "; XPrioText[ 3].IText = (UBYTE *)" -99 "; XPrioText[ 4].IText = (UBYTE *)" -75 "; XPrioText[ 5].IText = (UBYTE *)" -50 "; XPrioText[ 6].IText = (UBYTE *)" -25 "; XPrioText[ 7].IText = (UBYTE *)" -20 "; XPrioText[ 8].IText = (UBYTE *)" -15 "; XPrioText[ 9].IText = (UBYTE *)" -10 "; XPrioText[10].IText = (UBYTE *)" -5 "; XPrioText[11].IText = (UBYTE *)" 0 "; XPrioText[12].IText = (UBYTE *)" 5 "; XPrioText[13].IText = (UBYTE *)" 10 "; XPrioText[14].IText = (UBYTE *)" 15 "; XPrioText[15].IText = (UBYTE *)" 20 "; X} X X/*****************************************************************/ X/* The following initializes the structure arrays */ X/* needed to provide the Chip Mem Size menu topic. */ X/*****************************************************************/ X Xvoid InitChipItems() X { X int n,nplus1; X X/* initialize each menu item and IntuiText with loop */ Xfor( n=0; n. Mail comments to the moderator at . Post requests for sources, and general discussion to comp.sys.amiga.misc.