home *** CD-ROM | disk | FTP | other *** search
- /*
- ** MemMinister is copyright by Marcus Ohlström 1994. All rights reserved
- */
-
- #include "memminister.h"
- #include "memminister_rev.h"
- /*#include <stdio.h>*/
-
- UBYTE *ver = VERSTAG ;
-
- LONG __oslibversion = 37 ;
-
- void __regargs __chkabort(void);
- void __regargs __chkabort(void){} /* Oskadliggör hanteringen av CTRL-C */
-
- struct TextAttr textattr ; /* initieras av layoutAll() */
-
- UWORD snap_borData[2][6] = { {0,0,0,0,0,0},{0,0,0,0,0,0} } ;
- UWORD flush_borData[2][6] = { {0,0,0,0,0,0},{0,0,0,0,0,0} } ;
-
- struct Border snap_bor[] =
- {
- { 0, 0, 2, 0, JAM1, 3, snap_borData[0], &snap_bor[1] },
- { 0, 0, 1, 0, JAM1, 3, snap_borData[1], NULL }
- } ;
-
- struct Border flush_bor[] =
- {
- { 0, 0, 2, 0, JAM1, 3, flush_borData[0], &flush_bor[1] },
- { 0, 0, 1, 0, JAM1, 3, flush_borData[1], NULL }
- } ;
-
- struct IntuiText snap_gadText[] =
- {
- { 1, 0, JAM2, 10, 2, &textattr, "Free", &snap_gadText[1] },
- { 1, 0, JAM2, 45, 2, &textattr, "Snapped", &snap_gadText[2] },
- { 1, 0, JAM2, 90, 2, &textattr, "Used", NULL },
- } ;
-
- struct IntuiText flush_gadText =
- { 1, 0, JAM2, 4, 2, &textattr, "Flush", NULL } ;
-
- struct Gadget snap_gad = { NULL, 54, 12, 100, 12, GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_BOOLGADGET, &snap_bor, NULL, snap_gadText, NULL, NULL, SNAP_GAD, NULL } ;
- struct Gadget flush_gad = { &snap_gad, 4, 12, 28, 12, GFLG_GADGHCOMP, GACT_RELVERIFY, GTYP_BOOLGADGET, &flush_bor, NULL, &flush_gadText, NULL, NULL, FLUSH_GAD, NULL } ;
-
- struct Image image = { 0, 0, 0, 0, 0, NULL, 0, 0, NULL } ;
-
- ULONG chip_snapped = 0, fast_snapped = 0 ;
- ULONG old_chip_free = 0, old_fast_free = 0 ;
-
- /* nedanstående initieras i layouotAll() */
- ULONG chip_XPos, fast_XPos, total_XPos ;
- ULONG win_Width ;
- ULONG chip_YPos, fast_YPos, total_YPos ;
- ULONG text_RightX, free_RightX, snapped_RightX, used_RightX ;
- LONG number_length ;
-
- UBYTE *chip_text = "Chip" , *fast_text = "Fast", *total_text = "Total" ;
-
- UBYTE str[11] ; /* <- 11 istället för STRLEN gör att fönstret ser */
- /* konstigt ut om STRLEN är för litet, men programmet */
- /* krashar inte!! (Vilket det gör om det står STRLEN här) */
-
- struct IntuiText iText = { 1, 0, JAM2, 0, 0, &textattr, str, NULL } ;
-
- WORD zoomsize[] = { ~0, ~0, 20 + 10 + (STRLEN-1)*8 + 10 + 26 + 26, 11 } ;
-
- struct Window *win ;
- struct Screen *scr ;
-
- STRPTR wintitle = "MemMinister 1.1" ;
-
- VOID main( VOID )
- {
- LONG lng;
- BOOL done = FALSE ;
- struct IntuiMessage *iMsg ;
- ULONG class ;
- struct Gadget *gad ;
-
- if( scr = LockPubScreen( NULL ) )
- {
- /* layoutAll() initierar bla textattr => använd EJ textattr innan */
- layoutAll() ;
- if( win = OpenWindowTags( NULL,
- /*
- WA_Left, 100,
- WA_Top, 20,
- */
- WA_Width, win_Width,
- WA_InnerHeight, scr->RastPort.Font->tf_YSize * 4 + 3 + 1,
- WA_Title, wintitle,
- WA_ScreenTitle, "MemMinister 1.1 © Marcus Ohlström",
- WA_Gadgets, &flush_gad,
- WA_Zoom, zoomsize,
- WA_AutoAdjust, TRUE,
- WA_Flags, WFLG_CLOSEGADGET | WFLG_DEPTHGADGET | WFLG_DRAGBAR,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_GADGETUP | IDCMP_NEWSIZE,
- TAG_END ) )
- {
- writeInit() ;
- writeSnapped( AvailMem(MEMF_CHIP), AvailMem(MEMF_FAST) ) ;
- while( !done )
- {
- if( !(win->Flags & WFLG_ZOOMED) )
- writeFree( AvailMem(MEMF_CHIP), AvailMem(MEMF_FAST) ) ;
- else {
- lng = AvailMem(MEMF_ANY) ;
- RawDoFmt("%ld", &lng, (void (*))"\x16\xc0\x4e\x75", str);
- SetWindowTitles( win, str, (UBYTE *)~0 ) ;
- }
- Delay( UPDATEDELAY ) ;
-
- /* denna sats bör ligga här för att programmet inte */
- /* ska vänta ytterligare UPDATEDELAY*1/50 sec efter */
- /* IDCMP-meddelanden */
- /* */
- while( iMsg = (struct IntuiMessage *)GetMsg( win->UserPort ) )
- {
- class = iMsg->Class ;
- gad = (struct Gadget *)iMsg->IAddress ;
- /* använd INTE gad om class != IDCMP_GADGETUP */
- ReplyMsg( (struct Message *)iMsg ) ;
-
- switch( class )
- {
- case IDCMP_GADGETUP:
- switch( gad->GadgetID )
- {
- case FLUSH_GAD:
- AllocMem( 0, 0 ) ;
- break;
- case SNAP_GAD:
- writeSnapped( AvailMem(MEMF_CHIP), AvailMem(MEMF_FAST) ) ;
- writeUsed( 0, 0 ) ;
- }
- break ;
- case IDCMP_NEWSIZE:
- if( !(win->Flags & WFLG_ZOOMED) )
- {
- SetWindowTitles( win, wintitle, (UBYTE *)~0 ) ;
- writeInit() ;
- writeSnapped( chip_snapped, fast_snapped ) ;
- old_chip_free = old_fast_free = 0 ;
- /* ^ för att free-fälten ska ritas om */
- }
- break;
- case IDCMP_CLOSEWINDOW:
- done = TRUE ;
- }
- }
- }
- CloseWindow( win ) ;
- }
- UnlockPubScreen( NULL, scr ) ;
- }
- }
-
- VOID layoutAll( VOID )
- {
- LONG chip_length, fast_length, total_length, max_length, flush_length ;
- struct TextFont *Font = scr->RastPort.Font ;
-
- number_length = digit_maxlength() ;
-
- textattr.ta_Name = Font->tf_Message.mn_Node.ln_Name ;
- textattr.ta_YSize = Font->tf_YSize ;
- textattr.ta_Style = Font->tf_Style ;
- textattr.ta_Flags = Font->tf_Flags ;
-
- zoomsize[2] = 20 + number_length + 6 + 26 + 26 ;
- zoomsize[3] = 3 + textattr.ta_YSize ;
-
- iText.IText = chip_text ; chip_length = IntuiTextLength( &iText ) ;
- iText.IText = fast_text ; fast_length = IntuiTextLength( &iText ) ;
- iText.IText = total_text ; total_length = IntuiTextLength( &iText ) ;
- flush_length = IntuiTextLength( &flush_gadText ) ;
-
- max_length = MAX( MAX(chip_length, fast_length), MAX(total_length, flush_length) ) ;
-
- total_YPos = textattr.ta_YSize +
- (fast_YPos = textattr.ta_YSize +
- (chip_YPos = scr->WBorTop + 1 + 2*textattr.ta_YSize + 3 + 1)) ;
-
- win_Width = scr->WBorRight + 4 +
- (used_RightX = number_length +
- (snapped_RightX = number_length +
- (free_RightX = number_length +
- (text_RightX = scr->WBorLeft + 2 + max_length)))) ;
-
- flush_gad.LeftEdge = scr->WBorRight ;
- flush_gad.TopEdge = textattr.ta_YSize + 3 ;
- flush_gad.Width = 2 + max_length + 5 ;
- flush_gad.Height = textattr.ta_YSize + 3 ;
-
- snap_gad.LeftEdge = scr->WBorRight + flush_gad.Width ;
- snap_gad.TopEdge = flush_gad.TopEdge ;
- snap_gad.Width = win_Width-8-flush_gad.Width ;
- snap_gad.Height = flush_gad.Height ;
-
- buildBoolBorder( &flush_gad ) ;
- buildBoolBorder( &snap_gad ) ;
-
- snap_gadText[0].LeftEdge = text_RightX - flush_gad.Width + (number_length - IntuiTextLength(&snap_gadText[0]))/2 ;
- snap_gadText[1].LeftEdge = free_RightX - flush_gad.Width + (number_length - IntuiTextLength(&snap_gadText[1]))/2 ;
- snap_gadText[2].LeftEdge = snapped_RightX - flush_gad.Width + (number_length - IntuiTextLength(&snap_gadText[2]))/2 ;
-
- image.Height = textattr.ta_YSize ;
-
- chip_XPos = text_RightX - chip_length ;
- fast_XPos = text_RightX - fast_length ;
- total_XPos = text_RightX - total_length ;
- }
-
- VOID writeInit( VOID )
- {
- struct DrawInfo *di = GetScreenDrawInfo( win->WScreen ) ;
-
- iText.FrontPen = di ? di->dri_Pens[HIGHLIGHTTEXTPEN] : 2 ;
-
- iText.IText = chip_text ;
- PrintIText( win->RPort, &iText, chip_XPos, chip_YPos ) ;
-
- iText.IText = fast_text ;
- PrintIText( win->RPort, &iText, fast_XPos, fast_YPos ) ;
-
- iText.IText = total_text ;
- PrintIText( win->RPort, &iText, total_XPos, total_YPos ) ;
-
- iText.FrontPen = di ? di->dri_Pens[TEXTPEN] : 1 ;
-
- iText.IText = str ;
- }
-
- VOID writeFree( ULONG chip_free, ULONG fast_free )
- {
- BOOL any_change = FALSE ;
-
- if( chip_free != old_chip_free )
- {
- myPrintINumber( chip_free, free_RightX, chip_YPos ) ;
- old_chip_free = chip_free ;
- any_change = TRUE ;
- }
-
- if( fast_free != old_fast_free )
- {
- myPrintINumber( fast_free, free_RightX, fast_YPos ) ;
- old_fast_free = fast_free ;
- any_change = TRUE ;
- }
-
- if( any_change )
- {
- myPrintINumber( chip_free + fast_free, free_RightX, total_YPos ) ;
-
- writeUsed( chip_snapped-chip_free, fast_snapped-fast_free ) ;
- }
- }
-
- VOID writeSnapped( ULONG chip_now, ULONG fast_now )
- {
- myPrintINumber( chip_now, snapped_RightX, chip_YPos ) ;
- myPrintINumber( fast_now, snapped_RightX, fast_YPos ) ;
- myPrintINumber( chip_now + fast_now, snapped_RightX, total_YPos ) ;
- chip_snapped = chip_now ;
- fast_snapped = fast_now ;
- }
-
- VOID writeUsed( ULONG chip_used, ULONG fast_used )
- {
- myPrintINumber( chip_used, used_RightX, chip_YPos ) ;
- myPrintINumber( fast_used, used_RightX, fast_YPos ) ;
- myPrintINumber( chip_used+fast_used, used_RightX, total_YPos ) ;
- }
-
- VOID myPrintINumber( ULONG number, ULONG XRight, ULONG Y )
- {
- RawDoFmt("%ld", &number, (void (*))"\x16\xc0\x4e\x75", iText.IText);
- PrintIText( win->RPort, &iText, XRight-IntuiTextLength(&iText), Y ) ;
-
- image.Width = number_length - IntuiTextLength(&iText) ;
- DrawImage( win->RPort, &image, XRight-number_length, Y ) ;
- }
-
- /* gad->GadgetRender->XY MÅSTE vara MEMF_CLEARed WORD[12] */
- VOID buildBoolBorder( struct Gadget *gad )
- {
- WORD *XY = ((struct Border *)gad->GadgetRender)->XY ;
-
- XY[1] = XY[9] = XY[11] = gad->Height - 1 ;
- XY[4] = XY[6] = XY[8] = gad->Width - 1 ;
- XY[10] = 1 ;
- }
-
- LONG digit_maxlength( VOID )
- {
- struct TextFont *Font = scr->RastPort.Font ;
- ULONG LoChar = Font->tf_LoChar ;
-
- LONG char_width = 0, tmp, count = 10 ;
-
- if( FPF_PROPORTIONAL & Font->tf_Flags )
- {
- while( count-- )
- {
- tmp = ((WORD*)Font->tf_CharSpace)['0' - LoChar + count] + ((WORD*)Font->tf_CharKern )['0' - LoChar + count] ;
- char_width = MAX( char_width, tmp ) ;
- }
- tmp = ((WORD*)Font->tf_CharSpace)['-' - LoChar] + ((WORD*)Font->tf_CharKern )['-' - LoChar] ;
- tmp = MAX( char_width, tmp ) ;
- } else
- char_width = tmp = Font->tf_XSize ;
-
- return( char_width * (STRLEN-2) + tmp ) ; /* <- för att tänka på '-' */
- }
-