home *** CD-ROM | disk | FTP | other *** search
- ; CDCMD.TXT - GRASP 3.5 CD Command Routines - January 1990
- ;
- ; This program file contains routines for controlling audio CD play on
- ; CDROM devices:
- ;
- ; CDINIT checks whether cd-rom drive and driver are set up
- ; CDSTATUS returns CD status information
- ; PRTSTATUS analyzes CD status info and reports device capabilities
- ; CDPLAY plays starting at a given track for a given time
- ; CDPLAYTO plays from one track to a second track
- ; CDSTOP stops play
- ; CDRESUME resumes play from the last CDSTOP
- ; CDSEEK moves the cd head to a given track
- ; CDTRACK returns the location of a track
- ; CDEJECT opens the drive door/tray
- ; CDCLOSE closes the drive door/tray
- ;
- ; CDCMD a general-purpose command routine which makes the call
- ; (setting memory and issuing the interrupt) for the other
- ; subroutines
- ; CDCHECK reports any errors encountered by CDCMD
- ;
- ; Other commands supported by a given drive may be implemented by passing
- ; values to CDCMD. To determine the correct values, consult the reference
- ; or programming guide for your drive.
- ;
- ; Some older drives do not support all of the commands implemented here.
- ;
- ; Here's a small sample program that uses a CD player. Note that the first
- ; three commands set up variables which are used by the other routines.
- ; These must be issued before calling CDINIT. They were omitted from the
- ; CDROM example in the manual (page 3-41) by mistake.
- ;
- set first 0 ;first track on current CD
- set last 255 ;last track on current CD
- set drive "" ;drive letter of CD-ROM drive
- cdinit ;check whether CD driver is loaded
- if !len(@drive)
- text "CD ROM Driver not loaded"
- waitkey
- exit
- endif
- text "CD is drive "$@drive$":"$chr(10)$chr(10)
- cdstatus ;get drive status
- prtstatus @0 ;print out drive status
- cdplay 2 120 ;play track 2 for 120 seconds
- waitkey ;wait for a keypress
- cdstop ;stop playing
- exit
-
-
- ;CDINIT
- ;
- ; Checks for CD driver software and sets drive name.
- ;
- cdinit:
- int 0x2f 0x1500,0
- if @bx
- set drive chr(@cx+asc("A"))
- endif
- return
-
-
- ; CDSTATUS
- ;
- ; Returns CD Drive status and sets global variables @first and @last.
- ;
- cdstatus:
- local buf ofs("123456")
- local bseg seg(@buf);
- poke @bseg @buf 10 ;Audio Disk Info
- cdcmd 3,@buf|(@bseg<<16),6 ;READ IOCTL Input
- cdcheck @0,cdstatus
- set first peek(@bseg,@buf+1)+0
- set last peek(@bseg,@buf+2)+0
- poke @bseg @buf 6 ;Device status
- cdcmd 3,@buf|(@bseg<<16),5 ;READ IOCTL Input
- cdcheck @0,cdstatus
- return peekl(@bseg,@buf+1)
-
-
- ; PRTSTATUS
- ;
- ; Displays device characteristics and status.
- ;
- prtstatus:
- if @1&1
- text "Door Open"$chr(10)
- else
- text "Door Closed"$chr(10)
- endif
-
- if @1&2
- text "Door unlocked"$chr(10)
- else
- text "Door locked"$chr(10)
- endif
-
- if @1&4
- text "Supports cooked and raw reading"$chr(10)
- else
- text "Supports only cooked reading"$chr(10)
- endif
-
- if @1&8
- text "Read/write"$chr(10)
- else
- text "Read only"$chr(10)
- endif
-
- if @1&16
- text "Data read and plays audio/video tracks"$chr(10)
- else
- text "Data read only"$chr(10)
- endif
-
- if @1&32
- text "Supports ISO-9660 interleaving using interleave size and skip factor"$chr(10)
- else
- text "No interleaving"$chr(10)
- endif
-
- if @1&128
- text "Supports prefetching requests"$chr(10)
- else
- text "No Prefetching"$chr(10)
- endif
-
- if @1&256
- text "Supports audio channel manipulation"$chr(10)
- else
- text "No audio channel manipulation"$chr(10)
- endif
-
- if @1&512
- text "Supports HSG and Red Book addressing modes"$chr(10)
- else
- text "Supports HSG addressing mode"$chr(10)
- endif
-
- if @1&2048
- text "No disc is present in the drive"$chr(10)
- else
- text "Disc is present in the drive"$chr(10)
- endif
-
- return
-
-
- ; CDPLAY TRACK NUM_SECONDS [MINUTES SECONDS FRAMES]
- ;
- ; Starts playing at TRACK for NUM_SECONDS duration.
- ; MINUTES, SECONDS, and FRAMES (which are a 1/75th of
- ; a second) are optional offsets into the specified track
- ; to begin playing.
- ;
- cdplay:
- cdtrack @1 @3 @4 @5
- cdcmd 132,@0,@2*75
- cdcheck @0,cdplay
- return
-
-
- ; CDPLAYTO TRACK MINUTES SECONDS FRAMES TRACK MINUTES SECONDS FRAMES
- ;
- ; Plays from one TRACK (at offset MINUTES SECONDS FRAMES into it)
- ; to the second TRACK (at the second offsets into it).
- ;
- cdplayto:
- cdtrack @1 @2 @3 @4
- local begin @0
- cdtrack @5 @6 @7 @8
- local end @0
- cdcmd 132,@begin,@end-@begin
- cdcheck @0,cdplayto
- return
-
-
- ; CDSTOP
- ;
- ; Stops playing immediately.
- ;
- cdstop:
- cdcmd 133,0,0
- cdcheck @0,cdstop
- return
-
-
- ; CDRESUME
- ;
- ; Resumes playing from the last CDSTOP.
- ;
- cdresume:
- cdcmd 136,0,0
- cdcheck @0,cdresume
- return
-
-
- ; CDSEEK TRACK [MINUTES SECONDS FRAMES]
- ;
- ; Moves the playing head to a given track to minimize startup time.
- ; Parameters are the same as CDPLAY.
- ;
- cdseek:
- cdtrack @1 @2 @3 @4
- cdcmd 131,@0,0
- cdcheck @0,cdseek
- return
-
-
- ; CDTRACK TRACK MINUTES SECONDS FRAMES
- ;
- ; Returns the absolute sector number of a track.
- ;
- cdtrack:
- local buf ofs("1234567")
- local bseg seg(@buf);
- poke @bseg @buf 11 ;Get Audio Track Info
- poke @bseg @buf+1 @1 ;track number
- cdcmd 3,@buf|(@bseg<<16),7 ;READ IOCTL Input
- cdcheck @0,cdtrack
- return peekl(@bseg,@buf+2)+(@2*60+@3)*75+@4 ;return track address
-
-
- ; CDEJECT
- ;
- ; Opens the CD drive's tray/door.
- ;
- cdeject:
- local buf ofs("1")
- local bseg seg(@buf);
- poke @bseg @buf 0 ;Eject Disk
- cdcmd 12,@buf|(@bseg<<16),1 ;WRITE IOCTL Output
- cdcheck @0,cdeject
- return
-
-
- ; CDCLOSE
- ;
- ; Closes the CD's drive tray/door.
- ;
- cdclose:
- local buf ofs("1")
- local bseg seg(@buf);
- poke @bseg @buf 5 ;Close Tray
- cdcmd 12,@buf|(@bseg<<16),1 ;WRITE IOCTL Output
- cdcheck @0,cdclose
- return
-
-
- ; CDCMD
- ;
- ; Sets up command data in memory and calls the CD player software.
- ;
- cdcmd:
- local req ofs("12345678901234567890123456")
- local rseg seg(@req)
- poke @rseg @req 13 ;param length
- poke @rseg @req+1 0 ;subunit
- poke @rseg @req+2 @1 ;command code
- pokew @rseg @req+3 0 ;status
- pokel @rseg @req+5 0 0 ;reserved
- poke @rseg @req+13 1 ;address mode
- pokel @rseg @req+14 @2 ;begin
- pokel @rseg @req+18 @3 ;length
- pokel @rseg @req+22 0 ;reserved
- int 0x2f 0x1510,@req,asc(@drive)-asc("A"),,,,,seg(@req)
- if peek(@rseg,@req+4)&0x80
- databegin
- "Unknown Error"
- "Write-protect violation"
- "Unknown unit"
- "Drive not Ready"
- "Unknown command"
- "CRC error"
- "Bad drive request structure length"
- "Seek Error"
- "Unknown media"
- "Sector not found"
- "Printer out of paper"
- "Write Fault"
- "Read Fault"
- "General failure"
- "Reserved 1"
- "Reserved 2"
- "Invalid disk change"
- dataend
- if peek(@rseg,@req+3)<16
- dataskip peek(@rseg,@req+3)+1
- endif
- return @
- else
- return ""
- endif
-
-
- ; CDCHECK
- ;
- ; Reports any errors encountered by CDCMD.
- ;
- cdcheck:
- if @1!=""
- text chr(10)$@2$": "$@1$chr(10)
- endif
- return