ricompactdisclib
This library plays audio CDs through cd.device, the CD drive of the
CD32, or through another device that understands the same commands.
OpenCD opens the device, unit 0 of cd.device unless another device
and unit are given; every other command does nothing and returns 0
until it worked. CloseCD closes it again; a device still open is
closed when the program ends. Only one device can be open at a time:
call CloseCD before opening another.
CDReadTOC reads the table of contents of the CD; CDNumTracks,
CDFirstTrack, CDLastTrack and CDTrackLength read from it, so it
must come first. CDPlayTrack starts playing and returns at once;
CDStop stops the music.
CDUpdateInfo asks the drive for the current position, which
CDTrackPlaying, CDTrackMins and CDTrackSecs then return.
CDVolume and CDFastForward return the device’s error code, 0 if
they worked.
All commands except OpenCD, CloseCD, CDTrackMins, CDTrackSecs
and CDTrackPlaying work in Amiga mode only. With the third argument
of OpenCD, the SCSI flag, CDPlayTrack, CDReadTOC and the track
functions use SCSI commands instead, for a CD drive that does not
understand cd.device’s commands (see OpenCD). The library works on
every Kickstart.
Playing the first track and showing its time:
ok=OpenCD
If ok=-1
If CDReadTOC
CDPlayTrack CDFirstTrack,1
Repeat
VWait 50
r=CDUpdateInfo
NPrint CDTrackMins,":",CDTrackSecs
Until Joyb(0)
CDStop
EndIf
CloseCD
EndIfBased on the RI CompactDisk Lib guide by Red When Excited.
Library number 14.
Commands
CDDoor
Opens the tray of the drive with 1 and closes it with 0.
Statement. Help text: on/off
Arguments: .l
CDFastForward
Makes the drive search forwards through the music. Returns the device’s error code.
Statement or function, result .l. No help text.
No arguments.
CDFirstTrack
The number of the first track on the CD, from the table of contents read with CDReadTOC; 0 before it.
Function, result .l. No help text.
No arguments.
CDFlush
Sends the device’s flush command (CD_FLUSH).
Statement. No help text.
No arguments.
CDLastTrack
The number of the last track on the CD, from the table of contents read with CDReadTOC; 0 before it.
Function, result .l. No help text.
No arguments.
CDMotor
Switches the motor of the drive on with 1 (or -1) and off with 0.
Statement. Help text: on|off
Arguments: .l
Only the lowest bit of the value counts, so 2 switches it off.
CDNormalSpeed
Ends CDRewind or CDFastForward and plays at normal speed again.
Statement. No help text.
No arguments.
CDNumTracks
The number of tracks on the CD, from the table of contents read with CDReadTOC; 0 before it.
Function, result .l. No help text.
No arguments.
CDPause
Pauses the music with 1 (or -1) and goes on with 0.
Statement. Help text: on/off
Arguments: .l
Only the lowest bit of the value counts, so 2 also goes on.
CDPlayTrack
Starts playing numtracks tracks from the track track# on and returns at once, while the music plays. As a function it returns -1 if the play was sent, else 0.
Statement or function, result .l. Help text: track#,numtracks
Arguments: .l, .l
Tracks are numbered from 1. A play still running from the last
CDPlayTrack is stopped first. With the SCSI flag of OpenCD the
tracks are found in the table of contents of CDReadTOC, which must
come first; the result is -1 if the drive took the command, and 0
without a table of contents, for a track it does not hold and for 0
tracks.
CDReadTOC
Reads the table of contents of the CD, which CDNumTracks, CDFirstTrack, CDLastTrack and CDTrackLength use. Returns -1 if it worked, else 0.
Statement or function, result .l. No help text.
No arguments.
If reading fails, the library keeps no table of contents, and the track functions return 0.
CDRewind
Makes the drive search backwards through the music.
Statement. No help text.
No arguments.
CDSpeed
Sets the search mode directly - 0 normal play, 1 forwards, 2 backwards.
Statement. Help text: speed
Arguments: .l
CDStatus
The status of the drive, a set of bits.
Function, result .l. No help text.
No arguments.
| Bit value | Meaning |
|---|---|
| 1 | tray closed |
| 2 | a disc is in |
| 4 | the disc spins |
| 8 | table of contents read |
| 16 | track 1 holds data |
| 32 | playing |
| 64 | paused |
| 128 | searching |
| 256 | searching backwards |
Several bits can be set at once; test one with AND, for example
If CDStatus AND 32.
CDStop
Stops the music that CDPlayTrack started and waits until the device has stopped it.
Statement. No help text.
No arguments.
CDTrackLength
The length of a track in seconds, from its start to the start of the next track or, for the last track, to the end of the CD’s music. It is 0 before CDReadTOC.
Function, result .l. Help text: track#
Arguments: .l
The track must exist on the CD: check it against CDFirstTrack and
CDLastTrack. With runtime error checking, another track is a
runtime error; without it, the result means nothing.
CDTrackMins
The minutes of the position found by the last CDUpdateInfo - from the start of the track, or with an offset of 1 from the start of the CD.
Function, result .w. Help text: [offset] - mins for current track
2 forms:
- no arguments
.w
With runtime error checking, an offset other than 0 or 1 is a runtime error; without it, the result means nothing.
CDTrackPlaying
The number of the track that was playing at the last CDUpdateInfo.
Function, result .w. Help text: - current track being played
No arguments.
CDTrackSecs
The seconds of the position found by the last CDUpdateInfo - from the start of the track, or with an offset of 1 from the start of the CD.
Function, result .w. Help text: [offset] - secs for current track
2 forms:
- no arguments
.w
With runtime error checking, an offset other than 0 or 1 is a runtime error; without it, the result means nothing.
CDUpdateInfo
Asks the drive for the track playing and its position, for CDTrackPlaying, CDTrackMins and CDTrackSecs. The result is the address of that information, 0 without an open device.
Statement or function, result .l. Help text: - update track playing/time information
No arguments.
CDVolume
Fades the volume to volume, 0 to 32767, over lengthoffade frames of 1/75 second, through the device’s CD_ATTENUATE command, and returns the device’s error code.
Statement or function, result .l. Help text: volume,lengthoffade
Arguments: .l, .l
CloseCD
Stops playing and closes the device. Returns -1 if a device was open, else 0.
Statement or function, result .l. No help text.
No arguments.
OpenCD
Opens unit 0 of cd.device, or the unit unit of the device devicename, for the other commands. As a function it returns -1 if the device was opened, else 0.
Statement or function, result .l. Help text: [devicename,unit,scsiflag] - open a CD compatible device
3 forms:
- no arguments
$, .l$, .l, .l
Each OpenCD uses only what it is given: without arguments it opens
unit 0 of cd.device, and the SCSI flag counts only for the call it is
given to. A device name must be shorter than 40 characters; a longer
one is refused with 0. Only one device can be open: call CloseCD
before opening another. With runtime error checking, OpenCD while
a device is open is a runtime error.
With a scsiflag other than 0, CDPlayTrack, CDReadTOC and the
track functions use SCSI commands, for a CD drive that does not
understand cd.device’s commands. The other commands send cd.device’s
commands also then, so CDStop does not stop a play started with
SCSI.