home *** CD-ROM | disk | FTP | other *** search
- #include <aes.h>
- #include <tos.h>
- #include <ext.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include "libshoe.h"
-
- #include "mp2ctrl.h"
- #include "mp2info.h"
-
- /* Function from mp2audio.c */
- extern void unix2dos(char *path);
-
- /* Functions from mp2event.c */
- extern void do_formstuff(int obj_id);
- extern int quit_program(void);
- extern void close_window(void);
- extern void switch_window(void);
- extern char *do_selectfile(char *);
- extern void do_play(void);
- extern void do_stop(void);
- extern void do_pause(void);
- extern void do_loop(void);
- extern void do_ff(void);
- extern void do_info(void);
- extern void do_shoe(void);
- extern void set_title(char *title);
- extern void set_subtitle(char *subtitle);
- extern long calc_time(void);
-
- /* Functions from mp2file.c */
- extern int load_file(char *file);
- extern int check_file(int tfd);
-
- /* Function from console.c */
- extern Byte *notify_console(char *msg);
- extern void print_line(char *text);
- extern void clear_console(void);
- extern void prompt_console(int, int);
-
- /* Global variable from mp2info.c */
- extern MP2INFO mp2info;
-
- /* Global variable from mp2audio.c */
- extern int replay, count_dir;
-
- /* Global variables from mp2file.c */
- extern char path[512], filename[512];
-
- /* Global variables from mp2event.c */
- extern int looping, replay_pause;
- extern int fgexit, display_time, file_open;
-
- Byte *bif_notify_gc(Byte *args)
- {
- return notify_console(TP(args)?"gc":""), args;
- }
-
- Byte *bif_panic(Byte *msg)
- {
- Byte panicmsg[1024];
-
- sprintf(panicmsg, "[1][%s][OK]", msg);
- form_alert(1, panicmsg);
- exit(1);
- return msg;
- }
-
- Byte *bif_date(Byte *args)
- {
- Byte *r;
- unsigned int y, m, d, t;
-
- args = args; /* Fool Pure C. */
- t = Tgetdate();
- y = (t >> 9) + 1980;
- m = (t >> 5) & 0xf;
- d = t & 0x1f;
- sprintf(r = mem(1+4+1+2+1+2+1+1), "(%d %d %d)", y, m, d);
- return r;
- }
-
- Byte *bif_time(Byte *args)
- {
- Byte *r;
- unsigned int h, m, s, t;
-
- args = args; /* Fool Pure C. */
- t = Tgettime();
- h = t >> 11;
- m = (t >> 5) & 0x3f;
- s = (t & 0x1f) * 2;
- sprintf(r = mem(1+2+1+2+1+2+1+1), "(%d %d %d)", h, m, s);
- return r;
- }
-
- Byte *bif_pwd(Byte *args)
- {
- args = args; /* Fool Pure C. */
- return memdup(path);
- }
-
- Byte *bif_cd(Byte *args)
- {
- char *s, old_dir[512];
- int old_drv;
-
- s = decode_string(EVAL(args));
-
- old_drv = Dgetdrv();
- Dgetpath(old_dir, 0);
-
- Dsetdrv((char)tolower((int)path[0])-'a');
- Dsetpath(path);
-
- if(strlen(s) >= 2 && s[1] == ':')
- Dsetdrv((char)tolower((int)s[0])-'a');
- Dsetpath(s);
-
- path[0] = 'A' + (char)Dgetdrv();
- path[1] = ':';
- Dgetpath(path+2, 0);
- strcat(path, "\\");
-
- Dsetdrv(old_drv);
- Dsetpath(old_dir);
-
- return bif_pwd("()");
- }
-
- Byte *bif_ls(Byte *args)
- {
- int regfile, err;
- char *r, *dir;
- DTA *pdta;
-
- args = decode_string(EVAL(args));
-
- pdta = Fgetdta();
- dir = memdup(path);
- mem(strlen(NILP(args)?"*.*":args)+1);
- strcat(dir,NILP(args)?"*.*":args);
- err = Fsfirst(dir, FA_SUBDIR | FA_HIDDEN | FA_SYSTEM);
-
- *(r = mem(2)) = '\0';
- strcat(r, "(");
- while(!err) {
- mem(strlen(pdta->d_fname)+1);
- strcat(r, pdta->d_fname);
- err = Fsnext();
- if(!err)
- strcat(r, " ");
- }
- strcat(r, ")");
-
- return r;
- }
-
- Byte *bif_load(Byte *args)
- {
- int fp;
- Byte *r;
- long fret, length;
-
- fret = Fopen(decode_string(EVAL(args)), FO_READ);
- if(fret < 0) return F;
-
- fp = (int)fret;
- length = filelength(fp);
- Fread(fp, length, r = mem(length+1));
- r[length] = '\0';
- Fclose(fp);
-
- parse_eval(r);
- return T;
- }
-
- Byte *bif_exit(Byte *args)
- {
- args = args; /* Fool Pure C. */
- return quit_program()?T:F;
- }
-
- Byte *bif_mp2_load(Byte *args)
- {
- int tfd;
- char *file;
-
- file = args = decode_string(EVAL(args));
- if(!strchr(args, '\\')) {
- file = memdup(path);
- mem(strlen(args));
- strcat(file, args);
- }
- if((tfd=load_file(file)) < 0 || check_file(tfd))
- return F;
- return T;
- }
-
- Byte *bif_mp2_play(Byte *args)
- {
- args = args; /* Fool Pure C. */
- do_play();
- return T;
- }
-
- Byte *bif_mp2_stop(Byte *args)
- {
- args = args; /* Fool Pure C. */
- do_stop();
- return T;
- }
-
- Byte *bif_mp2_pause(Byte *args)
- {
- args = args; /* Fool Pure C. */
- do_pause();
- return replay_pause?T:F;
- }
-
- Byte *bif_mp2_loop(Byte *args)
- {
- args = args; /* Fool Pure C. */
- do_loop();
- return looping?T:F;
- }
-
- Byte *bif_mp2_fast_forward(Byte *args)
- {
- args = args; /* Fool Pure C. */
- do_ff();
- return T;
- }
-
- Byte *bif_mp2_window_info(Byte *args)
- {
- args = args; /* Fool Pure C. */
- do_info();
- return T;
- }
-
- Byte *bif_mp2_window_console(Byte *args)
- {
- args = args; /* Fool Pure C. */
- do_shoe();
- return T;
- }
-
- Byte *bif_mp2_select(Byte *args)
- {
- return memdup(((args=do_selectfile(NILP(args)?
- "*.mp?":decode_string(EVAL(args))))!=0)?args:F);
- }
-
- Byte *bif_mp2_type(Byte *args)
- {
- Byte *s;
-
- args = args; /* Fool Pure C. */
- sprintf(s=mem(128),
- "((filename %s) "
- "(layer 2) (bitrate %ld) (frequency %ld) "
- "(filelength %ld) (timelength %ld))",
- filename,
- mp2info.bitrate, mp2info.sample_frequency,
- mp2info.filelength, mp2info.timelength);
-
- return s;
- }
-
- Byte *bif_mp2_loadedp(Byte *args)
- {
- args = args;
- return file_open?T:F;
- }
-
- Byte *bif_mp2_playp(Byte *args)
- {
- args = args; /* Fool Pure C. */
- return replay?T:F;
- }
-
- Byte *bif_mp2_pausep(Byte *args)
- {
- args = args; /* Fool Pure C. */
- return replay_pause?T:F;
- }
-
- Byte *bif_mp2_loopp(Byte *args)
- {
- args = args; /* Fool Pure C. */
- return looping?T:F;
- }
-
- Byte *bif_mp2_play_time(Byte *args)
- {
- Byte *buf;
-
- args = args; /* Fool Pure C. */
-
- buf = mem(16);
- sprintf(buf, "%ld", calc_time());
-
- return buf;
- }
-
- Byte *bif_print(Byte *args)
- {
- args = EVAL(args);
- print_line(decode_string(args));
- prompt_console(0, -1);
- return args;
- }
-
- Byte *bif_mp2_clear_console(Byte *args)
- {
- args = args;
- clear_console();
- return T;
- }
-
- Byte *bif_mp2_close_window(Byte *args)
- {
- args = args;
- close_window();
- return T;
- }
-
- Byte *bif_mp2_switch_window(Byte *args)
- {
- args = args;
- switch_window();
- return T;
- }
-
- Byte *bif_mp2_display_time(Byte *args)
- {
- if(NILP(args))
- return (display_time = !display_time)!=0?T:F;
- return (display_time = TP(EVAL(args)))!=0?T:F;
- }
-
- Byte *bif_mp2_countdown(Byte *args)
- {
- if(NILP(args))
- return (count_dir = !count_dir)!=0?T:F;
- return (count_dir = TP(EVAL(args)))!=0?T:F;
- }
-
- Byte *bif_mp2_title(Byte *args)
- {
- if(NILP(args))
- return set_title(""), memdup("");
- return set_title(decode_string(args = EVAL(args))), args;
- }
-
- Byte *bif_mp2_subtitle(Byte *args)
- {
- if(NILP(args))
- return set_subtitle(""), memdup("");
- return set_subtitle(decode_string(args = EVAL(args))), args;
- }
-
- void call_control_key(char c)
- {
- static char s[] = "(mp2-control-x)";
- s[sizeof(s)-3] = c;
- eval(s);
- }
-
- void load_bifs(void)
- {
- bif("notify-gc", bif_notify_gc);
- bif("panic", bif_panic);
- /* bif("error", bif_error); */
-
- bif("ls", bif_ls);
- bif("pwd", bif_pwd);
- bif("cd", bif_cd);
- bif("time", bif_time);
- bif("date", bif_date);
- bif("load", bif_load);
- bif("exit", bif_exit);
-
- bif("print", bif_print);
-
- bif("mp2-load", bif_mp2_load);
- bif("mp2-play", bif_mp2_play);
- bif("mp2-stop", bif_mp2_stop);
- bif("mp2-pause", bif_mp2_pause);
- bif("mp2-loop", bif_mp2_loop);
- bif("mp2-fast-forward", bif_mp2_fast_forward);
- bif("mp2-select", bif_mp2_select);
-
- bif("mp2-type", bif_mp2_type);
- bif("mp2-play-time", bif_mp2_play_time);
-
- bif("mp2-loaded?", bif_mp2_loadedp);
- bif("mp2-play?", bif_mp2_playp);
- bif("mp2-pause?", bif_mp2_pausep);
- bif("mp2-loop?", bif_mp2_loopp);
-
- bif("mp2-window-info", bif_mp2_window_info);
- bif("mp2-window-console", bif_mp2_window_console);
-
- bif("mp2-clear-console", bif_mp2_clear_console);
- bif("mp2-close-window", bif_mp2_close_window);
- bif("mp2-switch-window", bif_mp2_switch_window);
-
- bif("mp2-display-time", bif_mp2_display_time);
- bif("mp2-countdown", bif_mp2_countdown);
- bif("mp2-title", bif_mp2_title);
- bif("mp2-subtitle", bif_mp2_subtitle);
- }
-