home *** CD-ROM | disk | FTP | other *** search
/ Bila Vrana / BILA_VRANA.iso / 031A / KARDP17.ZIP / KARAFM.C < prev    next >
C/C++ Source or Header  |  1995-06-17  |  6KB  |  314 lines

  1. /*
  2.      KARAOKE
  3.  
  4.      Copyright (c) 1993 94 JP COCATRIX . All rights reserved.
  5. */
  6. /*  This is the interface module used in karados
  7.         given as an explaination of how the resident code like Ultramid
  8.         is used.
  9.         These primitives are called only if the output mode is s (-po=s)
  10.         I Hope it is self documented.
  11.         If loading a patches is no meaning for you, just ignore in the TSR
  12.         The APP_START and APP_END is only a protection for multiple users
  13.         to avoid the remove of the TSR if a program is still using it.
  14.         The key for detection for an other TSR than ULTRAMID
  15.         is "KARADOS".
  16. */
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <dos.h>
  20. #include "ultramid.h"
  21.  
  22. #define MK_LONG   (long)((void _seg *)(_DX) + (void near *)(_AX))
  23.  
  24. #define control_change              0xB0
  25. #define after_touch                                0xD0
  26.  
  27. #define TRUE    1            /* Define some handy constants    */
  28. #define FALSE    0            /* Define some handy constants    */
  29.  
  30. extern enum HARD {RIEN,SB,GUS,MPU401,COM1,COM2,COM3,COM4} hardware;
  31. extern void SaySo(char *texte,int multiple);
  32. extern short inrange(unsigned char,unsigned char min,unsigned char max);
  33. extern const char *getInstrument(unsigned char);
  34. extern void info_system(char *txt,short x);
  35. extern volatile    unsigned int tempo;
  36. extern void check_buffers(void);
  37. void    sbFmSound3(int,int,int );
  38. //*******************************************************************
  39. //                 code Synth. output
  40. //*******************************************************************
  41.  
  42. int (far *um_hook)(void) = 0L;
  43.  
  44.  
  45. void    um_parameter( int channel, int control, int value )
  46. {
  47.     sbFmSound3( (control_change+channel),control,value );
  48. }
  49.  
  50. int    loadpatch( int patch )
  51. {
  52.     char strg[80];
  53.   unsigned i;
  54.     if (um_hook)
  55.     {
  56.     check_buffers(); // for wave see karawav
  57.         if (patch <128)
  58.         sprintf(strg,"Loading %s",getInstrument(patch));
  59.         else
  60.         {
  61.             if (!inrange(patch,128+27,128+87)) return (TRUE);
  62.             sprintf(strg,"Loading drum %d",patch-128);
  63.         }
  64.         SaySo(strg,6);
  65.     i=0;
  66.     if (um_hook)
  67.     do
  68.     {
  69.           _AX = TSR_LOAD_PATCH;
  70.           _CX = patch;
  71.       i++;
  72.         }while (((*um_hook)()!=0)&&(i<2));
  73.  
  74.     if (i==2)
  75.     {
  76.       SaySo("TSR Loading Error",7);
  77.       return (FALSE);
  78.     }
  79.     return (TRUE);
  80.     } return (FALSE);
  81. }
  82.  
  83. /*
  84. int    unloadpatch( int patch )
  85. {
  86.     char strg[80];
  87.   unsigned i;
  88.     if (um_hook)
  89.     {
  90.     check_buffers(); // for wave see karawav
  91.     i=0;
  92.     if (um_hook)
  93.     do
  94.     {
  95.           _AX = TSR_UNLOAD_PATCH;
  96.           _CX = patch;
  97.       i++;
  98.         }while (((*um_hook)()!=0)&&(i<2));
  99.  
  100.     if (i==2)
  101.     {
  102.       return (FALSE);
  103.     }
  104.     return (TRUE);
  105.     } return (FALSE);
  106. }
  107. */
  108.  
  109. int    reset_um( )
  110. {
  111.     int i;
  112.  
  113.     _AX = TSR_UNLOAD_ALL_PATCHES;
  114.     if (um_hook)(*um_hook)();
  115.     _AX = TSR_ALL_NOTES_OFF;
  116.     if (um_hook) (*um_hook)();
  117.     for (i=0; i < 16; i++) {
  118.         um_parameter(i, 0x78, 0); /* all sounds off */
  119.         um_parameter(i, 0x79, 0); /* reset all controllers */
  120.         um_parameter(i, 100, 0); /* RPN MSB 0 */
  121.         um_parameter(i, 101, 0); /* RPN LSB 0 */
  122.         um_parameter(i, 6, 2); /* Pitch Bend Sensitivity MSB */
  123.         um_parameter(i, 38, 0); /* Pitch Bend Sensitivity LSB */
  124.     }
  125.     return(1);
  126. }
  127.  
  128. void    um_cleanup( void )
  129. {
  130.     if (um_hook)
  131.     {
  132.         SaySo("Unload Patches",6);
  133.         _AX = TSR_UNLOAD_ALL_PATCHES;
  134.         if (um_hook)(*um_hook)();
  135.         reset_um();
  136.         _AX = TSR_APP_END;
  137.         if (um_hook)(*um_hook)();
  138.     }
  139. }
  140.  
  141.  
  142. //***********************************************************************
  143. //                code commun   common code
  144. //***********************************************************************
  145. // name with FM are for historical reasons !!
  146. #pragma warn -par
  147. int    initfm()
  148. {
  149.     int vector, i;
  150.     char far *stamp;
  151.     switch (hardware)
  152.     {
  153.     case GUS:
  154.     case SB:
  155.   case MPU401:
  156.   case COM1:
  157.   case COM2:
  158.   case COM3:
  159.   case COM4:
  160.         for (vector=0x78; vector <= 0x7f; vector++)
  161.         {
  162.             um_hook = (int (far *)())getvect(vector);
  163.             stamp = (char far *)MK_FP( FP_SEG(um_hook), 0x103 );
  164.             if ((strncmp(stamp, "ULTRAMID", 8) == 0)||(strncmp(stamp, "KARADOS", 7) == 0))
  165.                  break;
  166.             stamp = (char far *)MK_FP( FP_SEG(um_hook), FP_OFF(um_hook)+0x04 );
  167.             if ((strncmp(stamp, "ULTRAMID", 8) == 0)||(strncmp(stamp, "KARADOS", 7) == 0))
  168.                  break;
  169.         }
  170.         if (vector <= 0x7f) {
  171.             if (um_hook)
  172.             {
  173.                 _AX = TSR_APP_START;
  174.                 (*um_hook)();
  175.                 reset_um();
  176.             }
  177.         } else
  178.         {
  179.             um_hook = 0L;
  180.       tempo =0x3F;
  181.       info_system(" No synth found.",20);
  182.             return(1);
  183.         }
  184.         return(0);
  185.     case RIEN :
  186.     default:
  187.       tempo =0x3F;
  188.       info_system(" No hard. Sorry.",20);
  189.         return (1);
  190.     }
  191. }
  192. #pragma warn .par
  193.  
  194.  
  195. void    sbFmSound2(int car1, int car2)
  196. {
  197.     if (um_hook)
  198.     {
  199.             _AX = TSR_MIDI_OUT;
  200.             _CX = car1;
  201.             (*um_hook)();
  202.             _AX = TSR_MIDI_OUT;
  203.             _CX = car2;
  204.             (*um_hook)();
  205.   }
  206. }
  207.  
  208. void    sbFmSound3(int car1, int car2, int car3)
  209. {
  210.     if (um_hook)
  211.     {
  212.             _AX = TSR_MIDI_OUT;
  213.             _CX = car1;
  214.             (*um_hook)();
  215.             _AX = TSR_MIDI_OUT;
  216.             _CX = car2;
  217.             (*um_hook)();
  218.             _AX = TSR_MIDI_OUT;
  219.             _CX = car3;
  220.             (*um_hook)();
  221.   }
  222. }
  223.  
  224. int um_start_digital(struct um_sound_struct *umss)
  225. {
  226.     if (um_hook)
  227.     {
  228.         _ES = FP_SEG(umss);
  229.         _DI = FP_OFF(umss);
  230.         _AX = TSR_START_DIGITAL;
  231.         (*um_hook)();
  232.         return(_AX);
  233.   }
  234.   return 0;
  235. }
  236.  
  237. void um_stop_digital(int voice)
  238. {
  239.     if (um_hook)
  240.     {
  241.         _CX = voice;
  242.         _AX = TSR_STOP_DIGITAL;
  243.         (*um_hook)();
  244.   }
  245. }
  246.  
  247. void um_restart_digital(int voice)
  248. {
  249.     if (um_hook)
  250.     {
  251.         _CX = voice;
  252.         _AX = TSR_RESTART_DIGITAL;
  253.         (*um_hook)();
  254.   }
  255. }
  256.  
  257. void um_pause_digital(int voice)
  258. {
  259.     if (um_hook)
  260.     {
  261.         _CX = voice;
  262.         _AX = TSR_PAUSE_DIGITAL;
  263.         (*um_hook)();
  264.   }
  265. }
  266.  
  267. void um_set_pan(int voice, int pan)
  268. {
  269.     if (um_hook)
  270.     {
  271.         _CX = voice;
  272.         _BX = pan;
  273.         _AX = TSR_SET_PAN;
  274.         (*um_hook)();
  275.   }
  276. }
  277.  
  278. void um_set_volume(int voice, int volume)
  279. {
  280.     if (um_hook)
  281.     {
  282.         _CX = voice;
  283.         _BX = volume;
  284.         _AX = TSR_SET_VOLUME;
  285.         (*um_hook)();
  286.   }
  287. }
  288.  
  289. long um_allocate_memory(long mem)
  290. {
  291.     if (um_hook)
  292.     {
  293.         asm mov dx, word ptr mem;
  294.         asm mov bx, word ptr mem+2;
  295.         _AX = TSR_ALLOCATE_MEMORY;
  296.         (*um_hook)();
  297.         mem = MK_LONG;
  298.         return(mem);
  299.   }
  300.   return (0);
  301. }
  302.  
  303. void um_free_memory(long mem)
  304. {
  305.     if (um_hook)
  306.     {
  307.         asm mov bx, word ptr mem+2;
  308.         asm mov dx, word ptr mem;
  309.         _AX = TSR_FREE_MEMORY;
  310.         (*um_hook)();
  311.   }
  312. }
  313.  
  314.