home *** CD-ROM | disk | FTP | other *** search
/ M.u.C.S. Disc 2000 / MUCS2000.iso / sound / mp2_099 / src / gem / bifs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  8.1 KB  |  408 lines

  1.    #include <aes.h>
  2. #include <tos.h>
  3. #include <ext.h>
  4. #include <ctype.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #include "libshoe.h"
  10.  
  11. #include "mp2ctrl.h"
  12. #include "mp2info.h"
  13.  
  14. /* Function from mp2audio.c */
  15. extern void unix2dos(char *path);
  16.  
  17. /* Functions from mp2event.c */
  18. extern void do_formstuff(int obj_id);
  19. extern int quit_program(void);
  20. extern void close_window(void);
  21. extern void switch_window(void);
  22. extern char *do_selectfile(char *);
  23. extern void do_play(void);
  24. extern void do_stop(void);
  25. extern void do_pause(void);
  26. extern void do_loop(void);
  27. extern void do_ff(void);
  28. extern void do_info(void);
  29. extern void do_shoe(void);
  30. extern void set_title(char *title);
  31. extern void set_subtitle(char *subtitle);
  32. extern long calc_time(void);
  33.  
  34. /* Functions from mp2file.c */
  35. extern int load_file(char *file);
  36. extern int check_file(int tfd);
  37.  
  38. /* Function from console.c */
  39. extern Byte *notify_console(char *msg);
  40. extern void print_line(char *text);
  41. extern void clear_console(void);
  42. extern void prompt_console(int, int);
  43.  
  44. /* Global variable from mp2info.c */
  45. extern MP2INFO mp2info;
  46.  
  47. /* Global variable from mp2audio.c */
  48. extern int replay, count_dir;
  49.  
  50. /* Global variables from mp2file.c */
  51. extern char path[512], filename[512];
  52.  
  53. /* Global variables from mp2event.c */
  54. extern int looping, replay_pause;
  55. extern int fgexit, display_time, file_open;
  56.  
  57. Byte *bif_notify_gc(Byte *args)
  58. {
  59.     return notify_console(TP(args)?"gc":""), args;
  60. }
  61.  
  62. Byte *bif_panic(Byte *msg)
  63. {
  64.     Byte panicmsg[1024];
  65.  
  66.     sprintf(panicmsg, "[1][%s][OK]", msg);
  67.     form_alert(1, panicmsg);
  68.     exit(1);
  69.     return msg;
  70. }
  71.  
  72. Byte *bif_date(Byte *args)
  73. {
  74.     Byte *r;
  75.     unsigned int y, m, d, t;
  76.     
  77.     args = args;        /* Fool Pure C. */    
  78.     t = Tgetdate();
  79.     y = (t >> 9) + 1980;
  80.     m = (t >> 5) & 0xf;
  81.     d = t & 0x1f;
  82.     sprintf(r = mem(1+4+1+2+1+2+1+1), "(%d %d %d)", y, m, d);
  83.     return r;
  84. }
  85.  
  86. Byte *bif_time(Byte *args)
  87. {
  88.     Byte *r;
  89.     unsigned int h, m, s, t;
  90.     
  91.     args = args;        /* Fool Pure C. */    
  92.     t = Tgettime();
  93.     h = t >> 11;
  94.     m = (t >> 5) & 0x3f;
  95.     s = (t & 0x1f) * 2;
  96.     sprintf(r = mem(1+2+1+2+1+2+1+1), "(%d %d %d)", h, m, s);
  97.     return r;
  98. }
  99.  
  100. Byte *bif_pwd(Byte *args)
  101. {
  102.     args = args;        /* Fool Pure C. */    
  103.     return memdup(path);
  104. }
  105.  
  106. Byte *bif_cd(Byte *args)
  107. {
  108.     char *s, old_dir[512];
  109.     int old_drv;
  110.     
  111.     s = decode_string(EVAL(args));
  112.  
  113.     old_drv = Dgetdrv();
  114.     Dgetpath(old_dir, 0);
  115.  
  116.     Dsetdrv((char)tolower((int)path[0])-'a');
  117.     Dsetpath(path);
  118.     
  119.     if(strlen(s) >= 2 && s[1] == ':')
  120.         Dsetdrv((char)tolower((int)s[0])-'a');
  121.     Dsetpath(s);
  122.     
  123.     path[0] = 'A' + (char)Dgetdrv();
  124.     path[1] = ':';
  125.     Dgetpath(path+2, 0);
  126.     strcat(path, "\\");
  127.     
  128.     Dsetdrv(old_drv);
  129.     Dsetpath(old_dir);
  130.  
  131.     return bif_pwd("()");
  132. }
  133.  
  134. Byte *bif_ls(Byte *args)
  135. {
  136.     int regfile, err;
  137.     char *r, *dir;
  138.     DTA *pdta;
  139.     
  140.     args = decode_string(EVAL(args));
  141.  
  142.     pdta = Fgetdta();
  143.     dir = memdup(path);
  144.     mem(strlen(NILP(args)?"*.*":args)+1);
  145.     strcat(dir,NILP(args)?"*.*":args);
  146.     err = Fsfirst(dir, FA_SUBDIR | FA_HIDDEN | FA_SYSTEM);
  147.     
  148.     *(r = mem(2)) = '\0';
  149.     strcat(r, "(");
  150.     while(!err) {
  151.         mem(strlen(pdta->d_fname)+1);
  152.         strcat(r, pdta->d_fname);
  153.         err = Fsnext();
  154.         if(!err)
  155.             strcat(r, " ");
  156.     }
  157.     strcat(r, ")");
  158.  
  159.     return r;
  160. }
  161.  
  162. Byte *bif_load(Byte *args)
  163. {
  164.     int fp;
  165.     Byte *r;
  166.     long fret, length;
  167.  
  168.     fret = Fopen(decode_string(EVAL(args)), FO_READ);
  169.     if(fret < 0) return F;
  170.  
  171.     fp = (int)fret;
  172.     length = filelength(fp);
  173.     Fread(fp, length, r = mem(length+1));
  174.     r[length] = '\0';
  175.     Fclose(fp);
  176.  
  177.     parse_eval(r);
  178.     return T;
  179. }
  180.  
  181. Byte *bif_exit(Byte *args)
  182. {
  183.     args = args;        /* Fool Pure C. */    
  184.     return quit_program()?T:F;
  185. }
  186.  
  187. Byte *bif_mp2_load(Byte *args)
  188. {
  189.     int tfd;
  190.     char *file;
  191.  
  192.     file = args = decode_string(EVAL(args));
  193.     if(!strchr(args, '\\')) {
  194.         file = memdup(path);
  195.         mem(strlen(args));
  196.         strcat(file, args);
  197.     }
  198.     if((tfd=load_file(file)) < 0 || check_file(tfd))
  199.         return F;
  200.     return T;
  201. }
  202.  
  203. Byte *bif_mp2_play(Byte *args)
  204. {
  205.     args = args;        /* Fool Pure C. */    
  206.     do_play();
  207.     return T;
  208. }
  209.  
  210. Byte *bif_mp2_stop(Byte *args)
  211. {
  212.     args = args;        /* Fool Pure C. */    
  213.     do_stop();
  214.     return T;
  215. }
  216.  
  217. Byte *bif_mp2_pause(Byte *args)
  218. {
  219.     args = args;        /* Fool Pure C. */    
  220.     do_pause();
  221.     return replay_pause?T:F;
  222. }
  223.  
  224. Byte *bif_mp2_loop(Byte *args)
  225. {
  226.     args = args;        /* Fool Pure C. */    
  227.     do_loop();
  228.     return looping?T:F;
  229. }
  230.  
  231. Byte *bif_mp2_fast_forward(Byte *args)
  232. {
  233.     args = args;        /* Fool Pure C. */    
  234.     do_ff();
  235.     return T;
  236. }
  237.  
  238. Byte *bif_mp2_window_info(Byte *args)
  239. {
  240.     args = args;        /* Fool Pure C. */    
  241.     do_info();
  242.     return T;
  243. }
  244.  
  245. Byte *bif_mp2_window_console(Byte *args)
  246. {
  247.     args = args;        /* Fool Pure C. */    
  248.     do_shoe();
  249.     return T;
  250. }
  251.  
  252. Byte *bif_mp2_select(Byte *args)
  253. {
  254.     return memdup(((args=do_selectfile(NILP(args)?
  255.            "*.mp?":decode_string(EVAL(args))))!=0)?args:F);
  256. }
  257.  
  258. Byte *bif_mp2_type(Byte *args)
  259. {
  260.     Byte *s;
  261.  
  262.     args = args;        /* Fool Pure C. */    
  263.     sprintf(s=mem(128),
  264.         "((filename %s) "
  265.         "(layer 2) (bitrate %ld) (frequency %ld) "
  266.         "(filelength %ld) (timelength %ld))",
  267.         filename,
  268.         mp2info.bitrate, mp2info.sample_frequency,
  269.         mp2info.filelength, mp2info.timelength);
  270.  
  271.     return s;
  272. }
  273.  
  274. Byte *bif_mp2_loadedp(Byte *args)
  275. {
  276.     args = args;
  277.     return file_open?T:F;
  278. }
  279.  
  280. Byte *bif_mp2_playp(Byte *args)
  281. {
  282.     args = args;        /* Fool Pure C. */    
  283.     return replay?T:F;
  284. }
  285.  
  286. Byte *bif_mp2_pausep(Byte *args)
  287. {
  288.     args = args;        /* Fool Pure C. */    
  289.     return replay_pause?T:F;
  290. }
  291.  
  292. Byte *bif_mp2_loopp(Byte *args)
  293. {
  294.     args = args;        /* Fool Pure C. */    
  295.     return looping?T:F;
  296. }
  297.  
  298. Byte *bif_mp2_play_time(Byte *args)
  299. {
  300.     Byte *buf;
  301.  
  302.     args = args;        /* Fool Pure C. */    
  303.  
  304.     buf = mem(16);
  305.     sprintf(buf, "%ld", calc_time());
  306.     
  307.     return buf;
  308. }
  309.  
  310. Byte *bif_print(Byte *args)
  311. {
  312.     args = EVAL(args);
  313.     print_line(decode_string(args));
  314.     prompt_console(0, -1);
  315.     return args;
  316. }
  317.  
  318. Byte *bif_mp2_clear_console(Byte *args)
  319. {
  320.     args = args;
  321.     clear_console();
  322.     return T;
  323. }
  324.  
  325. Byte *bif_mp2_close_window(Byte *args)
  326. {
  327.     args = args;
  328.     close_window();
  329.     return T;
  330. }
  331.  
  332. Byte *bif_mp2_switch_window(Byte *args)
  333. {
  334.     args = args;
  335.     switch_window();
  336.     return T;
  337. }
  338.  
  339. Byte *bif_mp2_display_time(Byte *args)
  340. {
  341.     if(NILP(args))
  342.         return (display_time = !display_time)!=0?T:F;
  343.     return (display_time = TP(EVAL(args)))!=0?T:F;
  344. }
  345.  
  346. Byte *bif_mp2_countdown(Byte *args)
  347. {
  348.     if(NILP(args))
  349.         return (count_dir = !count_dir)!=0?T:F;
  350.     return (count_dir = TP(EVAL(args)))!=0?T:F;
  351. }
  352.  
  353. Byte *bif_mp2_title(Byte *args)
  354. {
  355.     if(NILP(args))
  356.         return set_title(""), memdup("");
  357.     return set_title(decode_string(args = EVAL(args))), args;
  358. }
  359.  
  360. Byte *bif_mp2_subtitle(Byte *args)
  361. {
  362.     if(NILP(args))
  363.         return set_subtitle(""), memdup("");
  364.     return set_subtitle(decode_string(args = EVAL(args))), args;
  365. }
  366.  
  367. void call_control_key(char c)
  368. {
  369.     static char s[] = "(mp2-control-x)";
  370.     s[sizeof(s)-3] = c;
  371.     eval(s);
  372. }
  373.  
  374. void load_bifs(void)
  375. {
  376.     bif("notify-gc",  bif_notify_gc);
  377.     bif("panic",      bif_panic);
  378.     /* bif("error", bif_error); */
  379.  
  380.     bif("ls",         bif_ls);
  381.     bif("pwd",        bif_pwd);
  382.     bif("cd",         bif_cd);
  383.     bif("time",       bif_time);
  384.     bif("date",       bif_date);
  385.     bif("load",       bif_load);
  386.     bif("exit",       bif_exit);
  387.  
  388.     bif("print",      bif_print);
  389.  
  390.     bif("mp2-load",         bif_mp2_load);
  391.     bif("mp2-play",         bif_mp2_play);
  392.     bif("mp2-stop",         bif_mp2_stop);
  393.     bif("mp2-pause",        bif_mp2_pause);
  394.     bif("mp2-loop",         bif_mp2_loop);
  395.     bif("mp2-fast-forward", bif_mp2_fast_forward);
  396.     bif("mp2-select",       bif_mp2_select);
  397.  
  398.     bif("mp2-type",         bif_mp2_type);
  399.     bif("mp2-play-time",    bif_mp2_play_time);
  400.  
  401.     bif("mp2-loaded?",  bif_mp2_loadedp);
  402.     bif("mp2-play?",    bif_mp2_playp);
  403.     bif("mp2-pause?",   bif_mp2_pausep);
  404.     bif("mp2-loop?",    bif_mp2_loopp);
  405.  
  406.     bif("mp2-window-info",    bif_mp2_window_info);
  407.     bif("mp2-window-console", bif_mp2_window_console);
  408.  
  409.     bif("mp2-clear-console",  bif_mp2_clear_console);
  410.     bif("mp2-close-window",   bif_mp2_close_window);
  411.     bif("mp2-switch-window",  bif_mp2_switch_window);
  412.  
  413.     bif("mp2-display-time", bif_mp2_display_time);
  414.     bif("mp2-countdown",    bif_mp2_countdown);
  415.     bif("mp2-title",        bif_mp2_title);
  416.     bif("mp2-subtitle",     bif_mp2_subtitle);
  417. }
  418.