home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !FALCON / NOCREW / MP2_0997.ZIP / mp2_0997 / src / main.c < prev    next >
C/C++ Source or Header  |  1999-08-01  |  5KB  |  227 lines

  1. /* MPEG Audio layer 2 decoder. */
  2.  
  3. #include <tos.h>
  4. #include <vdi.h>
  5. #include <aes.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10.  
  11. #include "version.h"
  12. #include "mp2audio.h"
  13. #include "mp2info.h"
  14. #include "configs.h"
  15.  
  16. #include "mp2ctrl.rsh"    /* rsc file */
  17. #include "mp2ctrl.rh"
  18. #include "window.h"
  19.  
  20. #include "libshoe.h"
  21. #include "stream.h"
  22. #include "replay.h"
  23.  
  24. /* global variables */
  25. int time_slice=DEFAULT_TIME_SLICE,count_dir=DEFAULT_COUNT_DIR;
  26. int replay = 0, quit;
  27. int app_id, acc_id, vdi_id;
  28. int dom;
  29. WINDFORM windforms[5];
  30. WINDHANDLELIST *windhandles = NULL;
  31.  
  32. extern int _app;
  33.  
  34. /* global variables from mp2file.c */
  35. extern char path[512];
  36.  
  37. /* Function in this module. */
  38. static void setup_rsrc(int nbpl);
  39. extern void unix2dos(char *);
  40.  
  41. /* Functions from mp2event.c */
  42. extern void main_event_loop(void);
  43. extern void unquote(char *);
  44.  
  45. /* Function from bifs.c */
  46. extern void load_bifs(void);
  47.  
  48. #pragma warn -par
  49. int main(int argc, char *argv[])
  50. {
  51.     int wchar,hchar,wbar,hbar;
  52.     int work_in[11] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 };
  53.     int work_out[57];
  54.     int tmp_id, button;
  55.  
  56.     if(_app) {
  57.         int sndlocked, dsplocked;
  58.         
  59.         sndlocked = locksnd()!=1?1:0;
  60.         dsplocked = Dsp_Lock()!=0?1:0;
  61.         
  62.         if(sndlocked && dsplocked) {
  63.             button = form_alert(1,"[1][The audio subsystem|and the DSP "
  64.                                   "are already in use!]"
  65.                                   "[ Quit | Force ]");
  66.             if(button == 1)
  67.                 return -129;
  68.             unlocksnd();
  69.             locksnd();
  70.             Dsp_Unlock();
  71.             Dsp_Lock();            
  72.         } else if(dsplocked) {
  73.             button = form_alert(1,"[1][The DSP is already in use!]"
  74.                                          "[ Quit | Force ]");
  75.             if(button == 1)
  76.                 return -130;
  77.             Dsp_Unlock();
  78.             Dsp_Lock();
  79.         } else if(sndlocked) {
  80.             button = form_alert(1,"[1][The audio subsystem|"
  81.                                          "is already in use!]"
  82.                                          "[ Quit | Force ]");
  83.             if(button == 1)
  84.                 return -131;
  85.             unlocksnd();
  86.             locksnd();
  87.         }
  88.     }
  89.  
  90.     dom = (Pdomain(1) == 0) ? 1 : 0;
  91.  
  92.     /* Default path is current. */
  93.     path[0] = 'A' + (char)Dgetdrv();
  94.     path[1] = ':';
  95.     Dgetpath(path+2, 0);
  96.     strcat(path, "\\");
  97.  
  98.     if((app_id = appl_init()) >= 0) {
  99.     /* Run external clock detection. */
  100.         external_clock();
  101.  
  102.         stream_set_buffer(DEFAULT_BLOCK_SIZE*1024L);
  103.         if(!stream_get_buffer()) {
  104.             form_alert(1,"[1][Not enough memory!][OK]");
  105.             appl_exit();
  106.             return 1;
  107.         }
  108.         
  109.         if(!_app || _GemParBlk.global[0] >= 0x0400)
  110.             tmp_id = menu_register(app_id, "  MP2 Audio ");
  111.         if(!_app)
  112.             acc_id = tmp_id;        
  113.         
  114.         work_in[0]=vdi_id=graf_handle(&wchar,&hchar,&wbar,&hbar);
  115.         v_opnvwk(work_in,&vdi_id,work_out);
  116.         if(vdi_id > 0) {
  117.             vq_extnd(vdi_id,1,work_out);
  118.             setup_rsrc(work_out[4]);
  119.             
  120.             /* Load application specific Shoe bifs. */
  121.             load_bifs();
  122.             
  123.             /* Load Shoe bootstrap code. */
  124.             parse_eval("(load \"mp2audio.sho\")");
  125.             
  126.             if(_app) {
  127.                 window_create(WIND_CTRL);
  128.                 graf_mouse(ARROW,NULL);
  129.  
  130.                 if(argc > 1) {
  131.                     char tmp[1024];
  132.  
  133.                     strcpy(tmp, "(mp2-hook-dragumdroppum \"");
  134.                     unquote(argv[1]);
  135.                     strcat(tmp, argv[1]);
  136.                     strcat(tmp, "\")");
  137.                     parse_eval(tmp);
  138.                 }
  139.  
  140.                 main_event_loop();
  141.                 replay_stop();
  142.     
  143.                 v_clsvwk(vdi_id);
  144.             } else if (acc_id >= 0)
  145.                 main_event_loop();
  146.         }
  147.  
  148.         /* This restores at least the keyclick.        */
  149.         soundcmd(4,1);        /* Set Adder-In -> Matrix. */
  150.         soundcmd(5,3);        /* ADC input -> PSG.       */
  151.         soundcmd(6,3);        /* STE prescaler 160.      */
  152.  
  153.         appl_exit();
  154.         
  155.         stream_close();
  156.         stream_free_buffer();
  157.     }
  158.  
  159.     Dsp_Unlock();
  160.     unlocksnd();
  161.     return 0;
  162. }
  163. #pragma warn .par
  164.  
  165. /* Initialize resource structures. */
  166. static void setup_rsrc(int nbpl)
  167. {
  168.     int ob;
  169.     char ver[64];
  170.     
  171.     for(ob = 0; ob < NUM_OBS; ob++)
  172.         rsrc_obfix(rs_object,ob);
  173.  
  174.     switch(nbpl) {
  175.         case 1:
  176.         case 2:
  177.             windforms[WIND_CTRL].formtree=rs_trindex[FORM_CTRL1];
  178.             windforms[WIND_INFO].formtree=rs_trindex[FORM_INFO1];
  179.             windforms[WIND_SHOE].formtree=rs_trindex[FORM_SHOE];
  180.             break;
  181.         case 4:
  182.         default:
  183.             windforms[WIND_CTRL].formtree=rs_trindex[FORM_CTRL4];
  184.             windforms[WIND_INFO].formtree=rs_trindex[FORM_INFO4];
  185.             windforms[WIND_SHOE].formtree=rs_trindex[FORM_SHOE];
  186.     }
  187.  
  188.     strcpy(windforms[WIND_CTRL].wind_title,"");
  189.     strcpy(windforms[WIND_INFO].wind_title,"Info");
  190.     strcpy(windforms[WIND_SHOE].wind_title,"      Shoe Console      ");
  191.     strcpy(ver,"Version ");
  192.     strcat(ver,VERSION_TEXT);
  193.     strcpy(windforms[WIND_INFO].formtree[INFO_VERSION].ob_spec.tedinfo->te_ptext,ver);
  194.     windforms[WIND_CTRL].windkind=(MOVER | CLOSER | NAME);
  195.     windforms[WIND_INFO].windkind=(MOVER | CLOSER | NAME);
  196.     windforms[WIND_SHOE].windkind=(MOVER | CLOSER | NAME);
  197.     windforms[WIND_CTRL].firstobj=CTRL_FIRST;
  198.     windforms[WIND_INFO].firstobj=INFO_FIRST;
  199.     windforms[WIND_SHOE].firstobj=SHOE_FIRST;
  200.     windforms[WIND_CTRL].objdepth=2;
  201.     windforms[WIND_INFO].objdepth=1;
  202.     windforms[WIND_SHOE].objdepth=0;
  203.     windforms[WIND_CTRL].has_opened=0;
  204.     windforms[WIND_INFO].has_opened=0;
  205.     windforms[WIND_SHOE].has_opened=0;
  206. }
  207.  
  208. /* Convert filenames from unix to ST format. */
  209. void unix2dos(char *path)
  210. {
  211.     int i = 0;
  212.     char tmp[512];
  213.  
  214.     if(path[0] == '/') {
  215.         strcpy(tmp,&path[1]);
  216.         strcpy(path,"U:\\");
  217.         strcat(path,tmp);
  218.         while(path[i]) {
  219.             if(path[i] == '/')
  220.                 path[i] = '\\';
  221.             i++;
  222.         }
  223.     }
  224.     if(path[strlen(path)-1] != '\\')
  225.         path[strlen(path)-1] = '\\';
  226. }
  227.