home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d523 / screenjaeger.lha / ScreenJaeger / Source / prog.c < prev    next >
C/C++ Source or Header  |  1991-08-05  |  19KB  |  829 lines

  1. /*************************************************************\
  2.  *                     SCREEN JAEGER                         *
  3.  *                     ~~~~~~ ~~~~~~                         *
  4.  *                                                           *
  5.  *       'Jaeger' - German word meaning HUNTER               *
  6.  *                  I'm not German, but I like the word      *
  7.  *                                                           *
  8.  *               Written by Syd L. Bolton                    *
  9.  *       ©1991 Legendary Design Technologies Inc.            *
  10.  *                                                           *
  11.  *         Compiled using Manx Aztec C (tm) V5.0             *
  12.  *                                                           *
  13.  *      Started:       Date:  May 13, 1991  Time: 18:55:00   *
  14.  *      Version: 1.00  Date: July 12, 1991  Time: 00:17:00   *
  15.  *      Version: 1.01  Date: July 16, 1991  Time: 12:30:00   *
  16. \*************************************************************/
  17.  
  18. #include <intuition/intuition.h>
  19. #include <intuition/intuitionbase.h>
  20. #include <exec/memory.h>
  21. #include <exec/execbase.h>
  22. #include <graphics/gfx.h>
  23. #include <graphics/gfxbase.h>
  24. #include <math.h>
  25. #include <iff.h>
  26.  
  27. long *IntuitionBase,*GfxBase,*IFFBase;
  28. extern struct ExecBase *SysBase;
  29. struct MemHeader *mh;
  30. struct BitMap bm;
  31. struct Screen *Screen,*MainScreen;
  32. struct Window *Window,*MessageWindow,*InfoWindow;
  33. struct ViewPort *ViewPort,*vport;
  34. struct RastPort *rport,*mrport,*irport;
  35. UWORD colortable[32];
  36. long upper[2],lower[2],xbody,ybody;
  37. long FOffset[6];
  38. PLANEPTR PlanePtr[6];
  39.  
  40. #include "screen.h"
  41. #include "main.h"
  42. #include "message.h"
  43. #include "info.h"
  44.  
  45. #define CHIP 0
  46. #define FAST 1
  47.  
  48. int num_bitplanes=1,fine=0,direction,plane=0,copy=0,swap=0;
  49. int width,height,NormalRows;
  50. int type=CHIP;
  51. int XOffset=0,YOffset=0;
  52. int overscan=0;
  53.  
  54. long offset=32768;
  55.  
  56. main()
  57. {
  58. int i,exit_prog=0;
  59. struct IntuiMessage *message;
  60. ULONG class;
  61.  
  62. openlibraries();
  63. setup();
  64. show_plane(2,1);
  65.  
  66. do {
  67.     WaitPort(Window->UserPort);
  68.                   while( (message = (struct IntuiMessage *)
  69.                          GetMsg(Window->UserPort) ) != NULL)
  70.                   {
  71.                       class = message->Class;
  72.                       ReplyMsg(message);
  73.      
  74.               if ( class == GADGETUP) exit_prog=option(message);
  75.               if ( class == GADGETDOWN && fine==0) holdit(message);
  76.               if ( class == VANILLAKEY) key(message);
  77.         }
  78.       } while (exit_prog==0);
  79.  
  80. closestuff(0);
  81. }
  82.  
  83. #include "pointer.h"
  84.  
  85. key(message)
  86. struct IntuiMessage *message;
  87. {
  88. int c;
  89.  
  90. c=message->Code;
  91.  
  92. switch (c) {
  93.     case 'b':
  94.     case 'B': ScreenToFront(Screen);
  95.           break;
  96.  
  97.     case 'f':
  98.     case 'F': ScreenToFront(MainScreen);
  99.           break;
  100.  
  101.     case 'm':
  102.     case 'M': MainScreen->TopEdge=0;
  103.           MainScreen->ViewPort.DyOffset=0;
  104.           Screen->TopEdge=57;
  105.           Screen->ViewPort.DyOffset=57;
  106.           ScreenToFront(Screen);
  107.           RemakeDisplay();
  108.           break;
  109.  
  110.     case 'n':
  111.     case 'N': MainScreen->TopEdge=NormalRows-56;
  112.           MainScreen->ViewPort.DyOffset=NormalRows-56;
  113.           Screen->TopEdge=0;
  114.           Screen->ViewPort.DyOffset=0;
  115.           ScreenToFront(MainScreen);
  116.           RemakeDisplay();
  117.           break;
  118.  
  119.     default: break;
  120.     }
  121. }
  122.  
  123. holdit(message)
  124. struct IntuiMessage *message;
  125. {
  126. struct Gadget *igad;
  127. int gadgid,hiexit=0;
  128. ULONG class;
  129.  
  130. igad=(struct Gadget *) message->IAddress;
  131. gadgid=igad->GadgetID;
  132.  
  133. if (copy==1 || swap==1) {
  134.     ClearPointer(Window);
  135.     copy=swap=0;
  136.     }                 /* turn off special modes */
  137.  
  138. if (overscan) return();
  139.  
  140. do {
  141.     message=(struct IntuiMessage *) GetMsg(Window->UserPort);
  142.     if (message != NULL) {
  143.         class=message->Class;
  144.         ReplyMsg(message);
  145.         if (class==GADGETUP) hiexit=1;
  146.         }
  147.     switch (gadgid) {    
  148.         case 1: offset-=width;
  149.             if (offset < lower[type]) offset=lower[type];
  150.             redo();
  151.             break;
  152.  
  153.         case 2: offset++;
  154.             if (offset+(width/8)*height > upper[type]) offset=upper[type]-width/8*height;
  155.             redo();
  156.             break;
  157.  
  158.         case 3: offset+=width;
  159.             if (offset+(width/8)*height > upper[type]) offset=upper[type]-width/8*height;
  160.             redo();
  161.             break;
  162.  
  163.         case 4: offset--;
  164.             if (offset < lower[type]) offset=lower[type];
  165.             redo();
  166.             break;
  167.  
  168.         case 45: redoprop();
  169.              break;
  170.  
  171.         default: break;
  172.         }
  173.     } while (hiexit==0);
  174. }
  175.  
  176. option(message)
  177. struct IntuiMessage *message;
  178. {
  179. struct Gadget *igad;
  180. int gadgid;
  181. long temp;
  182. ULONG size,max;
  183.  
  184. igad=(struct Gadet *) message->IAddress;
  185. gadgid=igad->GadgetID;
  186.  
  187. switch(gadgid) {
  188.     case 1: if (overscan) doscan(1);
  189.         else {
  190.         offset-=width/(7*fine+1);
  191.         if (offset < lower[type]) offset=lower[type];
  192.         redo();
  193.         }
  194.         break;
  195.  
  196.     case 2: if (overscan) doscan(2);
  197.         else {
  198.         offset++;
  199.         if (offset+(width/8)*height > upper[type]) offset=upper[type]-width/8*height;
  200.         redo();
  201.         }
  202.         break;
  203.  
  204.     case 3: if (overscan) doscan(3);
  205.         else {
  206.         offset+=width/(7*fine+1);
  207.         if (offset+(width/8)*height > upper[type]) offset=upper[type]-width/8*height;
  208.         redo();
  209.         }
  210.         break;
  211.  
  212.     case 4: if (overscan) doscan(4);
  213.         else {
  214.         offset--;
  215.         if (offset < lower[type]) offset=lower[type];
  216.         redo();
  217.         }
  218.         break;
  219.  
  220.     case 5: num_bitplanes++;
  221.         if (num_bitplanes > 6) num_bitplanes=6;
  222.         if (type==FAST) {
  223.             PlanePtr[num_bitplanes-1]=AllocRaster(width,height);
  224.             if (PlanePtr[num_bitplanes-1]) {
  225.                 CopyMem(lower[FAST],PlanePtr[num_bitplanes-1],(width/8)*height);
  226.                 bm.Planes[num_bitplanes-1]=PlanePtr[num_bitplanes-1];
  227.                 Screen->RastPort.BitMap->Planes[num_bitplanes-1]=PlanePtr[num_bitplanes-1];            /* if not, couldn't allocate the chip memory */
  228.                 }
  229.             else num_bitplanes--;
  230.             }
  231.         set_depth();
  232.         break;
  233.  
  234.     case 6: num_bitplanes--;
  235.         if (num_bitplanes < 1) num_bitplanes=1;
  236.         if (type==FAST) {
  237.             if (PlanePtr[num_bitplanes]) FreeRaster(PlanePtr[num_bitplanes],width,height);
  238.             PlanePtr[num_bitplanes]=0;
  239.             }
  240.         set_depth();
  241.         if (plane >= num_bitplanes) {
  242.             show_plane(1,2);
  243.             plane=num_bitplanes-1;
  244.             show_plane(2,1);
  245.             }
  246.         break;
  247.  
  248.     case 7: offset=atoi(Gadget32SIBuff);
  249.         if (offset < lower[type]) offset=lower[type];
  250.         if (offset+width/8*height > upper[type]) offset=upper[type]-width/8*height;
  251.         redo();
  252.         calcpropgad();
  253.         break;
  254.  
  255.     case 9: if (Gadget6.Flags & SELECTED)
  256.             fine=1;
  257.         else fine=0;
  258.         break;   
  259.  
  260.     case 10: if (Gadget13.Flags & SELECTED) {
  261.             if (type==FAST) freefastmem();
  262.             Screen->ViewPort.Modes |= LACE;
  263.             Screen->RastPort.BitMap->Rows=NormalRows*2;
  264.             bm.Rows=NormalRows*2;        
  265.             Screen->Height=NormalRows*2;
  266.             Screen->ViewPort.DHeight=NormalRows*2;
  267.             height=NormalRows*2;
  268.             if (type==FAST) allocfastmem();
  269.             }
  270.          else {
  271.             if (type==FAST) freefastmem();
  272.             Screen->ViewPort.Modes &= ~LACE;
  273.             Screen->RastPort.BitMap->Rows=NormalRows;
  274.             bm.Rows=NormalRows;
  275.             Screen->Height=NormalRows;
  276.             Screen->ViewPort.DHeight=NormalRows;
  277.             height=NormalRows;
  278.             if (type==FAST) allocfastmem();
  279.             }
  280.          calcpropgad();
  281.          fixhwgads();
  282.          RemakeDisplay();
  283.          break;
  284.  
  285.     case 11: if (Gadget14.Flags & SELECTED) {
  286.             if (type==FAST) freefastmem();
  287.             Screen->ViewPort.Modes |= HIRES;
  288.             Screen->Width=640;
  289.             Screen->RastPort.BitMap->BytesPerRow=80;
  290.             bm.BytesPerRow=80;    /* 640 div 8 */
  291.             Screen->ViewPort.DWidth=640;
  292.             width=640;
  293.             if (type==FAST) allocfastmem();
  294.             }
  295.          else {
  296.             if (type==FAST) freefastmem();
  297.             Screen->ViewPort.Modes &= ~HIRES;
  298.             Screen->Width=320;
  299.             bm.BytesPerRow=40;   /* 320 div 8 */
  300.             Screen->RastPort.BitMap->BytesPerRow=40;
  301.             Screen->ViewPort.DWidth=320;
  302.             width=320;
  303.             if (type==FAST) allocfastmem();
  304.             }
  305.          calcpropgad();
  306.          fixhwgads();
  307.          RemakeDisplay();
  308.          break;
  309.  
  310.     case 12: if (Gadget15.Flags & SELECTED) {
  311.             Screen->ViewPort.Modes |= EXTRA_HALFBRITE;
  312.             if (num_bitplanes < 6) Message("WARNING: Should have 6 bitplanes.");
  313.             }
  314.          else
  315.             Screen->ViewPort.Modes &= ~EXTRA_HALFBRITE;
  316.          RemakeDisplay();
  317.          break;
  318.  
  319.     case 13: if (Gadget16.Flags & SELECTED) {
  320.             Screen->ViewPort.Modes |= HAM;
  321.             if (num_bitplanes < 6) Message("WARNING: Should have 6 bitplanes.");
  322.             }
  323.          else
  324.             Screen->ViewPort.Modes &= ~HAM;
  325.          RemakeDisplay();
  326.          break;
  327.  
  328.     case 20:
  329.     case 21:
  330.     case 22:
  331.     case 23:
  332.     case 24:
  333.     case 25: if (gadgid-19 > num_bitplanes) break;
  334.          if (type==FAST) FOffset[plane]=offset;
  335.          if (copy==1) {
  336.             bm.Planes[gadgid-20]=Screen->RastPort.BitMap->Planes[gadgid-20]=bm.Planes[plane];
  337.             copy=0;
  338.             ClearPointer(Window);
  339.             RemakeDisplay();
  340.             }
  341.          if (swap==1) {
  342.             temp=bm.Planes[plane];
  343.             bm.Planes[plane]=Screen->RastPort.BitMap->Planes[plane]=bm.Planes[gadgid-20];
  344.             bm.Planes[gadgid-20]=Screen->RastPort.BitMap->Planes[gadgid-20]=temp;
  345.             swap=0;
  346.             ClearPointer(Window);
  347.             RemakeDisplay();
  348.             }
  349.          show_plane(1,2);
  350.          plane=gadgid-20;    
  351.          if (type==CHIP) offset=bm.Planes[plane];
  352.          if (type==FAST) {
  353.             offset=FOffset[plane];
  354.             if (offset < lower[FAST]) offset=lower[FAST];
  355.             }
  356.          show_plane(2,1);          
  357.          display_offset();   /* update gadget */
  358.          break;
  359.  
  360.     case 30: autooffset();
  361.          break;
  362.          
  363.     case 31: copy=1-copy;
  364.          if (copy) do_ToSprite(Window);
  365.              else ClearPointer(Window);
  366.          break;
  367.  
  368.     case 32: swap=1-swap;
  369.          if (swap) do_ExSprite(Window);
  370.              else ClearPointer(Window);
  371.          break;
  372.  
  373.     case 40: save_iff();
  374.          break;             /* save file */
  375.  
  376.     case 41: if (type==CHIP) {
  377.              max=AvailMem(MEMF_CHIP|MEMF_LARGEST);
  378.              if (max) size=AllocMem(max,MEMF_CHIP|MEMF_CLEAR);
  379.              if (size) FreeMem(size,max);
  380.              }
  381.          if (type==FAST) {
  382.             max=AvailMem(MEMF_FAST|MEMF_LARGEST);
  383.             if (max) size=AllocMem(max,MEMF_FAST|MEMF_CLEAR);
  384.             if (size) FreeMem(size,max);
  385.             }
  386.          break;
  387.  
  388.     case 42:
  389.     case 43: redo_dimensions();
  390.          break;
  391.  
  392.     case 45: redoprop();
  393.          break;
  394.  
  395.     case 46: if (type==CHIP) break;
  396.          type=CHIP;
  397.          show_mem_type();
  398.          offset=lower[CHIP];
  399.          freefastmem();
  400.          redo();         
  401.          break;
  402.  
  403.     case 47: if (type==FAST) break;
  404.          if (lower[FAST]==0) {
  405.             type=CHIP;
  406.             show_mem_type();
  407.             break;
  408.             }
  409.          type=FAST;
  410.          show_mem_type();
  411.          offset=lower[FAST];
  412.          allocfastmem();
  413.          redo();
  414.          break;
  415.  
  416.     case 50: return(1);
  417.     
  418.     case 75: if (Gadget30.Flags & SELECTED)
  419.             overscan=1;
  420.          else overscan=0;
  421.          break;
  422.  
  423.     case 80: ScreenInfo();
  424.          break;
  425.  
  426.     default: break;
  427.     }
  428. if ((swap==1 || copy==1) && (gadgid!=31 && gadgid!=32)) {
  429.     ClearPointer(Window);
  430.     swap=copy=0;
  431.     }
  432. return(0);
  433. }
  434.  
  435. doscan(dir)
  436. int dir;
  437. {
  438. switch (dir) {
  439.     case 1: YOffset--;
  440.         break;
  441.  
  442.     case 2: XOffset++;
  443.         break;
  444.  
  445.     case 3: YOffset++;
  446.         break;
  447.  
  448.     case 4: XOffset--;
  449.         break;
  450.  
  451.     default: break;
  452.     }
  453. if (YOffset < -46) YOffset=-46;
  454. if (YOffset > 534) YOffset=534;
  455. if (XOffset < -36) XOffset=-36;
  456. if (YOffset > 724) XOffset=724;
  457.  
  458. Screen->ViewPort.DyOffset=YOffset;
  459. Screen->ViewPort.DxOffset=XOffset;
  460.  
  461. RemakeDisplay();
  462. }
  463.  
  464. allocfastmem()
  465. {
  466. int i,rv=0;
  467.  
  468. for (i=0; i<num_bitplanes; i++) {
  469.     PlanePtr[i]=AllocRaster(width,height);
  470.     if (PlanePtr[i]) {
  471.         bm.Planes[i]=PlanePtr[i];
  472.         Screen->RastPort.BitMap->Planes[i]=PlanePtr[i];
  473.         }
  474.     else rv=-1;
  475.     }
  476. return(rv);
  477. }
  478.  
  479. freefastmem()
  480. {
  481. int i;
  482.  
  483. for (i=0; i<num_bitplanes; i++) {
  484.     if (PlanePtr[i]) FreeRaster(PlanePtr[i],width,height);
  485.     PlanePtr[i]=0;   /* just clear it out to be safe later */
  486.     bm.Planes[i]=lower[CHIP];
  487.     Screen->RastPort.BitMap->Planes[i]=lower[CHIP];
  488.     }
  489. }
  490.  
  491. fixhwgads()
  492. {
  493. sprintf(Gadget25SIBuff,"%-d",width);
  494. sprintf(Gadget26SIBuff,"%-d",height);
  495. RefreshGadgets(&Gadget25,Window,NULL);
  496. show_mem_type();  /* just so it doesn't get lost */
  497. }
  498.  
  499. redo_dimensions()
  500. {
  501. int swidth,sheight;
  502.  
  503. swidth=atoi(Gadget25SIBuff);
  504. sheight=atoi(Gadget26SIBuff);
  505.  
  506. if (swidth > 1024) swidth=1024;
  507. if (sheight > 1024) sheight=1024;
  508. if (swidth < 1) swidth=1;
  509. if (sheight < 1) swidth=1;
  510. sprintf(Gadget25SIBuff,"%-d",swidth);
  511. sprintf(Gadget26SIBuff,"%-d",sheight);
  512.  
  513. if (type==FAST) freefastmem();
  514. Screen->Width=swidth;
  515. bm.BytesPerRow=swidth/8;
  516. bm.Rows=sheight;
  517. Screen->RastPort.BitMap->Rows=sheight;
  518. Screen->RastPort.BitMap->BytesPerRow=swidth/8;
  519. Screen->ViewPort.DWidth=swidth;
  520. Screen->Height=sheight;
  521. Screen->ViewPort.DHeight=sheight;
  522.  
  523. width=swidth; height=sheight;
  524. if (height > 399) {
  525.     Screen->ViewPort.Modes |= LACE;
  526.     Gadget13.Flags |= SELECTED;
  527.     }
  528.     else {
  529.     Screen->ViewPort.Modes &= ~LACE;
  530.     Gadget13.Flags &= ~SELECTED;
  531.     }
  532. if (width > 639) {
  533.     Screen->ViewPort.Modes |= HIRES;
  534.     Gadget14.Flags |= SELECTED;
  535.     }
  536.     else {
  537.     Screen->ViewPort.Modes &= HIRES;
  538.     Gadget14.Flags &= ~SELECTED;
  539.     }
  540. if (type==FAST) allocfastmem();
  541. RefreshGadgets(&Gadget13,Window,NULL);
  542. show_mem_type();
  543. RemakeDisplay();
  544. }
  545.  
  546. show_plane(a,b)
  547. int a,b;
  548. {
  549. char p[4];
  550.  
  551. SetAPen(rport,a);
  552. SetBPen(rport,b);
  553. Move(rport,301+33*plane,9);
  554. sprintf(p," %1d ",plane+1);
  555. Text(rport,p,3);
  556. }
  557.  
  558. show_mem_type()
  559. {
  560. SetAPen(rport,1-type+1);
  561. SetBPen(rport,type+1);
  562. Move(rport,102,30);
  563. Text(rport," CHIP ",6);
  564. SetAPen(rport,type+1);
  565. SetBPen(rport,1-type+1);
  566. Move(rport,160,30);
  567. Text(rport," FAST ",6);
  568. }
  569.  
  570. autooffset()
  571. {
  572. int i;
  573.  
  574. if (num_bitplanes < 2) return();
  575.  
  576. for (i=1; i<num_bitplanes; i++) {
  577.     bm.Planes[i]=bm.Planes[0]+i*(width*height/8);
  578.     Screen->RastPort.BitMap->Planes[i]=bm.Planes[0]+i*(width*height/8);
  579.     }
  580. RemakeDisplay();
  581. }
  582.  
  583. set_depth()
  584. {
  585. char msg[2];
  586.  
  587. sprintf(msg,"%-1d",num_bitplanes);
  588. Move(rport,242,10);
  589. SetAPen(rport,1); SetBPen(rport,0);
  590. Text(rport,msg,1);
  591. bm.Depth=num_bitplanes;
  592. Screen->Depth=num_bitplanes;
  593. Screen->RastPort.BitMap->Depth=num_bitplanes;
  594. RemakeDisplay();
  595. }
  596.  
  597. redo()
  598. {
  599. display_offset();
  600. if (type==CHIP) {
  601.     bm.Planes[plane]=offset;
  602.     Screen->RastPort.BitMap->Planes[plane]=offset;
  603.     RemakeDisplay();
  604.     }
  605. if (type==FAST) {
  606.     CopyMem(offset,PlanePtr[plane],(width/8)*height);
  607.     RemakeDisplay();
  608.     }
  609. }
  610.  
  611. display_offset()
  612. {
  613. sprintf(Gadget32SIBuff,"%-d",offset);
  614. RefreshGadgets(&Gadget32,Window,NULL);
  615. }
  616.  
  617. calcpropgad()
  618. {
  619. USHORT VertPot,HorizPot;
  620. long value,xpos,ypos;
  621.  
  622. value=(upper[type]-lower[type])/(width/8*height);
  623. xbody=sqrt(value*3)+0.5;   /* for rounding of course */
  624. ybody=sqrt(value/3)+0.5;
  625. value=offset/(width/8*height);
  626. xpos=sqrt(value*3)+0.5; xpos++;
  627. ypos=sqrt(value/3)+0.5; ypos++;
  628. HorizPot=(UWORD) (((ULONG) xpos * MAXPOT) / (xbody-1));
  629.  VertPot=(UWORD) (((ULONG) ypos * MAXPOT) / (ybody-1));
  630. NewModifyProp(&Gadget27,Window,NULL,AUTOKNOB+FREEHORIZ+FREEVERT,HorizPot,VertPot,0xffff/xbody,0xffff/ybody,1);
  631. }
  632.  
  633. redoprop()
  634. {
  635. USHORT VertPot,HorizPot;
  636. USHORT mx,my;
  637. int dmem;
  638.  
  639. dmem=width/8*height;
  640.  
  641. VertPot=Gadget27SInfo.VertPot; HorizPot=Gadget27SInfo.HorizPot;
  642. mx=((HorizPot+1)*(xbody-1))>>16; mx++;
  643. my=((VertPot+1)*(ybody-1))>>16; my++;
  644. offset=lower[type]+mx*my*dmem;
  645. if (offset < lower[type]) offset=lower[type];
  646. if (offset > upper[type]-dmem) offset=upper[type]-dmem;
  647. redo();
  648. }
  649.  
  650. Message(text)
  651. char *text;
  652. {
  653. struct IntuiMessage *message;
  654.  
  655. MesWin.Screen=MainScreen;
  656. MessageWindow=OpenWindow(&MesWin);
  657. if (MessageWindow==NULL) return();
  658.  
  659. mrport=MessageWindow->RPort;
  660. Move(mrport,10,20);
  661. Text(mrport,text,strlen(text));
  662.  
  663. WaitPort(MessageWindow->UserPort);
  664.                   while( (message = (struct IntuiMessage *)
  665.                          GetMsg(MessageWindow->UserPort) ) != NULL)
  666.                       ReplyMsg(message);
  667. CloseWindow(MessageWindow);
  668. }
  669.  
  670. ScreenInfo()
  671. {
  672. struct IntuiMessage *message;
  673. char string[10];
  674. long available,tmem;
  675.  
  676. InfoWin.Screen=MainScreen;
  677. InfoWindow=OpenWindow(&InfoWin);
  678. if (InfoWindow==NULL) return();
  679.  
  680. irport=InfoWindow->RPort;
  681. PrintIText(irport,&ITextList,0,0);
  682.  
  683. SetAPen(irport,3); SetBPen(irport,0);  /* set lighter color */
  684.  
  685. sprintf(string,"%-8d",lower[CHIP]); Move(irport,59,20); Text(irport,string,8);
  686. sprintf(string,"%-8d",upper[CHIP]); Move(irport,176,20); Text(irport,string,8);
  687. sprintf(string,"%-8d",lower[FAST]); Move(irport,59,41); Text(irport,string,8);
  688. sprintf(string,"%-8d",upper[FAST]); Move(irport,176,41); Text(irport,string,8);
  689. available=(upper[CHIP]-lower[CHIP])+(upper[FAST]-lower[FAST]);
  690. sprintf(string,"%-8d",available); Move(irport,149,51); Text(irport,string,8);
  691. sprintf(string,"%-3d",XOffset); Move(irport,494,20); Text(irport,string,3);
  692. sprintf(string,"%-3d",YOffset); Move(irport,551,20); Text(irport,string,3);
  693. tmem=(width/8)*height*num_bitplanes;
  694. sprintf(string,"%8d",tmem); Move(irport,471,41); Text(irport,string,8);
  695.  
  696. WaitPort(InfoWindow->UserPort);
  697.                   while( (message = (struct IntuiMessage *)
  698.                          GetMsg(InfoWindow->UserPort) ) != NULL)
  699.                       ReplyMsg(message);
  700. CloseWindow(InfoWindow);
  701. }
  702.  
  703. save_iff()
  704. {
  705. int k,max_colors;
  706. long val1,val2;
  707.  
  708. max_colors=1 << num_bitplanes;
  709. if (max_colors > 32) max_colors=32;
  710.  
  711. for (k=0; k < max_colors; k++)
  712.     colortable[k]=GetRGB4(ViewPort->ColorMap,k);
  713.  
  714. for (k=0; k<num_bitplanes; k++) {               /* we must do this       */
  715.     val1=val2=bm.Planes[k];            /* to insure that the    */
  716.     val1=val1/2;                /* BITMAP is alinged     */
  717.     val1=val1*2;                /* to a word. Otherwise  */
  718.     if (val1 != val2) {            /* the resultant picture */
  719.         bm.Planes[k]--;            /* will be screwed!      */
  720.         Screen->BitMap.Planes[k]--;
  721.         }
  722.     }
  723.  
  724. SaveBitMap(Gadget19SIBuff,&Screen->BitMap,&colortable[0],1);
  725. }
  726.  
  727. setup()
  728. {
  729. int i;
  730.  
  731. InitBitMap(&bm,1,320,NormalRows);
  732. for (i=0; i<6; i++)
  733.     bm.Planes[i]=offset;
  734. NewScreenStructure.Depth=1;
  735.  
  736. width=320; height=NormalRows;
  737.  
  738. if(!(Screen=OpenScreen(&NewScreenStructure))) {
  739.     problem("   Screen Jaeger: Couldn't open Screen.  ");
  740.     closestuff(1);
  741.     }
  742.  
  743. Screen2.TopEdge=NormalRows-56;
  744. Screen2.Height=55;
  745.  
  746. if(!(MainScreen=OpenScreen(&Screen2))) {
  747.     problem("   Screen Jaeger: Couldn't open S.Screen!  ");
  748.     closestuff(1);
  749.     }
  750.  
  751. sprintf(Gadget26SIBuff,"%-d",NormalRows);
  752. strcpy(Gadget25SIBuff,"320");
  753. vport=&MainScreen->ViewPort;
  754. ViewPort=&Screen->ViewPort;
  755. LoadRGB4(vport,&Palette[0],PaletteColorCount);
  756. NewWindowStructure1.Screen=MainScreen;
  757. if(!(Window=OpenWindow(&NewWindowStructure1))) {
  758.     problem("   Screen Jaeger: Couldn't open Window!.  ");
  759.     closestuff(1);
  760.     }
  761. rport=Window->RPort;
  762. Move(rport,178,10);
  763. SetAPen(rport,1); SetBPen(rport,0);
  764. Text(rport,"Planes: 1",9);
  765. display_offset();
  766. show_mem_type();
  767. lower[0]=0; lower[1]=0; upper[0]=0; upper[1]=0;  /* clear mem values */
  768. Forbid();
  769. for (mh=(struct MemHeader *) SysBase->MemList.lh_Head; mh->mh_Node.ln_Succ;
  770.     mh=(struct MemHeader *)mh->mh_Node.ln_Succ) {
  771.     if (mh->mh_Attributes & MEMF_CHIP) {
  772.         lower[CHIP]=mh->mh_Lower; upper[CHIP]=mh->mh_Upper; }
  773.     if (mh->mh_Attributes & MEMF_FAST) {
  774.         lower[FAST]=mh->mh_Lower; upper[FAST]=mh->mh_Upper; }
  775.     }
  776. Permit();
  777. calcpropgad();
  778. }
  779.  
  780. problem(message)
  781. char *message;
  782. {
  783. int l;
  784.  
  785. message[0]=0; message[1]=8; message[2]=14;
  786. l=strlen(message);
  787. message[l-2]=0; message[l-1]=0;
  788. DisplayAlert(RECOVERY_ALERT,message,30);
  789. }
  790.  
  791. openlibraries()
  792. {
  793. if(!(IntuitionBase=OpenLibrary("intuition.library",0L))) {
  794.     problem("   Screen Jaeger: Couldn't open Intuition.  ");
  795.     exit(1);
  796.     }
  797.  
  798. if(!(GfxBase=OpenLibrary("graphics.library",0L))) {
  799.     problem("   Screen Jaeger: Couldn't open Graphics!!  ");
  800.     exit(1);
  801.     }
  802. NormalRows=GfxBase->NormalDisplayRows;  /* see if we're PAL or not! */
  803. if(!(IFFBase=OpenLibrary("iff.library",15))) {
  804.     problem("   Screen Jaeger: Please copy iff.library V15 or higher to SYS:LIBS directory!  ");
  805.     exit(1);
  806.     }
  807. }
  808.  
  809. closestuff(value)
  810. int value;
  811. {
  812. if (type==FAST) freefastmem();
  813. if (Screen) {
  814.     type=CHIP;
  815.     num_bitplanes=1;
  816.     set_depth();
  817.     bm.Planes[0]=MainScreen->RastPort.BitMap->Planes[0];
  818.     Screen->RastPort.BitMap->Planes[0]=MainScreen->RastPort.BitMap->Planes[0];
  819.     CloseScreen(Screen);
  820.     }
  821. if (Window) CloseWindow(Window);
  822. if (MainScreen) CloseScreen(MainScreen);
  823. if (IFFBase) CloseLibrary(IFFBase);
  824. if (GfxBase) CloseLibrary(GfxBase);
  825. if (IntuitionBase) CloseLibrary(IntuitionBase);
  826. if (value > 0) exit(-1);
  827. }
  828.  
  829.