home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / CDROM / GetCDDB / src / MYCDCODE.BB2 < prev    next >
Text File  |  2000-01-07  |  5KB  |  190 lines

  1. ;MyCDCode.bb2
  2.  
  3. ; This is the CD code taken from Marc Le Douarain's archive MaVaTi_Blitz.lha on ; Aminet. It has been modified to remove all of the unnecessary bits for GetCDDB
  4.  
  5.  
  6. ;#SCSI_CMD_SSU=$1B
  7. #SCSIF_WRITE=0
  8. #SCSIF_READ=1
  9. #SCSIF_AUTOSENSE=2
  10. ;#SCSI_CMD_READSUBCHANNEL=$42
  11. #SCSI_CMD_READTOC=$43
  12. ;#SCSI_CMD_PLAYAUDIO12=$A5
  13. ;#SCSI_CMD_PAUSERESUME=$4B
  14.  
  15. #SENSE_LEN=252
  16. #MAX_DATA_LEN=252
  17. #MAX_TOC_LEN=804
  18.  
  19. OPENDEVERROR=0;#_FALSE
  20. ; CDDA vars
  21. STATUS_CDDA.b=0 ; How the CD drive is (playing:$11, paused:$12, stopped:other values)
  22. TRACK.b=0       ; Track being played
  23. ACTUALINDEX.l=0 ; address in actualtrack
  24. TOTALINDEX.l=0  ; address in CD
  25. TOClength.b=0   ; Number of tracks
  26. validTOC.b=0    ; 1=We have read a valid TOC, 0=No
  27. DEFTYPE .b *TOCbuf       ; Buffer for Table Of Contents
  28. Dim TOCflags.b(100) ; 0=CDDA, 1=Data
  29. ONECDDAVALID.b=0    ; Is there at least one CDDA track ?
  30. Dim TOCaddr.l(100)  ; Track starts
  31. TOCCDID$=""      ; Id string of CD
  32. TOCCDTITLE$=""   ; Title of actual CD */
  33. TOCCDARTIST$=""  ; Artist
  34. Dim TOCCDTITLESONG$(100) ; Title of the songs...
  35.  
  36. NEWTYPE.toc
  37.   f.w ;frames
  38.   s.w ;seconds
  39.   m.w ;minutes
  40. End NEWTYPE
  41.  
  42. Dim cdtoc.toc(100)
  43.  
  44. ; Global vars
  45. DEFTYPE .MsgPort *msgport
  46. DEFTYPE .IOStdReq *ioreq
  47. DEFTYPE .b *scsidata
  48. DEFTYPE .SCSICmd *scsicmd
  49. DEFTYPE .b *scsisense
  50.  
  51. NEWTYPE .SCSICMD10
  52.   opcode.b
  53.   b1.b
  54.   b2.b
  55.   b3.b
  56.   b4.b
  57.   b5.b
  58.   b6.b
  59.   b7.b
  60.   b8.b
  61.   control.b
  62. End NEWTYPE
  63.  
  64. ;  DoScsiCmd(UBYTE *Data, Int datasize, UBYTE *cmd, Int cmdsize, UBYTE flags)
  65. Function.l DoScsiCmd{*_Data,datasize,*cmd,cmdsize,flags}
  66.   SHARED *ioreq
  67.   SHARED *scsicmd
  68.   SHARED *scsisense
  69.   *ioreq\io_Length=SizeOf.SCSICmd
  70.   *ioreq\io_Data=*scsicmd
  71.   *ioreq\io_Command=#HD_SCSICMD
  72.   *scsicmd\scsi_Data=*_Data
  73.   *scsicmd\scsi_Length=datasize
  74.   *scsicmd\scsi_SenseActual=0
  75.   *scsicmd\scsi_SenseData=*scsisense
  76.   *scsicmd\scsi_Command=*cmd
  77.   *scsicmd\scsi_CmdLength=cmdsize
  78.   *scsicmd\scsi_Flags=flags
  79.   DoIO_(*ioreq)
  80.   Function Return *ioreq\io_Error
  81. End Function
  82.  
  83. Function CDDAReadContents{}
  84.   SHARED *TOCbuf
  85.   SHARED TOClength.b
  86.   SHARED TOCaddr.l()
  87.   SHARED TOCflags.b()
  88.   SHARED validTOC.b
  89.   SHARED ONECDDAVALID.b
  90.   SHARED TOCCDID$
  91.   SHARED PATHDISK$
  92.   SHARED TOCCDARTIST$
  93.   SHARED TOCCDTITLE$
  94.   SHARED TOCCDTITLESONG$()
  95.   SHARED cdtoc()
  96.  
  97.   DEFTYPE .SCSICMD10 command
  98.   command\opcode=#SCSI_CMD_READTOC
  99.   command\b7=$03
  100.   command\b8=$24
  101.   TOCsize.l=0
  102.   *TOCptr.b=0
  103.   validTOC=0;#_FALSE
  104.   err=DoScsiCmd{*TOCbuf,#MAX_TOC_LEN,&command,SizeOf.SCSICMD10,#SCSIF_READ|#SCSIF_AUTOSENSE}
  105.   If NOT err
  106.     TOCsize=((Peek.b(*TOCbuf)MOD256)*(2^8))|(Peek.b(*TOCbuf+1)MOD256)
  107.     TOCaddr(2)=0:TOCaddr(1)=0:TOCaddr(0)=0
  108.     TOClength=0
  109.     If(TOCsize>=2)
  110.         TOCsize=TOCsize-2
  111.     End If
  112.     ONECDDAVALID=0
  113.     *TOCptr=*TOCbuf+4
  114.     Repeat
  115.       I1$=Right$(Hex$(Peek.b(*TOCptr+4)),2)
  116.       I2$=Right$(Hex$(Peek.b(*TOCptr+5)),2)
  117.       I3$=Right$(Hex$(Peek.b(*TOCptr+6)),2)
  118.       I4$=Right$(Hex$(Peek.b(*TOCptr+7)),2)
  119. ;      Request "o",I1$+"|"+I2$+"|"+I3$+"|"+I4$,"OK"
  120.       TOCaddr(TOClength)=Val("$"+I1$+I2$+I3$+I4$)
  121. ;      Request "p",Str$(TOCaddr(TOClength)+150),"OK"
  122.       TOCflags(TOClength)=((Peek.b(*TOCptr+1) AND $4) /4) AND 1
  123.       ONECDDAVALID=ONECDDAVALID| ((NOT(TOCflags(TOClength)))AND 1)
  124.       TOClength+1
  125.       *TOCptr=*TOCptr+8
  126.     Until NOT ((*TOCptr<(*TOCbuf+4+TOCsize)) AND (TOClength<100))
  127.     TOClength-1
  128.     TOCCDID$="ID"+Right$("0000"+Str$(TOClength),2)+Right$(Hex$(TOCaddr(2)),6)+Right$(Hex$(TOCaddr(TOClength)),6)
  129.     validTOC=-1;#_TRUE
  130.   End If
  131.   Function Return err
  132. End Function
  133.  
  134. Function InitCDDA{}
  135.   SHARED scsidev$,scsiid
  136.   SHARED *msgport,*ioreq,OPENDEVERROR,*scsicmd,*scsisense,*scsidata,*TOCbuf
  137.   CD_DRIVE_OK=0;#_FALSE
  138.   *msgport=CreateMsgPort_
  139.   If *msgport
  140.     *ioreq=CreateIORequest_(*msgport,SizeOf.IOStdReq)
  141.     If *ioreq
  142.       OPENDEVERROR=OpenDevice_(&scsidev$,scsiid,*ioreq,0)
  143.       If NOT OPENDEVERROR
  144.         *scsicmd=AllocMem(SizeOf.SCSICmd,0)
  145.         If *scsicmd
  146.           *scsisense=AllocMem(#SENSE_LEN,0)
  147.           If *scsisense
  148.             *scsidata=AllocMem(#MAX_DATA_LEN,0)
  149.             If *scsidata
  150.               *TOCbuf=AllocMem(#MAX_TOC_LEN,0)
  151.               If *TOCbuf
  152.                 CD_DRIVE_OK=-1;#_TRUE
  153.               End If
  154.             End If
  155.           End If
  156.         End If
  157.       Else
  158. ;        R=Request("CDDA Init Error","Couldn't open device:|'"+scsidev$+"'|Unit:"+Str$(scsiid),"OK!")
  159.       End If
  160.     End If
  161.   End If
  162.   Function Return CD_DRIVE_OK
  163. End Function
  164.  
  165. Statement EndingCDDA{}
  166.   SHARED *msgport,*ioreq,OPENDEVERROR,*scsicmd,*scsisense,*scsidata,*TOCbuf
  167.   If *TOCbuf
  168.     FreeMem *TOCbuf,#MAX_TOC_LEN
  169.   End If
  170.   If *scsidata
  171.     FreeMem *scsidata,#MAX_DATA_LEN
  172.   End If
  173.   If *scsisense
  174.     FreeMem *scsisense,#SENSE_LEN
  175.   End If
  176.   If *scsicmd
  177.     FreeMem *scsicmd,SizeOf.SCSICmd
  178.   End If
  179.   If NOT OPENDEVERROR
  180.     CloseDevice_(*ioreq)
  181.   End If
  182.   If *ioreq
  183.     DeleteIORequest_(*ioreq)
  184.   End If
  185.   If *msgport
  186.     DeleteMsgPort_(*msgport)
  187.   End If
  188. End Statement
  189.  
  190.