Deprecated: Array and string offset access syntax with curly braces is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Subs.php on line 3825
SDL: Open Default CDROM Drive

Author Topic: SDL: Open Default CDROM Drive  (Read 2516 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
SDL: Open Default CDROM Drive
« on: July 27, 2008, 10:58:35 PM »
The following example illustrates the use of the SDL_CDOpen and SDL_CDStatus functions.

Code: [Select]
#COMPILE EXE
#DIM ALL
#INCLUDE "SDL.INC"

FUNCTION PBMAIN () AS LONG

   ' Initialize SDL
   IF SDL_Init(%SDL_INIT_CDROM) < 0 THEN
      ? "Couldn't initialize SDL" & SDL_GetError
      #IF %DEF(%PB_CC32)
         WAITKEY$
      #ENDIF
      EXIT FUNCTION
   END IF

   LOCAL pcdrom AS SDL_CD PTR
   LOCAL nStatus AS LONG
   LOCAL strStatus AS STRING

   pcdrom = SDL_CDOpen(0)
   IF pcdrom = %NULL THEN
      ? "Couldn't open default CD-ROM drive: " & SDL_GetError
      #IF %DEF(%PB_CC32)
         WAITKEY$
      #ENDIF
      SDL_Quit
      EXIT FUNCTION
   END IF

   nStatus = SDL_CDStatus(pcdrom)
   SELECT CASE nStatus
      CASE %CD_TRAYEMPTY : strStatus = "tray empty"
      CASE %CD_STOPPED   : strStatus = "stopped"
      CASE %CD_PLAYING   : strStatus = "playing"
      CASE %CD_PAUSED    : strStatus = "paused"
      CASE %CD_ERROR     : strStatus = "error state"
   END SELECT
   ? "Drive status: " & strStatus

   IF nStatus >= %CD_PLAYING THEN
      LOCAL m, s, f AS LONG
      FRAMES_TO_MSF(@pcdrom.cur_frame, m, s, f)
      ? "Currently playing track" & _
         STR$(@pcdrom.track(@pcdrom.cur_track).id) &  _
         STR$(m) & "." & FORMAT$(s)
   END IF

   ' Close the SDL_CD handle
   SDL_CDClose(pcdrom)

   ' Shut down SDL
   SDL_Quit

   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION
« Last Edit: August 07, 2011, 08:06:27 PM by José Roca »