home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / m / m110 / 3.ddi / GRPCT2.EXE / CDCMD.TXT < prev    next >
Encoding:
Text File  |  1990-02-12  |  7.0 KB  |  306 lines

  1. ;       CDCMD.TXT - GRASP 3.5 CD Command Routines - January 1990
  2. ;
  3. ; This program file contains routines for controlling audio CD play on
  4. ; CDROM devices:
  5. ;
  6. ; CDINIT     checks whether cd-rom drive and driver are set up
  7. ; CDSTATUS   returns CD status information
  8. ; PRTSTATUS  analyzes CD status info and reports device capabilities
  9. ; CDPLAY     plays starting at a given track for a given time
  10. ; CDPLAYTO   plays from one track to a second track
  11. ; CDSTOP     stops play
  12. ; CDRESUME   resumes play from the last CDSTOP
  13. ; CDSEEK     moves the cd head to a given track
  14. ; CDTRACK    returns the location of a track
  15. ; CDEJECT    opens the drive door/tray
  16. ; CDCLOSE    closes the drive door/tray
  17. ;
  18. ; CDCMD      a general-purpose command routine which makes the call
  19. ;            (setting memory and issuing the interrupt) for the other
  20. ;            subroutines
  21. ; CDCHECK    reports any errors encountered by CDCMD
  22. ;
  23. ; Other commands supported by a given drive may be implemented by passing
  24. ; values to CDCMD. To determine the correct values, consult the reference
  25. ; or programming guide for your drive.
  26. ;
  27. ; Some older drives do not support all of the commands implemented here.
  28. ;
  29. ; Here's a small sample program that uses a CD player.  Note that the first
  30. ; three commands set up variables which are used by the other routines.
  31. ; These must be issued before calling CDINIT.  They were omitted from the
  32. ; CDROM example in the manual (page 3-41) by mistake.
  33.   set first 0       ;first track on current CD
  34.   set last 255      ;last track on current CD
  35.   set drive ""      ;drive letter of CD-ROM drive
  36.   cdinit            ;check whether CD driver is loaded
  37.   if !len(@drive)
  38.     text "CD ROM Driver not loaded"
  39.     waitkey
  40.     exit
  41.   endif
  42.   text "CD is drive "$@drive$":"$chr(10)$chr(10)
  43.   cdstatus          ;get drive status
  44.   prtstatus @0      ;print out drive status
  45.   cdplay 2 120      ;play track 2 for 120 seconds
  46.   waitkey           ;wait for a keypress
  47.   cdstop            ;stop playing
  48. exit
  49.  
  50.  
  51. ;CDINIT
  52. ;
  53. ; Checks for CD driver software and sets drive name.
  54. ;
  55. cdinit:
  56.     int 0x2f 0x1500,0
  57.     if @bx
  58.         set drive chr(@cx+asc("A"))
  59.     endif
  60.     return
  61.  
  62.  
  63. ; CDSTATUS
  64. ;
  65. ; Returns CD Drive status and sets global variables @first and @last.
  66. ;
  67. cdstatus:
  68.     local    buf ofs("123456")
  69.     local    bseg seg(@buf);
  70.     poke    @bseg @buf 10                ;Audio Disk Info
  71.     cdcmd    3,@buf|(@bseg<<16),6            ;READ IOCTL Input
  72.     cdcheck    @0,cdstatus
  73.     set    first peek(@bseg,@buf+1)+0
  74.     set    last  peek(@bseg,@buf+2)+0
  75.     poke    @bseg @buf 6                ;Device status
  76.     cdcmd    3,@buf|(@bseg<<16),5            ;READ IOCTL Input
  77.     cdcheck    @0,cdstatus
  78.     return    peekl(@bseg,@buf+1)
  79.  
  80.  
  81. ; PRTSTATUS
  82. ;
  83. ; Displays device characteristics and status.
  84. ;
  85. prtstatus:
  86.     if @1&1
  87.         text "Door Open"$chr(10)
  88.     else
  89.         text "Door Closed"$chr(10)
  90.     endif
  91.  
  92.     if @1&2
  93.         text "Door unlocked"$chr(10)
  94.     else
  95.         text "Door locked"$chr(10)
  96.     endif
  97.  
  98.     if @1&4
  99.         text "Supports cooked and raw reading"$chr(10)
  100.     else
  101.         text "Supports only cooked reading"$chr(10)
  102.     endif
  103.  
  104.     if @1&8
  105.         text "Read/write"$chr(10)
  106.     else
  107.         text "Read only"$chr(10)
  108.     endif
  109.  
  110.     if @1&16
  111.         text "Data read and plays audio/video tracks"$chr(10)
  112.     else
  113.         text "Data read only"$chr(10)
  114.     endif
  115.  
  116.     if @1&32
  117.         text "Supports ISO-9660 interleaving using interleave size and skip factor"$chr(10)
  118.     else
  119.         text "No interleaving"$chr(10)
  120.     endif
  121.  
  122.     if @1&128
  123.         text "Supports prefetching requests"$chr(10)
  124.     else
  125.         text "No Prefetching"$chr(10)
  126.     endif
  127.  
  128.     if @1&256
  129.         text "Supports audio channel manipulation"$chr(10)
  130.     else
  131.         text "No audio channel manipulation"$chr(10)
  132.     endif
  133.  
  134.     if @1&512
  135.         text "Supports HSG and Red Book addressing modes"$chr(10)
  136.     else
  137.         text "Supports HSG addressing mode"$chr(10)
  138.     endif
  139.  
  140.     if @1&2048
  141.         text "No disc is present in the drive"$chr(10)
  142.     else
  143.         text "Disc is present in the drive"$chr(10)
  144.     endif
  145.  
  146.     return
  147.  
  148.  
  149. ; CDPLAY TRACK NUM_SECONDS [MINUTES SECONDS FRAMES]
  150. ;
  151. ; Starts playing at TRACK for NUM_SECONDS duration.
  152. ; MINUTES, SECONDS, and FRAMES (which are a 1/75th of
  153. ; a second) are optional offsets into the specified track
  154. ; to begin playing.
  155. ;
  156. cdplay:
  157.     cdtrack    @1 @3 @4 @5
  158.     cdcmd    132,@0,@2*75
  159.     cdcheck    @0,cdplay
  160.     return
  161.  
  162.  
  163. ; CDPLAYTO TRACK MINUTES SECONDS FRAMES TRACK MINUTES SECONDS FRAMES
  164. ;
  165. ; Plays from one TRACK (at offset MINUTES SECONDS FRAMES into it)
  166. ; to the second TRACK (at the second offsets into it).
  167. ;
  168. cdplayto:
  169.     cdtrack    @1 @2 @3 @4
  170.     local    begin @0
  171.     cdtrack    @5 @6 @7 @8
  172.     local    end @0
  173.     cdcmd    132,@begin,@end-@begin
  174.     cdcheck    @0,cdplayto
  175.     return
  176.  
  177.  
  178. ; CDSTOP
  179. ;
  180. ; Stops playing immediately.
  181. ;
  182. cdstop:
  183.     cdcmd    133,0,0
  184.     cdcheck    @0,cdstop
  185.     return
  186.  
  187.  
  188. ; CDRESUME
  189. ;
  190. ; Resumes playing from the last CDSTOP.
  191. ;
  192. cdresume:
  193.     cdcmd    136,0,0
  194.     cdcheck    @0,cdresume
  195.     return
  196.  
  197.  
  198. ; CDSEEK TRACK [MINUTES SECONDS FRAMES]
  199. ;
  200. ; Moves the playing head to a given track to minimize startup time.
  201. ; Parameters are the same as CDPLAY.
  202. ;
  203. cdseek:
  204.     cdtrack @1 @2 @3 @4
  205.     cdcmd 131,@0,0
  206.     cdcheck    @0,cdseek
  207.     return
  208.  
  209.  
  210. ; CDTRACK TRACK MINUTES SECONDS FRAMES
  211. ;
  212. ; Returns the absolute sector number of a track.
  213. ;
  214. cdtrack:
  215.     local    buf ofs("1234567")
  216.     local    bseg seg(@buf);
  217.     poke    @bseg @buf 11                ;Get Audio Track Info
  218.     poke    @bseg @buf+1 @1             ;track number
  219.     cdcmd    3,@buf|(@bseg<<16),7            ;READ IOCTL Input
  220.     cdcheck    @0,cdtrack
  221.     return    peekl(@bseg,@buf+2)+(@2*60+@3)*75+@4    ;return track address
  222.  
  223.  
  224. ; CDEJECT
  225. ;
  226. ; Opens the CD drive's tray/door.
  227. ;
  228. cdeject:
  229.     local    buf ofs("1")
  230.     local    bseg seg(@buf);
  231.     poke    @bseg @buf 0                ;Eject Disk
  232.     cdcmd    12,@buf|(@bseg<<16),1            ;WRITE IOCTL Output
  233.     cdcheck    @0,cdeject
  234.     return
  235.  
  236.  
  237. ; CDCLOSE
  238. ;
  239. ; Closes the CD's drive tray/door.
  240. ;
  241. cdclose:
  242.     local    buf ofs("1")
  243.     local    bseg seg(@buf);
  244.     poke    @bseg @buf 5                ;Close Tray
  245.     cdcmd    12,@buf|(@bseg<<16),1            ;WRITE IOCTL Output
  246.     cdcheck    @0,cdclose
  247.     return
  248.  
  249.  
  250. ; CDCMD
  251. ;
  252. ; Sets up command data in memory and calls the CD player software.
  253. ;
  254. cdcmd:
  255.     local req ofs("12345678901234567890123456")
  256.     local rseg seg(@req)
  257.     poke  @rseg @req 13                ;param length
  258.     poke  @rseg @req+1 0                ;subunit
  259.     poke  @rseg @req+2 @1                ;command code
  260.     pokew @rseg @req+3 0                ;status
  261.     pokel @rseg @req+5 0 0                ;reserved
  262.     poke  @rseg @req+13 1                ;address mode
  263.     pokel @rseg @req+14 @2                ;begin
  264.     pokel @rseg @req+18 @3                ;length
  265.     pokel @rseg @req+22 0                ;reserved
  266.     int 0x2f 0x1510,@req,asc(@drive)-asc("A"),,,,,seg(@req)
  267.     if peek(@rseg,@req+4)&0x80
  268.         databegin
  269.             "Unknown Error"
  270.             "Write-protect violation"
  271.             "Unknown unit"
  272.             "Drive not Ready"
  273.             "Unknown command"
  274.             "CRC error"
  275.             "Bad drive request structure length"
  276.             "Seek Error"
  277.             "Unknown media"
  278.             "Sector not found"
  279.             "Printer out of paper"
  280.             "Write Fault"
  281.             "Read Fault"
  282.             "General failure"
  283.             "Reserved 1"
  284.             "Reserved 2"
  285.             "Invalid disk change"
  286.         dataend
  287.         if peek(@rseg,@req+3)<16
  288.             dataskip peek(@rseg,@req+3)+1
  289.         endif
  290.         return @
  291.     else
  292.         return ""
  293.     endif
  294.  
  295.  
  296. ; CDCHECK
  297. ;
  298. ; Reports any errors encountered by CDCMD.
  299. cdcheck:
  300.     if @1!=""
  301.         text chr(10)$@2$": "$@1$chr(10)
  302.     endif
  303.     return
  304.