home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 097.lha / Ic.Source / menu.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  15KB  |  632 lines

  1. /*
  2.  
  3. InvaderCraft von J.Hertel
  4. (C) CW-Publikationen
  5.  
  6.  "menu.c"
  7.  
  8.  
  9. Kompilieren mit Aztec C Version 3.20a.
  10.  
  11. Im Include-Directory muss sich das Header-File "invadercraft1.h" befinden!
  12.  
  13. Aufruf:  cc menu -a
  14.          as menu
  15.  
  16. Linken:  siehe invadercraft.c
  17.  
  18. */
  19.  
  20. #include <exec/types.h>
  21. #include <exec/interrupts.h>
  22. #include <graphics/gfx.h>
  23. #include <graphics/view.h>
  24. #include <graphics/rastport.h>
  25. #include <graphics/gfxmacros.h>
  26. #include <hardware/intbits.h>
  27. #include <hardware/dmabits.h>
  28. #include <hardware/custom.h>
  29. #include <hardware/cia.h>
  30.  
  31. /* Vor Compiler-Aufruf unbedingt "invadercraft1.h" in include/ - Directory
  32. kopieren! */
  33.  
  34. #include <invadercraft1.h>
  35.  
  36. extern char *versstr[];
  37. extern int _Dorg,player,anzplay,ship[],version,demo,kick;
  38. extern struct Custom *custom;
  39. extern struct CIA *ciaa;
  40. extern struct RastPort rp,rp2;
  41. extern struct ViewPort vp,vphi;
  42. extern struct BitMap bm,bm2,ab1;
  43. extern UWORD colorhi[],color1[],color2[],color3[];
  44. extern long YA[];
  45.  
  46. long MITTE[]={87,110};
  47. struct Interrupt VertBIntr;
  48. struct liste slots[MAXVERSIONS][SLOTS];
  49.  
  50. #define ANZSTR1 6          /* Hauptmenu */
  51. char *textstr[ANZSTR1]={
  52. "Choose Version",
  53. "One Player Game",
  54. "Two Player Game",
  55. "Hall of Fame",
  56. "About",
  57. "Exit"
  58. };
  59.  
  60. #define ANZSTR3 7          /* About */
  61. char *aboutstr[ANZSTR3]={
  62. "InvaderCraft",
  63. "written by",
  64. "J. Hertel",
  65. "Version 2.0",
  66. "Copyright",
  67. "1987 by",
  68. "CW-Publikationen",
  69. };
  70.  
  71. #define ANZSTERN 35
  72. UBYTE vstern[ANZSTERN];
  73. USHORT xstern[ANZSTERN],ystern[ANZSTERN];
  74.  
  75. long zufall=523476729;
  76. USHORT rnd;
  77.  
  78. VertBServer()
  79. /* Interface zwischen C-Code und Interrupt-Handler */
  80. {
  81. #asm
  82.    movem.l d2-d7/a2-a4,-(sp)
  83.    move.l a1,a4
  84. #endasm
  85.    hinter();
  86. #asm
  87.    MOVEQ.L #0,D0
  88.    movem.l (sp)+,d2-d7/a2-a4
  89. #endasm
  90. }
  91.  
  92. /* Zufallszahlen-Routine, Aufruf: rnd1(), Resultat in rnd */
  93.  
  94. #asm
  95.    cseg
  96. _rnd1:
  97.    public _rnd1
  98.    movem.l d0-d3,-(sp)
  99.    move.l _zufall,d0
  100.    move.w #7,d3
  101. label:
  102.    move.b d0,d1
  103.    move.b d0,d2
  104.    lsr.b #3,d1
  105.    lsr.b #1,d2
  106.    eor.b d1,d2
  107.    lsr.b #1,d2
  108.    roxr.l #1,d0
  109.    move.l d0,_zufall
  110.    dbra d3,label
  111.    move.w d0,_rnd
  112.    movem.l (sp)+,d0-d3
  113.    rts
  114.    cseg
  115. #endasm
  116.  
  117. interein()
  118. /* Vertical-Blank-Interrupt einschalten fuer die Bewegung der Sterne im
  119. Hintergrund */
  120. {
  121.    VertBIntr.is_Node.ln_Type=NT_INTERRUPT;
  122.    VertBIntr.is_Node.ln_Pri=-60;
  123.    VertBIntr.is_Node.ln_Name="InvaderCraft!";
  124.    VertBIntr.is_Data=(APTR)((BYTE *)&_Dorg+32766);
  125.    VertBIntr.is_Code=(void (*)())VertBServer;
  126.  
  127.    AddIntServer(INTB_VERTB,&VertBIntr);
  128. }
  129.  
  130. interaus()
  131. /* Ausschalten des Vertical-Blank-Interrupts */
  132. {
  133.    RemIntServer(INTB_VERTB,&VertBIntr);
  134. }
  135.  
  136. hauptmenu()
  137.  
  138. /* Hauptmenue (Choose Version/One Player Game/Two Player Game/Hall of Fame/
  139. About/Exit) anzeigen, Joystick abfragen und entsprechende Routinen
  140. aufrufen */
  141.  
  142. {
  143.    int i,item=1;
  144.  
  145.    do {
  146.       player=0; anzplay=1; ship[0]=0; ship[1]=0;
  147.       titrest();
  148.       sync();
  149.       if(item==1||item==2)
  150.          demorot();
  151.       SetRast(&rp2,0L); SetRast(&rp,0L);
  152.       auswahlanz(0,1,ANZSTR1,textstr[0]);
  153.       for(i=1;i<ANZSTR1;i++)
  154.          auswahlanz(i,3,ANZSTR1,textstr[i]);
  155.       interein();
  156.       if(item==2||item==1) {
  157.          sound(15,0,3);
  158.          sound(15,0,4);
  159.          einblenden(color1,1);
  160.       }
  161.       else
  162.          einblenden(color1,0);
  163.       item=0;
  164.       do {
  165.          for(i=0;i<5;i++) {
  166.             sync();
  167.             SetRGB4(&vp,10L,(long)(i%5+5),(long)((i+3)%5+6),
  168.              (long)((i+6)%6+5));
  169.          }
  170.          auswahlanz(item,3,ANZSTR1,textstr[item]);
  171.          if((custom->joy1dat>>1 ^ custom->joy1dat)&1)
  172.             item=(item+1)%6;
  173.          else if((custom->joy1dat>>1 ^ custom->joy1dat)&0x100)
  174.             item=(item+5)%6;
  175.          auswahlanz(item,1,ANZSTR1,textstr[item]);
  176.  
  177.       } while(ciaa->ciapra&0x80);
  178.       while ((ciaa->ciapra&0x80)==0) ;
  179.  
  180.       if(item==1||item==2) {     /* One/Two Player Game  */
  181.          ausblenden(1);
  182.          interaus();
  183.          spiel(item-1);
  184.       }
  185.       else if(item==3) {         /* Hall of Fame */
  186.          ausblenden(0);
  187.          interaus();
  188.          showhi();
  189.          while(ciaa->ciapra&0x80);
  190.          while ((ciaa->ciapra&0x80)==0) ;
  191.          ausblenden(0);
  192.          interaus();
  193.       }
  194.       else if(item==0)
  195.          otherversion();         /* Choose Version */
  196.       else if(item==4) {
  197.          ausblenden(0);          /* About */
  198.          about1();
  199.          einblenden(color3,0);
  200.          while(ciaa->ciapra&0x80);
  201.          while ((ciaa->ciapra&0x80)==0);
  202.          ausblenden(0);
  203.          about();
  204.          einblenden(color1,0);
  205.          while(ciaa->ciapra&0x80);
  206.          while ((ciaa->ciapra&0x80)==0);
  207.          ausblenden(0);
  208.          interaus();
  209.       }
  210.       else {
  211.          ausblenden(1);          /* Exit */
  212.          interaus();
  213.       }
  214.    } while(item!=5);
  215. }
  216.  
  217. otherversion()
  218.  
  219. /* Menue zur Auswahl der verschiedenen Versionen anzeigen und gewuenschte
  220. Version einschalten */
  221.  
  222. {
  223.    int i;
  224.  
  225.    ausblenden(0);
  226.    SetRast(&rp2,0L);
  227.    auswahlanz(version,1,MAXVERSIONS,versstr[version]);
  228.    for(i=0;i<MAXVERSIONS;i++) {
  229.       if(i!=version)
  230.          auswahlanz(i,3,MAXVERSIONS,versstr[i]);
  231.    }
  232.    einblenden(color1,0);
  233.    do {
  234.       for(i=0;i<5;i++) {
  235.          sync();
  236.          SetRGB4(&vp,10L,(long)(i%5+5),(long)((i+3)%5+6),(long)((i+6)%6+5));
  237.       }
  238.       auswahlanz(version,3,MAXVERSIONS,versstr[version]);
  239.       if((custom->joy1dat>>1 ^ custom->joy1dat)&1)
  240.          version=(version+1)%MAXVERSIONS;
  241.       else if((custom->joy1dat>>1 ^ custom->joy1dat)&0x100)
  242.          version=(version+MAXVERSIONS-1)%MAXVERSIONS;
  243.       auswahlanz(version,1,MAXVERSIONS,versstr[version]);
  244.  
  245.    } while(ciaa->ciapra&0x80);
  246.    while ((ciaa->ciapra&0x80)==0);
  247.    ausblenden(0);
  248.    interaus();
  249. }
  250.  
  251. demorot()
  252.  
  253. /* Demo-Modus - Computer spielt nun Invadercraft bis Joystick-Knopf (oder
  254. ausnahmsweise linke Maustaste) betaetigt wird */
  255.  
  256. {
  257.    int demozeiger=0,flg=1;
  258.  
  259.    SetRast(&rp,0L); SetRast(&rp2,0L);
  260.    sound(15,0,3);
  261.    sound(15,0,4);
  262.    demo=1;
  263.    for(;;demozeiger=(demozeiger+1)%4) {
  264.      /* Auswahl aller Hauptmenuepunkte */
  265.       switch(demozeiger) {
  266.          case 0:
  267.             ausblenden(0);
  268.             interein();
  269.             about1();
  270.             einblenden(color3,flg);
  271.             if(sleep()) {
  272.                ausblenden(1);
  273.                interaus();
  274.                goto enddemo1;
  275.             }
  276.             flg=0;
  277.          break;
  278.          case 1:
  279.             ausblenden(0);
  280.             about();
  281.             einblenden(color1,0);
  282.             if(sleep()) {
  283.                ausblenden(1);
  284.                interaus();
  285.                goto enddemo1;
  286.             }
  287.          break;
  288.          case 2:
  289.             ausblenden(0);
  290.             interaus();
  291.             showhi();
  292.             if(sleep()) {
  293.                ausblenden(1);
  294.                interaus();
  295.                goto enddemo1;
  296.             }
  297.             ausblenden(0);
  298.             interaus();
  299.          break;
  300.          case 3:
  301.             SetRast(&rp,0L); SetRast(&rp2,0L);
  302.             SetAPen(&rp,0L); SetAPen(&rp2,0L);
  303.             if(spiel(0))
  304.                goto enddemo;
  305.             SetRast(&rp,0L);
  306.          break;
  307.       }
  308.    }
  309.  
  310. enddemo:
  311.    ausblenden(1);
  312. enddemo1:
  313.    demo=0;
  314. }
  315.  
  316. sleep()
  317.  
  318. /* Joystick und linke Maustaste abfragen; wenn gedrueckt, dann sleep()==1 */
  319.  
  320. {
  321.    int i;
  322.  
  323.    for(i=0;i<300;i++) {
  324.       sync();
  325.       if((ciaa->ciapra&0x80)==0) {
  326.          while ((ciaa->ciapra&0x80)==0);
  327.          return(1);
  328.       }
  329.       if((ciaa->ciapra&0x40)==0) {
  330.          while ((ciaa->ciapra&0x40)==0);
  331.          return(1);
  332.       }
  333.    }
  334.    return(0);
  335. }
  336.  
  337. about()
  338.  
  339. /* Copyright-Hinweis und Name des Programmierers zeigen */
  340.  
  341. {
  342.    int i,j;
  343.  
  344.    SetRast(&rp2,0L);
  345.    for(i=0;i<ANZSTR3;i++) {
  346.       auswahlanz(i,1,ANZSTR3,aboutstr[i]);
  347.    }
  348. }
  349.  
  350. about1()
  351.  
  352. /* IFF-Brush ("ic.data:about") mit dem Titel des Programms anzeigen */
  353.  
  354. {
  355.    SetRast(&rp2,0L);
  356.    BltBitMap(&ab1,0L,0L,&bm2,VX,VY+MITTE[kick]-ABOUTHEIGHT/2,ABOUTWIDTH,
  357.     ABOUTHEIGHT,0xc0L,0xffL);
  358. }
  359.  
  360. hinter()
  361.  
  362. /* Sterne im Hintergrund bewegen (einfach, da Dual-Playfield) */
  363.  
  364. {
  365.    int addr1,i;
  366.    long addr;
  367.    BYTE xz;
  368.  
  369.    OFF_SPRITE
  370.    for(i=0;i<ANZSTERN;i++) {
  371.       if(xstern[i]< VX-1) {
  372.          xstern[i]=XA+VX;
  373.       }
  374.       addr=ystern[i]*bm.BytesPerRow; addr1=xstern[i]>>3;
  375.       if(i&1)
  376.          *(bm.Planes[0]+addr+addr1)=0;
  377.       if(i&2)
  378.          *(bm.Planes[1]+addr+addr1)=0;
  379.       if(i&4)
  380.          *(bm.Planes[2]+addr+addr1)=0;
  381.       xstern[i]-=vstern[i]; addr1=xstern[i]>>3; xz=128>>(xstern[i]&7);
  382.  
  383.       if(i&1)  /* Einfaerben der Sterne */
  384.          *(bm.Planes[0]+addr+addr1)=xz;
  385.       if(i&2)
  386.          *(bm.Planes[1]+addr+addr1)=xz;
  387.       if(i&4)
  388.          *(bm.Planes[2]+addr+addr1)=xz;
  389.  
  390.    }
  391. }
  392.  
  393. sternsetz()
  394.  
  395. /* Stern-Koordinaten und Geschwindigkeiten festsetzen */
  396.  
  397. {
  398.    int i;
  399.  
  400.    for(i=0;i<ANZSTERN;i++) {
  401.        rnd1();
  402.        ystern[i]=(long)YA[kick]*(long)rnd/0x10000L+VY;
  403.        rnd1();
  404.        vstern[i]=10L*(long)rnd/0x10000L+1;
  405.        rnd1();
  406.        xstern[i]=(long)XA*(long)rnd/0x10000L+VX;
  407.    }
  408. }
  409.  
  410. auswahlanz(i,j,anzstring,string)
  411. int i,j,anzstring;
  412. char *string;
  413.  
  414. /* Zeile zweifarbigen Textes anzeigen (automatisch zentrierend)
  415.    i           Zeilennummer ( Zeilenhoehe = 20 Pixels )
  416.    j           Farbe (bzw.j+1)
  417.    anzstring   Anzahl an Zeilen insgesamt (fuer Zentrierung)
  418.    string      Zeiger auf auszudruckenden String */
  419.  
  420. {
  421.    SetAPen(&rp2,(long)j);
  422.    Move(&rp2,XA/2+VX-5L*strlen(string),VY+MITTE[kick]+6L+20L*i-
  423.     anzstring*10L+5L);
  424.    Text(&rp2,string,(long)strlen(string));
  425.    SetAPen(&rp2,(long)j+1L);
  426.    Move(&rp2,XA/2+VX-5L*strlen(string)+1L,VY+MITTE[kick]+6L+20L*i-
  427.     anzstring*10L+5L);
  428.    Text(&rp2,string,(long)strlen(string));
  429. }
  430.  
  431. showhi()
  432.  
  433. /* Highscore-Tabelle zeigen */
  434.  
  435. {
  436.    int i,y;
  437.    char str[6];
  438.    ULONG z;
  439.  
  440.    SetRast(&rp,0L); SetRast(&rp2,0L);
  441.    for(y=0;y<SLOTS;y++) {
  442.       for(i=0;i<6;i++)
  443.          str[i]=' ';
  444.       z=slots[version][y].score;
  445.       for(i=5;i>=0;i--) {
  446.          str[i]= z % 10 + 48;
  447.          z/=10;
  448.             if(z==0)
  449.                break;
  450.       }
  451.       SetAPen(&rp2,1L);
  452.       Move(&rp2,125L,y*10L+MITTE[kick]+VY-SLOTS*5L+6L+3L);
  453.       Text(&rp2,slots[version][y].who,8L);
  454.       Move(&rp2,220L,y*10L+MITTE[kick]+VY-SLOTS*5L+6L+3L);
  455.       Text(&rp2,str,6L);
  456.  
  457.       SetAPen(&rp2,2L);
  458.       Move(&rp2,126L,y*10L+MITTE[kick]+VY-SLOTS*5L+6L+3L);
  459.       Text(&rp2,slots[version][y].who,8L);
  460.       Move(&rp2,221L,y*10L+MITTE[kick]+VY-SLOTS*5L+6L+3L);
  461.       Text(&rp2,str,6L);
  462.  
  463.    }
  464.    interein();
  465.    einblenden(color2,0);
  466. }
  467.  
  468. ausblenden(nichtstill)
  469. int nichtstill;
  470.  
  471. /* Ausblenden von Grafik und, wenn 'nichtstill' ungleich Null, von Sound
  472. (Soundfile 15) */
  473.  
  474. {
  475.    int i,j;
  476.    UWORD zcol;
  477.  
  478.    for(j=0;j<16;j++) {
  479.       sync();
  480.       if(nichtstill) {
  481.          soundvol(15,60-j*4,3);
  482.          soundvol(15,60-j*4,4);
  483.       }
  484.       for(i=0;i<AC;i++) {
  485.          zcol=*((UWORD *)vp.ColorMap->ColorTable+i);
  486.          if(zcol&0xf00)
  487.             zcol-=0x100;
  488.          if(zcol&0x0f0)
  489.             zcol-=0x010;
  490.          if(zcol&0x00f)
  491.             zcol-=0x001;
  492.          SetRGB4(&vp,(long)i,(long)zcol/256,(long)(zcol/16)%16,
  493.           (long)zcol%16);
  494.       }
  495.       for(i=0;i<HIAC;i++) {
  496.          zcol=*((UWORD *)vphi.ColorMap->ColorTable+i);
  497.          if(zcol&0xf00)
  498.             zcol-=0x100;
  499.          if(zcol&0x0f0)
  500.             zcol-=0x010;
  501.          if(zcol&0x00f)
  502.             zcol-=0x001;
  503.          SetRGB4(&vphi,(long)i,(long)zcol/256,(long)(zcol/16)%16,
  504.           (long)zcol%16);
  505.       }
  506.    }
  507. }
  508.  
  509. einblenden(table,nichtstill)
  510. UWORD table[];
  511. int nichtstill;
  512.  
  513. /* Einblenden von Grafik mit Farbtabelle, die durch table[] festgelegt
  514. wird, und, wenn 'nichtstill' ungleich Null, von Sound (Nr.15) */
  515.  
  516. {
  517.    int i,j;
  518.    UWORD zcol;
  519.  
  520.    for(j=0;j<16;j++) {
  521.       sync();
  522.       if(nichtstill) {
  523.          soundvol(15,j*4+4,3);
  524.          soundvol(15,j*4+4,4);
  525.       }
  526.       for(i=0;i<AC;i++) {
  527.          zcol=*((UWORD *)vp.ColorMap->ColorTable+i);
  528.          if((zcol&0xf00) < (table[i]&0xf00))
  529.             zcol+=0x100;
  530.          if((zcol&0x0f0) < (table[i]&0x0f0))
  531.             zcol+=0x010;
  532.          if((zcol&0x00f) < (table[i]&0x00f))
  533.             zcol+=0x001;
  534.          SetRGB4(&vp,(long)i,(long)zcol/256,(long)(zcol/16)%16,
  535.           (long)zcol%16);
  536.       }
  537.       for(i=0;i<HIAC;i++) {
  538.          zcol=*((UWORD *)vphi.ColorMap->ColorTable+i);
  539.          if((zcol&0xf00) < (colorhi[i]&0xf00))
  540.             zcol+=0x100;
  541.          if((zcol&0x0f0) < (colorhi[i]&0x0f0))
  542.             zcol+=0x010;
  543.          if((zcol&0x00f) < (colorhi[i]&0x00f))
  544.             zcol+=0x001;
  545.          SetRGB4(&vphi,(long)i,(long)zcol/256,(long)(zcol/16)%16,
  546.           (long)zcol%16);
  547.       }
  548.    }
  549. }
  550.  
  551. eintrag(wieviel)
  552. ULONG wieviel;
  553.  
  554. /* Eintragen in die Highscore-Liste (Joystick rechts/links = Cursor steuern,
  555. nach oben/unten = Buchstaben wechseln, Feuerknopf = Beenden) */
  556.  
  557. {
  558.    int i,j,k;
  559.    char z,c;
  560.  
  561.    for(i=0;i<SLOTS;i++) {
  562.       if(slots[version][i].score<wieviel)
  563.          break;
  564.    }
  565.    if(i==SLOTS)
  566.       return();
  567.    for(j=SLOTS-1;j>i;j--)
  568.       slots[version][j]=slots[version][j-1];
  569.    slots[version][i].score=wieviel;
  570.    for(j=0;j<8;j++)
  571.       slots[version][i].who[j]=' ';
  572.    showhi();
  573.    z=1; j=0;
  574.    do {
  575.       if((custom->joy1dat>>1 ^ custom->joy1dat)&1)
  576.          z=(z+27)%28;
  577.       else if((custom->joy1dat>>1 ^ custom->joy1dat)&0x100)
  578.          z=(z+1)%28;
  579.       else if(custom->joy1dat & 0x200) {
  580.          if(j) {
  581.             j--; z=slots[version][i].who[j]-'?';
  582.          }
  583.       }
  584.       else if(custom->joy1dat & 2) {
  585.          if(j<7) {
  586.             j++; z=slots[version][i].who[j]-'?';
  587.          }
  588.       }
  589.       if(z<0)
  590.          if(z==' '-'?')
  591.             z=1;
  592.          else
  593.             z=0;
  594.       if(z==1)
  595.          c=' ';
  596.       else if(z==0)
  597.          c='.';
  598.       else
  599.          c=z+'?';
  600.       slots[version][i].who[j]=c;
  601.       for(k=0;k<7;k++) {
  602.          SetAPen(&rp2,(long)2*(k%2));
  603.          Move(&rp2,125L+10L*j,i*10L+MITTE[kick]+VY-SLOTS*5L+2L+6L+3L);
  604.          Draw(&rp2,125L+10L*j+10L,i*10L+MITTE[kick]+VY-SLOTS*5L+2L+6L+3L);
  605.          sync();
  606.       }
  607.       SetDrMd(&rp2,JAM2);
  608.       Move(&rp2,125L+10L*j,i*10L+MITTE[kick]+VY-SLOTS*5L+6L+3L);
  609.       Text(&rp2," ",1L);
  610.       Move(&rp2,126L+10L*j,i*10L+MITTE[kick]+VY-SLOTS*5L+6L+3L);
  611.       Text(&rp2," ",1L);
  612.       SetDrMd(&rp2,JAM1); SetAPen(&rp2,1L);
  613.       Move(&rp2,125L+10L*j,i*10L+MITTE[kick]+VY-SLOTS*5L+6L+3L);
  614.       Text(&rp2,&c,1L);
  615.       SetAPen(&rp2,2L);
  616.       Move(&rp2,126L+10L*j,i*10L+MITTE[kick]+VY-SLOTS*5L+6L+3L);
  617.       Text(&rp2,&c,1L);
  618.    } while(ciaa->ciapra&0x80);
  619.    while ((ciaa->ciapra&0x80)==0) ;
  620. }
  621.  
  622. sync()
  623.  
  624. /* Bildschirmzeile abwarten ( VBeamPos() wird an Stelle von WaitTOF() oder
  625. WaitBOVP() verwendet, da diese Forbid() wieder desaktivieren ) */
  626.  
  627. {
  628.    while(VBeamPos()<240||VBeamPos()>249);
  629.    while(VBeamPos()<250);
  630. }
  631.  
  632.