home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 3 / FreeSoftwareCollection3pd199x-jp.img / pao / ms_dos / cdplay / src / cdr.c < prev    next >
Text File  |  1980-01-02  |  8KB  |  276 lines

  1. /******************************************************************************
  2. **
  3. **        CDR.LIB << MSC V5.1 >>
  4. **
  5. **        ※コンパイル時に /Zp オプションを必ずつけること!
  6. **
  7. **        ただ単純にMS-DOSでCDを聴きたいためだけに作ったので
  8. **        最低限必要な機能しかありません。しかも、C言語で作成してあるのです。
  9. **        きまぐれで作ったので・・・・そのうちアセンブラで作りたいなぁ・・・・!
  10. **
  11. **        <HISTORY>
  12. **        1990.02.21 : CREATE
  13. **        1990.05.12 : リピート回数のバグ修正。
  14. **        1990.06.29 : CDR_continue()の追加。
  15. **
  16. **        Programed by Y.HIRATA Nifty-ID (NAB03321)
  17. **
  18. ******************************************************************************/
  19.  
  20. #include    <stdio.h>
  21. #include    <stdlib.h>
  22. #include    <string.h>
  23. #include    <dos.h>
  24. #include    <conio.h>
  25. #include    "cdr.h"
  26.  
  27. #define    CDR_INT    0x93
  28.  
  29. union    REGS    regs, regs ;
  30. struct    SREGS    sregs ;
  31.  
  32. typedef struct _TRACK_INF {
  33.     unsigned char    min ;
  34.     unsigned char    sec ;
  35.     unsigned char    frame ;
  36. } TRACK_INF ;
  37.  
  38. typedef struct _TOC {
  39.     unsigned char    cdtype;
  40.     unsigned char    sttrack;
  41.     unsigned char    endtrack;
  42.     TRACK_INF    disc ;
  43.     TRACK_INF    track[99] ;    
  44. } TOC ;
  45.  
  46. /******************************************************************************
  47.     CDR_cdinfo
  48. ******************************************************************************/
  49. int CDR_cdinfo( deviceno, cdtype, starttrack, endtrack, tracktime, disktime )
  50. int        deviceno ;            /* デバイス番号                */
  51. int        *cdtype ;            /* コンパクトディスクタイプ    */
  52. int        *starttrack ;        /* 先頭トラック(曲)番号        */
  53. int        *endtrack ;            /* 最終トラック(曲)番号        */
  54. char    *tracktime ;        /* トラック内演奏時間        */
  55. char    *disktime ;            /* ディスク内演奏時間        */
  56. {
  57.     TOC    toc ;
  58.     int        ret ;
  59.  
  60.     regs.h.ah = 0x54 ;
  61.     deviceno |= 0xc0 ;
  62.     regs.h.al = deviceno ;
  63.     regs.x.cx = 0;
  64.     regs.x.di = (unsigned int)&toc ;
  65.  
  66.     segread( &sregs ) ;
  67.     int86x( CDR_INT,®s,®s,&sregs ) ;
  68.     ret = 0 ;                                /* 正常終了            */
  69.     if ( regs.h.ah == 0x02 )                /* デバイス番号誤り */
  70.         ret = DEVERR ;
  71.     else if ( regs.h.ah == 0x10 )            /* 音楽演奏中        */
  72.         ret = DEVPLY ;
  73.     else if ( regs.h.ah == 0x80 )            /* ハードエラー        */
  74.         ret = regs.x.cx ;
  75.  
  76.     *cdtype = toc.cdtype ;
  77.     *starttrack = toc.sttrack ;
  78.     *endtrack = toc.endtrack ;
  79.     memcpy( tracktime,(char *)toc.track,99*3 ) ;
  80.     memcpy( disktime,(char *)&toc.disc,3 ) ;
  81.  
  82.     return ( ret ) ;
  83. }
  84.  
  85. /******************************************************************************
  86.     CDR_mtplay
  87. ******************************************************************************/
  88. int CDR_mtplay( deviceno, starttime, endtime )
  89. int        deviceno ;            /* デバイス番号                */
  90. char    *starttime ;        /* 演奏開始時間                */
  91. char    *endtime ;            /* 演奏終了時間                */
  92. {
  93.     TRACK_INF    track_inf[2] ;
  94.     int        ret ;
  95.  
  96.     memcpy( &track_inf[0],starttime,3 ) ;
  97.     memcpy( &track_inf[1],endtime,3 ) ;
  98.  
  99.     regs.h.ah = 0x50 ;
  100.     deviceno |= 0xc0 ;
  101.     regs.h.al = deviceno ;
  102.     regs.h.ch = 0;
  103.     regs.h.cl = 0x01;
  104.     regs.x.di = (unsigned int)track_inf ;
  105.  
  106.     segread( &sregs ) ;
  107.     int86x( CDR_INT,®s,®s,&sregs ) ;
  108.     ret = 0 ;                                /* 正常終了            */
  109.     if ( regs.h.ah == 0x02 )                /* デバイス番号誤り */
  110.         ret = DEVERR ;
  111.     else if ( regs.h.ah == 0x10 )            /* 音楽演奏中        */
  112.         ret = DEVPLY ;
  113.     else if ( regs.h.ah == 0x80 )            /* ハードエラー        */
  114.         ret = regs.x.cx ;
  115.  
  116.     return ( ret ) ;
  117. }
  118.  
  119. /******************************************************************************
  120.     CDR_mtrplay
  121. ******************************************************************************/
  122. int CDR_mtrplay( deviceno, starttime, endtime, count )
  123. int        deviceno ;            /* デバイス番号                */
  124. char    *starttime ;        /* 演奏開始時間                */
  125. char    *endtime ;            /* 演奏終了時間                */
  126. unsigned char count ;        /* リピート回数                */
  127. {
  128.     TRACK_INF    track_inf[2] ;
  129.     int        ret ;
  130.  
  131.     memcpy( &track_inf[0],starttime,3 ) ;
  132.     memcpy( &track_inf[1],endtime,3 ) ;
  133.  
  134.     regs.h.ah = 0x50 ;
  135.     deviceno |= 0xc0 ;
  136.     regs.h.al = deviceno ;
  137.     regs.h.bh = count - 1 ;
  138. /*    ↑マニュアルではリピート回数って書いてあるのに、TBIOSを除いて見たら-1していた。    */
  139.     regs.h.ch = 0xfe;
  140.     regs.h.cl = 0x01;
  141.     regs.x.di = (unsigned int)track_inf ;
  142.  
  143.     segread( &sregs ) ;
  144.     int86x( CDR_INT,®s,®s,&sregs ) ;
  145.     ret = 0 ;                                /* 正常終了            */
  146.     if ( regs.h.ah == 0x02 )                /* デバイス番号誤り */
  147.         ret = DEVERR ;
  148.     else if ( regs.h.ah == 0x10 )            /* 音楽演奏中        */
  149.         ret = DEVPLY ;
  150.     else if ( regs.h.ah == 0x80 )            /* ハードエラー        */
  151.         ret = regs.x.cx ;
  152.  
  153.     return ( ret ) ;
  154. }
  155.  
  156. /******************************************************************************
  157.     CDR_mphase
  158. ******************************************************************************/
  159. int CDR_mphase( deviceno, status, nowmusicno, tracktime, disktime )
  160. int        deviceno ;            /* デバイス番号                */
  161. int        *status ;            /* 音楽の演奏状態            */
  162. int        *nowmusicno ;        /* 現在演奏中の曲番号        */
  163. char    *tracktime ;        /* トラック内演奏時間        */
  164. char    *disktime ;            /* ディスク内演奏時間        */
  165. {
  166.     struct _status_data {
  167.         unsigned char    res1 ;
  168.         unsigned char    now ;
  169.         unsigned char    res2 ;
  170.         TRACK_INF    tracktime ;
  171.         unsigned char    res3 ;
  172.         TRACK_INF    disktime ;
  173.     } status_data ;
  174.     int        ret ;
  175.  
  176.     regs.h.ah = 0x53 ;
  177.     deviceno |= 0xc0 ;
  178.     regs.h.al = deviceno ;
  179.     regs.x.cx = 0;
  180.     regs.x.di = (unsigned int)&status_data ;
  181.  
  182.     segread( &sregs ) ;
  183.     int86x( CDR_INT,®s,®s,&sregs ) ;
  184.     ret = 0 ;                                /* 正常終了            */
  185.     if ( regs.h.ah == 0x02 )                /* デバイス番号誤り */
  186.         ret = DEVERR ;
  187.     else if ( regs.h.ah == 0x80 )            /* ハードエラー        */
  188.         ret = regs.x.cx ;
  189.  
  190.     *status = regs.h.al ;
  191.     *nowmusicno = status_data.now ;
  192.     memcpy( tracktime,&status_data.tracktime,3 ) ;
  193.     memcpy( disktime,&status_data.disktime,3 ) ;
  194.  
  195.     return ( ret ) ;
  196. }
  197.  
  198. /******************************************************************************
  199.     CDR_pause
  200. ******************************************************************************/
  201. int CDR_pause( deviceno )
  202. int        deviceno ;            /* デバイス番号                */
  203. {
  204.     int        ret ;
  205.  
  206.     regs.h.ah = 0x55 ;
  207.     deviceno |= 0xc0 ;
  208.     regs.h.al = deviceno ;
  209.     regs.h.ch = 0;
  210.  
  211.     segread( &sregs ) ;
  212.     int86x( CDR_INT,®s,®s,&sregs ) ;
  213.     ret = 0 ;                                /* 正常終了            */
  214.     if ( regs.h.ah == 0x02 )                /* デバイス番号誤り */
  215.         ret = DEVERR ;
  216.     else if ( regs.h.ah == 0x22 )            /* 音楽一時停止状態    */
  217.         ret = DEVPAUSE ;
  218.     else if ( regs.h.ah == 0x80 )            /* ハードエラー        */
  219.         ret = regs.x.cx ;
  220.  
  221.     return ( ret ) ;
  222. }
  223.  
  224. /******************************************************************************
  225.     CDR_continue
  226. ******************************************************************************/
  227. int CDR_continue( deviceno )
  228. int        deviceno ;            /* デバイス番号                */
  229. {
  230.     int        ret ;
  231.  
  232.     regs.h.ah = 0x56 ;
  233.     deviceno |= 0xc0 ;
  234.     regs.h.al = deviceno ;
  235.     regs.h.ch = 0;
  236.  
  237.     segread( &sregs ) ;
  238.     int86x( CDR_INT,®s,®s,&sregs ) ;
  239.     ret = 0 ;                                /* 正常終了            */
  240.     if ( regs.h.ah == 0x02 )                /* デバイス番号誤り */
  241.         ret = DEVERR ;
  242.     else if ( regs.h.ah == 0x10 )            /* 音楽演奏中        */
  243.         ret = DEVPLY ;
  244.     else if ( regs.h.ah == 0x23 )            /* 音楽一時停止状態でない    */
  245.         ret = DEVNPAUSE ;
  246.     else if ( regs.h.ah == 0x80 )            /* ハードエラー        */
  247.         ret = regs.x.cx ;
  248.  
  249.     return ( ret ) ;
  250. }
  251.  
  252. /******************************************************************************
  253.     CDR_mstop
  254. ******************************************************************************/
  255. int CDR_mstop( deviceno )
  256. int        deviceno ;            /* デバイス番号                */
  257. {
  258.     int        ret ;
  259.  
  260.     regs.h.ah = 0x52 ;
  261.     deviceno |= 0xc0 ;
  262.     regs.h.al = deviceno ;
  263.     regs.h.ch = 0;
  264.  
  265.     segread( &sregs ) ;
  266.     int86x( CDR_INT,®s,®s,&sregs ) ;
  267.     ret = 0 ;                                /* 正常終了            */
  268.     if ( regs.h.ah == 0x02 )                /* デバイス番号誤り */
  269.         ret = DEVERR ;
  270.     else if ( regs.h.ah == 0x80 )            /* ハードエラー        */
  271.         ret = regs.x.cx ;
  272.  
  273.     return ( ret ) ;
  274. }
  275.  
  276.