home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / m / m111 / 2.img / GRPCT2.EXE / CDCMD.TXT < prev    next >
Encoding:
Text File  |  1990-02-26  |  7.3 KB  |  304 lines

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