home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !FALCON / NOCREW / MP2_0997.ZIP / mp2_0997 / src / decoder.tml < prev    next >
Text File  |  1999-07-12  |  2KB  |  123 lines

  1. /* decoder.c
  2.  *
  3.  * COPYRIGHT (c) 1998 by NoCrew Laboratories.
  4.  *
  5.  * MPEG audio layer 2 decoder.
  6.  */
  7.  
  8. #include <tos.h>
  9.  
  10. #include "dsp.h"
  11. #include "types.h"
  12. #include "stream.h"
  13. #include "snddefs.h"
  14.  
  15. static Byte decoder_program[] = {
  16. $ };
  17.  
  18. Int decoder_dsp_acknowledge(void);
  19. extern int replay;
  20.  
  21. /*
  22.  * Darn slow, but that's the way it
  23.  * is when we can't use supervisor mode.
  24.  */
  25.  
  26. static void dsp_send(Int x)
  27. {
  28.     Dsp_BlkUnpacked(&x, 1, 0, 0);
  29. }
  30.  
  31. static Int dsp_receive(void)
  32. {
  33.     Int r;
  34.     
  35.     Dsp_BlkUnpacked(0, 0, &r, 1);
  36.     return r&0x00800000L?r|0xff000000L:r;
  37. }
  38.  
  39. /*
  40.  * RPC (Remote Procedure Call) functions.
  41.  */
  42.  
  43. static void dsp_rpc(Int n)
  44. {
  45.     dsp_send(-(n+1));
  46. }
  47.  
  48. static Int dsp_frpc(Int n)
  49. {
  50.     if(decoder_dsp_acknowledge()) {
  51.         dsp_rpc(n);
  52.         return dsp_receive();
  53.     } else {
  54.         return 0;
  55.     }
  56. }
  57.  
  58. static Int dsp_rpc_timeout(Int n)
  59. {
  60.     return dsp_send_timeout(-(n+1));
  61. }
  62.  
  63. static Int dsp_frpc_timeout(Int n)
  64. {
  65.     return dsp_rpc_timeout(n)==1?dsp_receive_timeout():0x80000000L;
  66. }
  67.  
  68. void decoder_add_available(Int bytes)
  69. {
  70.     dsp_send(bytes/2);
  71. }
  72.  
  73. Int decoder_current_load(void)
  74. {
  75.     if(replay)
  76.         return dsp_frpc(7);
  77.     else
  78.         return 0;
  79. }
  80.  
  81. Int decoder_average_load(void)
  82. {
  83.     if(replay)
  84.         return dsp_frpc(8);
  85.     else
  86.         return 0;
  87. }
  88.  
  89. Int decoder_stream_available(void)
  90. {
  91.     return dsp_frpc(9)*2;
  92. }
  93.  
  94. Int decoder_dsp_acknowledge(void)
  95. {
  96.     return dsp_frpc_timeout(2) == 0x6d7032L;
  97. }
  98.  
  99. Int decoder_dma_acknowledge(void)
  100. {
  101.     Int r;
  102.     char s[] = { 0xff,0x4e,0x6f,0x43,0x72,0x65,0x77,
  103.                  0x20,0x72,0x75,0x6c,0x65,0x73,0x21 };
  104.     
  105.     buffoper(0);
  106.     for(r = 0; r < sizeof(s); r++)
  107.         ((char*) stream_get_buffer())[r] = s[r];
  108.     buffoper(SB_PLA_ENA | SB_PLA_RPT);
  109.     r = dsp_frpc_timeout(3) == 0x646d61L;
  110.     buffoper(0);
  111.     
  112.     return r;
  113. }
  114.  
  115. /*
  116.  * Load DSP MPEG audio layer 2 decoder.
  117.  */
  118.  
  119. Int decoder_load(void)
  120. {
  121.     return dsp_load_program(decoder_program, sizeof(decoder_program)/3);
  122. }
  123.