Author Topic: Replayer for Gameboy music files (*.gbs) + Source  (Read 1292 times)

0 Members and 1 Guest are viewing this topic.

Offline padman

  • Senior Member
  • Pentium
  • ********
  • Posts: 977
  • Karma: 258
    • View Profile
Hey guys!

This is the replayer I used for my GBC cracktro remakes which can be found
here: http://www.dbfinteractive.com/forum/index.php?topic=4825.0 and
here: http://www.dbfinteractive.com/forum/index.php?topic=4826.0 in case you've missed them.  ;)

It uses the nezplug dll which can be found here: http://sourceforge.net/projects/nezplug/
It shouldn't be too hard to port it to Freebasic etc. It's nothing special, but maybe someone finds it useful one day. :) In the executable provided in the zipfile (which assumes that the dll is in the same folder!!) you can switch thru the subsongs by pressing [1] or [2]. [ESC] quits.

Enjoy!

Pad

Oh yeah, I almost forgot. Here's the code & zip:

Code: [Select]
;#########################################################################
;# Gameboy music replayer for Purebasic by Padman. (c)02/2011            #
;# It uses an old version of the nezplug dll which can be found at       #
;# http://sourceforge.net/projects/nezplug/                              #
;# Newer versions of the dll lack the GetSongMax Export, so make         #
;# sure to use the dll included in the ZIP file when running the example!#
;# Tested with PB 4.41, but should work with all versions 4.x            #
;#########################################################################
 
  Number = 1
 
  If OpenLibrary(0, "npnez.dll")
 
       
       ;************************************************************       ;Get DLL exports
        *GB_Open_Mem = GetFunction(0, "_HSPNSFOpenMemory@16")
        *GB_Close = GetFunction(0, "_HSPNSFClose@16")
        *GB_Song_No = GetFunction(0, "_HSPNSFSongNo@16")
        *GB_GetSongMax = GetFunction(0, "_HSPNSFGetSongMax@16")
        *GB_Volume = GetFunction(0, "_HSPNSFVolume@16")
        *GB_Play = GetFunction(0, "_HSPNSFPlay@16")
        *GB_Stop = GetFunction(0, "_HSPNSFStop@16")
       ;************************************************************
                                                                           ; There are more exports, but I only used these.
                                                                           ; If you want more you'll have to add them on your own ;)
       
 
        CallFunctionFast(*GB_Open_Mem,?GBS,?GBSEnd-?GBS,0,0)               ;open the included music file
       
   
       
    max=CallFunctionFast(*GB_GetSongMax,0,0,0,0)                           ;look up how many subsongs there are
        CallFunctionFast(*GB_Song_No,Number,0,0,0)                         ;set subsong to 1
        CallFunctionFast(*GB_Play,@music,0,0,0)                            ;start playing

   

        Title.s=PeekS(?GBS+$10)                                            ; offsets 10h,30h,50h; quick "hack" to easily get the file info
        Author.s=PeekS(?GBS+$30)
        Copyright.s=PeekS(?GBS+$50)

 
 
     If OpenConsole()                   
         EnableGraphicalConsole(1)             
             PrintN("Gameboy music replayer for Purebasic by Padman")
             For i=1 To 3 : PrintN("") : Next
             PrintN("Title: "+title.s)
             PrintN("Author: "+author.s)
             PrintN("Copyright: "+copyright.s)
             PrintN("")
             PrintN("Press ESC to exit...")
        Repeat
             ConsoleLocate(0,2)
             PrintN("Song "+Str(number)+" of "+Str(Abs(max)))
             KeyPressed$ = Inkey()
           
             Delay(20)   
               If KeyPressed$ = Chr(50)                                    ;if "2" (ASCII 50) is pressed increase subsong number
                   If Number< Abs(max) : Number+1 : EndIf

                    CallFunctionFast(*GB_Song_No,Number,0,0,0)             ; set new subsong
                    CallFunctionFast(*GB_Play,@music,0,0,0)                ; start playing again
 
              EndIf     
   
              If KeyPressed$ = Chr(49)                                     ;if "1" (ASCII 49) is pressed decrease subsong number
                  If Number > 1 : Number-1 : EndIf

                   CallFunctionFast(*GB_Song_No,Number,0,0,0)              ;set new subsong
                   CallFunctionFast(*GB_Play,?GBS,0,0,0)                   ;start playing againg
             EndIf
     
 

      Until KeyPressed$ = Chr(27)                                         ;until ESC is pressed
    EndIf

 EndIf
 
  CloseLibrary(0)                                             ;shutdown DLL
 
 
  DataSection
  GBS: IncludeBinary "mario.gbs"
  GBSEnd:
  EndDataSection
« Last Edit: February 08, 2011 by padman »
Challenge Trophies Won: