home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / commodities / superdark / blankers / music.dark.c < prev    next >
C/C++ Source or Header  |  1993-03-19  |  15KB  |  646 lines

  1.  /* Fichier Music.dark.c                */
  2. /* Module appele par le programme principal    */
  3. /* pour effectuer un effet defini..appele par    */
  4. /* loadseg                    */
  5.  
  6. #include    <exec/types.h>
  7. #include    <exec/memory.h>
  8. #include    <exec/interrupts.h>
  9. #include    <graphics/gfx.h>
  10. #include    <graphics/gfxmacros.h>
  11. #include    <graphics/rastport.h>
  12. #include    <graphics/gfxbase.h>
  13. #include    <clib/exec_protos.h>
  14. #include    <clib/graphics_protos.h>
  15. #include    <clib/intuition_protos.h>
  16. #include    <clib/gadtools_protos.h>
  17. #include    <dos/dos.h>
  18. #include    <devices/audio.h>
  19. #include    <hardware/cia.h>
  20. #include    <clib/asl_protos.h>
  21. #include    <libraries/gadtools.h>
  22. #include    <libraries/asl.h>
  23. #include    "/includes/struct.h"
  24. #include    "/includes/tom_gadget.h"
  25.  
  26. BPTR    hdf;
  27. extern    struct    CIA    far ciab;
  28. struct    RastPort    *rp,rp_s;
  29. struct    Screen    *s;
  30. extern    struct    appel_proc    *p_data_proc;
  31. struct    Library *myCiaPointer;
  32. struct    Library *AudioDev;
  33. struct    Library *AslBase;
  34. extern    struct    GfxBase *GfxBase;
  35. struct    Library    *GadToolsBase;
  36. /* Pour l'audiodevice */
  37. struct    IOAudio    *allocIOB=0;
  38. struct    IOAudio    *lockIOB=0;
  39. struct    Device    *device=0;
  40. struct    MsgPort    *soundport=0;
  41. UBYTE    allocationmap[]={15};
  42. struct    BitMap    b;
  43. unsigned    int    seed;
  44. struct    FileRequester    *my_req=0;
  45. UBYTE    flg_able;
  46.  
  47. extern    void    mt_init(),mt_music(),mt_end();
  48. UWORD    v[4];
  49.  
  50. #define    WIDTH    320
  51. int    HEIGHT;
  52. #define    HEIGHT_S    161
  53. #define    DEPTH    5
  54. #define    POSY_SCENE    102
  55. #define    NB_ANIM        12
  56. #define    FIRST_X        64
  57.  
  58. #define    T_PLATE_FORME    4
  59. #define    T_POI        18
  60. extern    char    *get_image();
  61. char    *image;
  62. char    *p_text_info="      'The Great PoiPoi'\n\n\nBased on an my old demo....The poipoi are\nvery nice guys,bumping and playing in rythm.\n\nYou can choose a the soundtracker module to\nplay by selecting it in the string gadget.\n\nYou can select the voice instrument assigned\nto a PoiPoi in the bottom of the screen. If\nthe selected voice do nothing, the PoPoi will\nnot move!\n(Read docs...)\n\n     V1.0 By T.Landspurg";
  63.  
  64. char    *adr_data;
  65. extern    void    replay();
  66. UWORD    tab_inst[32];
  67.  
  68. WORD ColorMap[] =
  69. {
  70.    0x000,0xFE0,0xF00,0xDDE,0x0B0,0x333,0x959,0x747,
  71.    0x077,0x00F,0x0A0,0x070,0xA00,0x050,0x000,0x0EE,
  72.    0xB00,0xBA0,0x733,0x944,0xB55,0x444,0x555,0x666,
  73.    0x777,0x888,0x044,0xAAA,0x99A,0xDDD,0x0BA,0xFFF
  74. };
  75.  
  76. struct NewScreen    Screen = {
  77.     0, 0, WIDTH,  256, DEPTH, 0,0,0, CUSTOMSCREEN, NULL, NULL ,NULL, NULL};
  78.  
  79. /*char    nom[100]="<insert a module name here>";*/
  80. char    nom[100]="DH_Divers:Musiques/Modules-ST/mod.impact";
  81.  
  82. int    __saveds    press_load();
  83.  
  84. struct tom_gadget my_gadg[]={
  85.     {"_Module",    STRING, 100, 20,  250,13,0,100,0,0,nom},
  86.     {"Drummer (l)",    INTEGER,100, 35,  50,13,5,2,0,0,0},
  87.     {"Drummer (r)",    INTEGER,100, 50,  50,13,5,2,0,0,0},
  88.     {"Left  Keyb",    INTEGER,250, 35,  50,13,2,2,0,0,0},
  89.     {"Right Keyb",    INTEGER,250, 50,  50,13,7,2,0,0,0},
  90.     {"guitar",    INTEGER,100, 65,  50,13,1,2,0,0,0},
  91.     {"_Sel",    BUTTON ,380, 20,  50,13, 0,0,0,0,(char *)&press_load},
  92.     {0,        END_LISTE,  0,  0,   0, 0, 0,0,0,0,0}
  93. };
  94. struct    Interrupt *p_interrupt;
  95.  
  96. #define    SIZE    100000
  97.  
  98. #define    OK    1
  99. #define    NOK    0
  100.  
  101. #define    FREQU_PAL    1773447/125
  102. #define FREQU_NTSC    1789773/125
  103. int    frequ=FREQU_PAL;
  104.  
  105. /**************************************************/
  106.  
  107. int    init_audio()
  108. {
  109.     if(((allocIOB=(struct IOAudio *)AllocMem(sizeof(struct IOAudio),MEMF_PUBLIC|MEMF_CLEAR))==0)||
  110.        (( lockIOB=(struct IOAudio *)AllocMem(sizeof(struct IOAudio),MEMF_PUBLIC|MEMF_CLEAR))==0)){
  111.         return(NOK);
  112.     }
  113.     if(OpenDevice(AUDIONAME,0,allocIOB,0)!=0){
  114.         return(NOK);
  115.     }
  116.     device=allocIOB->ioa_Request.io_Device;
  117.     allocIOB->ioa_Request.io_Message.mn_Node.ln_Pri=127;
  118.     if((soundport=(struct MsgPort *)CreatePort("music.dark",0))==0){
  119.         return(NOK);
  120.     }
  121.  
  122.     allocIOB->ioa_Request.io_Message.mn_ReplyPort=soundport;
  123.     allocIOB->ioa_Request.io_Command=ADCMD_ALLOCATE;
  124.     allocIOB->ioa_Request.io_Flags=ADIOF_NOWAIT;
  125.     allocIOB->ioa_Data=allocationmap;
  126.     allocIOB->ioa_Length=sizeof(allocationmap);
  127.     BeginIO(allocIOB);
  128.     if(WaitIO(allocIOB)){
  129. /*        SimpleRequest("Audio device busy");*/
  130.         return(NOK);
  131.     }
  132.     lockIOB->ioa_Request.io_Message.mn_ReplyPort=soundport;
  133.     lockIOB->ioa_Request.io_Device=device;
  134.     lockIOB->ioa_Request.io_Unit=allocIOB->ioa_Request.io_Unit;
  135.     lockIOB->ioa_Request.io_Command=ADCMD_LOCK;
  136.     lockIOB->ioa_AllocKey=allocIOB->ioa_AllocKey;
  137.     SendIO(lockIOB);
  138.     if(CheckIO(lockIOB)){
  139. /*        SimpleRequest("Canal deja pris!");*/
  140.         return(NOK);
  141.     }
  142.  
  143.     return(OK);
  144. }
  145. void    free_audio()
  146. {
  147.     if(lockIOB->ioa_Request.io_Device!=0){
  148.         if(CheckIO(lockIOB)){
  149. /*            SimpleRequest("Channel stolen");*/
  150.         }
  151.         allocIOB->ioa_Request.io_Command=ADCMD_FREE;
  152.         DoIO(allocIOB);
  153.     }
  154.     if(soundport!=0)DeletePort(soundport);
  155.     if(device!=0)CloseDevice(allocIOB);
  156.     if(lockIOB!=0)FreeMem(lockIOB,sizeof(struct IOAudio));
  157.     if(allocIOB!=0)FreeMem(allocIOB,sizeof(struct IOAudio));
  158.  
  159. }
  160.  
  161. /**************************************************/
  162.  
  163. int SetCIAInt()
  164. {
  165.     int code_ret;
  166.  
  167.     if( (GfxBase->DisplayFlags & PAL) !=0){
  168.         frequ=FREQU_PAL;
  169.     }else if( (GfxBase->DisplayFlags & NTSC) !=0){
  170.         frequ=FREQU_NTSC;
  171.     }    
  172.     myCiaPointer=(struct Library *)OpenResource("ciab.resource");
  173.     if(myCiaPointer==NULL){
  174.         code_ret=FALSE;
  175.     }else{
  176.         code_ret=TRUE;;
  177.     }
  178.     return(code_ret);
  179. }
  180.  
  181. /**************************************************/
  182.  
  183. unsigned        int     my_rand()
  184. {
  185.         
  186.         seed=25173*seed+138490;
  187.         return(seed);
  188. }
  189.  
  190. /**************************************************/
  191. /* Initialisation de notre handler d'interruption */
  192. /**************************************************/
  193.  
  194. int    setup()
  195. {
  196.  
  197.    p_interrupt=(struct Interrupt *)AllocMem(sizeof(struct Interrupt),MEMF_PUBLIC);
  198.  
  199.    if(p_interrupt == NULL){
  200.     return(NOK);
  201.    }
  202.    p_interrupt->is_Node.ln_Type=NT_INTERRUPT;
  203.    p_interrupt->is_Node.ln_Pri=0;
  204.    p_interrupt->is_Node.ln_Name="SuperDark replay Interrupt";
  205.    p_interrupt->is_Data=0;
  206.    p_interrupt->is_Code=replay;
  207.  
  208.    if(AddICRVector(myCiaPointer,CIAICRB_TA,p_interrupt)!=0){
  209.     return(NOK);
  210.    }else{
  211.     flg_able=TRUE;
  212.     ciab.ciatalo=(UBYTE)(frequ & 0xff);
  213.     ciab.ciatahi=(UBYTE)((frequ>>8) & 0xff);
  214.     ciab.ciacra|=1;
  215.    }
  216.    return(OK);
  217. }
  218.  
  219. /******************************************/
  220. /* Arret  de notre handler d'interruption */
  221. /******************************************/
  222.  
  223. void stop()
  224. {
  225.     if(flg_able){
  226.         AbleICR(myCiaPointer,(1<<CIAICRB_TA) );
  227.            RemICRVector(myCiaPointer,CIAICRB_TA,p_interrupt);
  228.     }
  229.     if(p_interrupt!=0)FreeMem(p_interrupt,sizeof(struct Interrupt));
  230. /*
  231.    exec_safe(tab_replay[num_replay].p_end);
  232. */
  233. }
  234. /********************************************************** aff_poipoi ***/
  235.  
  236. void    aff_poipoi()
  237. {
  238.     UWORD    i;
  239.     UWORD    old[4];
  240.     UWORD    new[4];
  241.     UWORD    poi[4];
  242.     WORD    speed[4];
  243.     UWORD    num_anim[4];
  244.     UWORD    num_bonjour[4];
  245.     UWORD    posx,posy;
  246.     UWORD    temp,tx;
  247.     
  248.     UWORD    anim_bat_g;
  249.     UWORD    num_batteur_g;
  250.     UWORD    anim_bat_d;
  251.     UWORD    num_batteur_d;
  252.     UWORD    anim_keyb_g;
  253.     UWORD    num_keyb_g;
  254.     UWORD    anim_keyb_d;
  255.     UWORD    num_keyb_d;
  256.     UWORD    anim_guitare;
  257.     UWORD    num_guitare;
  258.     UWORD    anim_tourne;
  259.     
  260.     for(i=0;i<4;i++){
  261.         old[i]=0;
  262.         new[i]=0;
  263.         speed[i]=0;
  264.         num_anim[i]=0;
  265.         num_bonjour[i]=0;
  266.         poi[i]=30;
  267.     }
  268.     num_batteur_g=my_gadg[1].value;
  269.     num_batteur_d=my_gadg[2].value;
  270.     num_keyb_g   =my_gadg[3].value;
  271.     num_keyb_d   =my_gadg[4].value;
  272.     num_guitare  =my_gadg[5].value;
  273.     anim_bat_d=0;
  274.     anim_bat_g=0;
  275.     anim_keyb_g=0;
  276.     anim_keyb_d=0;
  277.     anim_guitare=0;
  278.     anim_tourne=0;
  279.  
  280.     SetAPen(rp,0);
  281.     while(tst_end()==FALSE){
  282.  
  283.         WaitTOF();
  284.  
  285.         for(i=0;i<4;i++){
  286.            tx=FIRST_X+i*48;
  287.            new[i]=160-v[i]/2;
  288.            RectFill(rp,tx,poi[i]/2,tx+32,poi[i]/2+T_POI-1);
  289.  
  290.            poi[i]-=speed[i];
  291.            speed[i]--;
  292.  
  293.            /* Animation du poipoi */
  294.  
  295.            /********************************************************/
  296.            /* On demarre l'anim si le poipoi a une vitesse sup a 6 */
  297.            /* lorsqu'il passe a 0                   */
  298.            /********************************************************/
  299.  
  300.            if(num_anim[i]==0){
  301.             if((speed[i]>6)&&(poi[i]/2<100)){
  302.                num_anim[i]=1;
  303.             }
  304.            }else{
  305.             if(num_anim[i])num_anim[i]++;
  306.             if(num_anim[i]==NB_ANIM*2){
  307.                 num_anim[i]=0;
  308.             }
  309.            }
  310.            /************************************/
  311.            /* Si le poipoi "touche" le plateau */
  312.            /************************************/
  313.            if(poi[i]/2+T_POI>=new[i]){
  314.  
  315.             /* Si la vitesse est assez importante pour le*/
  316.             /* faire rebondir                 */
  317.  
  318.             if(old[i]-new[i]>20){
  319.                 speed[i]=5+(poi[i]/2+T_POI-new[i])/5;
  320.                 num_bonjour[i]=0;
  321.             }else{
  322.                 speed[i]=0;
  323.                 num_anim[i]=0;
  324.             }
  325.             poi[i]=2*(new[i]-T_POI+1);
  326.            }
  327.            posx=num_anim[i]>>1;
  328.            posy=0;
  329.            if(posx>=10){
  330.             posx-=10;
  331.             posy=T_POI;
  332.            }
  333.            posx=posx*32;
  334.            /* Si on est pose */
  335.            if(speed[i]==0){
  336.             if(num_bonjour[i]){
  337.                 num_bonjour[i]--;
  338.                 temp=num_bonjour[i]>>4;
  339.                 posy=18;
  340.                 posx=64+temp*32;
  341.             }else{
  342.                 if((my_rand()&0xFF)>254){
  343.                     num_bonjour[i]=(7)<<4;
  344.                 }
  345.             }
  346.            }
  347.                  ClipBlit(&rp_s,posx,posy,rp,tx,poi[i]/2,32,T_POI,0xc0);
  348.         }
  349.         /**************************************/
  350.         /* On s'occupe des support maintenant */
  351.         /**************************************/
  352.         for(i=0;i<4;i++){
  353.            tx=FIRST_X+i*48;
  354.            if(new[i]!=old[i]){
  355.             RectFill(rp,tx,old[i],tx+32,old[i]+T_PLATE_FORME);
  356.             ClipBlit(    &rp_s,0,55,
  357.                     rp,tx,new[i],32,T_PLATE_FORME,0xc0);
  358.             if(new[i]<old[i]) {
  359.                 ClipBlit(    &rp_s,288,17,
  360.                         rp,tx+8,T_PLATE_FORME+new[i],16,old[i]-new[i]+1,0xc0);
  361.             /* Si le plateau redescend trop vitre, il se peut qu'il */
  362.             /* reste un trace d'un precedent "tube"            */
  363.             }else if(new[i]>old[i]+T_PLATE_FORME){
  364.                 RectFill(rp,tx,old[i]+T_PLATE_FORME,
  365.                         tx+16,new[i]);
  366.             }
  367.             old[i]=new[i];
  368.            }
  369.         }
  370.         /* Animation batteur cote gauche */
  371.         if(tab_inst[num_batteur_g]>90){
  372.             anim_bat_g=2*2;
  373.         }
  374.         if(anim_bat_g){
  375.             anim_bat_g--;
  376.             ClipBlit(    &rp_s,128+(anim_bat_g/2)*16,58,
  377.                     rp,96,HEIGHT-36,16,14,0xc0);
  378.         }
  379.  
  380.         /* Animation batteur cote droit */
  381.         if(tab_inst[num_batteur_d]>90){
  382.             anim_bat_d=3*2;
  383.         }
  384.         if(anim_bat_d){
  385.             anim_bat_d--;
  386.             ClipBlit(    &rp_s,80+(anim_bat_d/2)*16,58,
  387.                     rp,112,HEIGHT-39,16,14,0xc0);
  388.         }
  389.         /* Animation keyb cote gauche */
  390.         if(tab_inst[num_keyb_g]>90){
  391.             anim_keyb_g=3*2;
  392.         }
  393.         
  394.         if(anim_keyb_g){
  395.             anim_keyb_g--;
  396.             ClipBlit(    &rp_s,80+(anim_keyb_g/2)*16,72,
  397.                     rp,32,HEIGHT-20,16,5,0xc0);
  398.         }
  399.  
  400.         /* Animation keyb cote gauche */
  401.         if(tab_inst[num_keyb_d]>90){
  402.             anim_keyb_d=3*2;
  403.         }
  404.         if(anim_keyb_d){
  405.             anim_keyb_d--;
  406.             ClipBlit(    &rp_s,80+(anim_keyb_d/2)*16,77,
  407.                     rp,192,HEIGHT-18,16,6,0xc0);
  408.             ClipBlit(    &rp_s,80+(anim_keyb_d/2)*16,83,
  409.                     rp,208,HEIGHT-18,16,6,0xc0);
  410.         }
  411.  
  412.         /* Animation guitare gauche */
  413.         if(tab_inst[num_guitare]>90){
  414.             anim_guitare=3*2;
  415.         }
  416.         if(anim_guitare){
  417.             anim_guitare--;
  418.             ClipBlit(    &rp_s,128+(anim_guitare>>1)*32,72,
  419.                     rp,144,HEIGHT-15,32,12,0xc0);
  420.         }
  421.  
  422.         /* Animation tourne */
  423.         if(anim_tourne){
  424.             anim_tourne--;
  425.             temp=anim_tourne>>4;
  426.             if(temp>=3){
  427.                 temp=5-temp;
  428.             }
  429.             ClipBlit(    &rp_s,80+(temp)*8,89,
  430.                     rp,208,HEIGHT-21,8,9,0xc0);
  431.         }else{
  432.             if((my_rand()&0xFF)>253){
  433.                 anim_tourne=(2*3)<<4;
  434.             }
  435.         }
  436.     }
  437.  
  438. }
  439.  
  440. /********************************************************** press_load() ***/
  441.  
  442. int    __saveds    press_load(pg,p_t,ctx)
  443. struct    Gadget    *pg;
  444. struct    tom_gadget    *p_t;
  445. struct    contexe    *ctx;
  446. {
  447.     UWORD    res,len_dir;
  448.  
  449.     if(my_req!=0){
  450.         res=(int)RequestFile(my_req);
  451.         len_dir=strlen(my_req->rf_Dir);
  452.         if((my_req->rf_Dir[len_dir-1]!='/')&&(my_req->rf_Dir[len_dir-1]!=':')){
  453.             SPrintF(my_gadg[0].p_data,
  454.                 "%s/%s",
  455.                 my_req->rf_Dir,
  456.                 my_req->rf_File);
  457.         }else{
  458.             SPrintF(my_gadg[0].p_data,
  459.                 "%s%s",
  460.                 my_req->rf_Dir,
  461.                 my_req->rf_File);
  462.         }
  463.     }
  464.     if(GadToolsBase!=0){
  465.         GT_SetGadgetAttrs(  my_gadg[0].p_gadg,ctx->Wnd,NULL,
  466.                 GTST_String,my_gadg[0].p_data,
  467.                 TAG_END);
  468.         GT_RefreshWindow( ctx->Wnd, 0l );
  469.     }else{
  470.         RefreshGadgets( ctx->Wnd->FirstGadget,ctx->Wnd, 0l );
  471.     }
  472.     return 0;
  473. }
  474. /********************************************************** dark ()***/
  475.  
  476. void    dark()
  477. {
  478.     UWORD    d,i;
  479.     int    flg_error;
  480.     int    etape;
  481.     int    flg_err;
  482.     struct    FileInfoBlock    *fib;
  483.     BPTR    lt;
  484.     int    size;
  485.     char    *name;
  486.     UWORD    width,height;
  487.     ULONG    did;
  488.  
  489.     lt=0;
  490.     fib=0;
  491.     adr_data=0;
  492.     allocIOB=0;
  493.     lockIOB=0;
  494.     device=0;
  495.     soundport=0;
  496.     p_interrupt=0;
  497.     flg_able=FALSE;
  498.  
  499.     if(GfxBase->Flags&NTSC){
  500.         HEIGHT=200;
  501.     }else{
  502.         HEIGHT=256;
  503.     }
  504.     Screen.Height=HEIGHT;
  505.     d=5;
  506.     width=0;
  507.     height=0;
  508.     if(find_res((SHORT)TRUE,&d,&width,&height,&did)){
  509.         Screen.ViewModes=did;
  510.         if(d<5)return;
  511.     }else{
  512.         return;
  513.     }
  514.  
  515.     InitBitMap(&b,DEPTH,WIDTH,HEIGHT_S);
  516.     InitRastPort(&rp_s);
  517.     rp_s.BitMap=&b;
  518.     image=get_image();
  519.     for(i=0;i<DEPTH;i++){
  520.         b.Planes[i]=image+i*HEIGHT_S*WIDTH/8;
  521.     }
  522.     flg_err=FALSE;
  523.     etape=0;
  524.     while((etape<10)&&(flg_err==FALSE)){
  525.         switch(etape){
  526.             case 0:
  527.                     if (( s = OpenScreen(&Screen))){
  528.                     rp = &(s->RastPort);
  529.                     SetAPen(rp,0);
  530.                     ClipBlit(&rp_s,0,POSY_SCENE,
  531.                         rp,0,HEIGHT-(HEIGHT_S-POSY_SCENE),WIDTH,HEIGHT_S-POSY_SCENE-1,0xc0);
  532.                     if(GfxBase->Flags&NTSC){
  533.                         SetAPen(rp,0);
  534.                         RectFill(rp,
  535.                             0,
  536.                             HEIGHT-(HEIGHT_S-POSY_SCENE),
  537.                             WIDTH-1,
  538.                             HEIGHT-(HEIGHT_S-POSY_SCENE)+55);
  539.                     }
  540.                     d=1<<(s->BitMap.Depth);
  541.                     LoadRGB4(&s->ViewPort,ColorMap,d);
  542.                     FreeSprite (0);
  543.                     GfxBase->SpriteReserved|=1;
  544.                 }else{
  545.                     flg_err=TRUE;
  546.                 }
  547.             break;
  548.             case 1:
  549.                 if(init_audio()!=OK){
  550.                     flg_err=TRUE;
  551.                 }
  552.             break;
  553.             case 2:
  554.                 flg_error=SetCIAInt();
  555.                 break;
  556.             case 3:
  557.                 if(setup()!=OK){
  558.                     flg_error=TRUE;
  559.                 }
  560.                 break;
  561.             case 4:
  562.                 size=0;
  563.                 name=my_gadg[0].p_data;
  564.                 if((fib=(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),0))!=0){
  565.                     lt=Lock(name,ACCESS_READ);
  566.                     if(lt!=0){
  567.                         if(Examine(lt,fib)!=0){
  568.                             size=fib->fib_Size;
  569.                         }
  570.                     }
  571.                 }
  572.                 /* Si le module n'a pas ete trouve, on saute       */
  573.                 /* deux etapes -> on jouera le module par defaut! */
  574.                 if(!size){
  575.                     etape+=2;
  576.                     SetAPen(rp,15);
  577.                     My_Print(rp,30,HEIGHT-(HEIGHT_S-POSY_SCENE)-20,"Error with selected module");
  578.                     My_Print(rp,30,HEIGHT-(HEIGHT_S-POSY_SCENE)-10,"  --- Using default ---");
  579.                 }
  580.                 break;
  581.             case 5:
  582.                 adr_data=AllocMem(size,MEMF_CHIP|MEMF_CLEAR);
  583.                 if(adr_data!=0){
  584.                     hdf=Open(name,MODE_OLDFILE);
  585.                     if(hdf!=0){
  586.                         Read(hdf,adr_data,size);
  587.                         Close(hdf);
  588.                     }
  589.                 }else{
  590.                     flg_err=TRUE;
  591.                 }
  592.             break;
  593.             /* Test if the module is really a stk module */
  594.             case 6:
  595.                 name=&adr_data[0x438];
  596.                 if(strncmp(name,"M.K.",4)){
  597.                     FreeMem(adr_data,size);
  598.                     adr_data=0;
  599.                     SetAPen(rp,15);
  600.                     My_Print(rp,20,HEIGHT-(HEIGHT_S-POSY_SCENE)-20,"   Error with selected module");
  601.                     My_Print(rp,20,HEIGHT-(HEIGHT_S-POSY_SCENE)-10,"-- Not a soundtracker module --");
  602.                 }
  603.                 break;
  604.             case 7:
  605.                 exec_safe(mt_init);
  606.                 aff_poipoi();
  607.                 break;
  608.             default:
  609.                 break;
  610.         }
  611.         etape++;
  612.     }
  613.     stop();
  614.  
  615.     free_audio();
  616.  
  617.     if(adr_data!=0)FreeMem(adr_data,size);
  618.     if(lt)UnLock(lt);
  619.     if(fib)FreeMem(fib,sizeof(struct FileInfoBlock));
  620.     exec_safe(mt_end);
  621.     if(s)CloseScreen(s);
  622. }
  623.  
  624. void    proc_init()
  625. {
  626.         seed=VBeamPos();
  627.     AslBase=(struct Library *)OpenLibrary(AslName,0);
  628.     if(AslBase!=0){
  629.         my_req=AllocFileRequest();
  630.     }
  631.     GadToolsBase=(struct Library *)OpenLibrary("gadtools.library",0);
  632. }
  633. void    proc_save()
  634. {
  635. }
  636.  
  637. void    proc_end()
  638. {
  639.     if(AslBase)CloseLibrary(AslBase);
  640.     if(my_req!=0){
  641.             FreeFileRequest(my_req);
  642.     }
  643.     if(GadToolsBase)CloseLibrary(GadToolsBase);
  644. }
  645.  
  646.