Advertisement
Guest User

nitrofurano

a guest
Mar 12th, 2008
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '--- vgm to txt converter - Paulo Silva - march '08 - GPL - runs on sdlBasic
  2. finp$="BattleSquadron_03_EndingTheme.vgm": fout$=finp$+".txt"
  3. '---------------------------------------------------------------------
  4. '--- define variables and arrays
  5. songname$="":mkflag$="":npatt=0:nflag=0
  6. dim samplename$[32],samplelngth[32],sampleftune[32],samplevolum[32],samplereppt[32],samplerepln[32],pattseq[128]
  7. '----------------------------------------------- functions -----------
  8. function hxfx$(a,b)
  9.   tmpq$="":for i=1 to b:tmpq$+="0":next:tmpr$=ucase$(right$(tmpq$+hex$(a),b)):hxfx$=tmpr$:end function
  10. '--- open document
  11. open finp$ for input as #1:open fout$ for output as #2
  12. '----------------------------------------------- converter code ------
  13. '------ reading 64 bytes header
  14. print #2,"#vgm_txt":print #2,"#header:"
  15. '--- read file header
  16. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):fhead$=chr$(v0)+chr$(v1)+chr$(v2)+chr$(v3)
  17. txou$="fileheader:"+fhead$+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  18. '--- eof offset
  19. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  20. txou$="eofoffset:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  21. '--- version
  22. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  23. txou$="version:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  24. '--- sn76489clock
  25. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  26. txou$="sn76489clock:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  27. '--- ym2413clock
  28. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  29. txou$="ym2413clock:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  30. '--- gd3offset
  31. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  32. txou$="gd3offset:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  33. '--- totalsamples
  34. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  35. txou$="totalsamples:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  36. '--- loopoffset
  37. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  38. txou$="loopoffset:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  39. '--- loopsamples
  40. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  41. txou$="loopsamples:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  42. '--- rate
  43. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  44. txou$="rate:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  45. '--- sn76489feedback
  46. v0=readbyte(1):v1=readbyte(1):vle=(v1*256)+v0
  47. txou$="sn76489feedback:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+")":print #2,txou$
  48. '--- sn76489shiftregisterwidth
  49. v0=readbyte(1):vle=v0:txou$="sn76489shiftregisterwidth:"+str$(vle)+":("+hxfx$(v0,2)+")":print #2,txou$
  50. '--- reserved
  51. v0=readbyte(1):vle=v0:txou$="reserved:"+str$(vle)+":("+hxfx$(v0,2)+")":print #2,txou$
  52. '--- ym2612clock
  53. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  54. txou$="ym2612clock:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  55. '--- ym2151clock
  56. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  57. txou$="ym2151clock:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  58. '--- vgmdataoffset
  59. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  60. txou$="vgmdataoffset:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  61. '--- reserved
  62. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  63. txou$="reserved:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  64. '--- reserved
  65. v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0
  66. txou$="reserved:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  67. '-------- reading data
  68. print #2," ":print #2,"#data:"
  69. eosd=0:x7xsc=0:x8xsc=0:x7xfg=0:x8xfg=0:cmsc=0
  70. while (eof(1)=0 or eosd=0)
  71.   cmdo=readbyte(1):setcaption("command:"+str$(cmsc)):cmsc+=1
  72.   if int(cmdo/16)=7 and x7xfg=1 then:x7xfg=1:txou7x$+=","+str$(cmdo mod 16):x7xsc+=1:end if
  73.   if int(cmdo/16)=8 and x8xfg=1 then:x8xfg=1:txou8x$+=","+str$(cmdo mod 16):x8xsc+=1:end if
  74.   if int(cmdo/16)=7 and x7xfg=0 then:x7xfg=1:txou7x$="0x7X:waitsamples:"+str$(cmdo mod 16):x7xsc+=1:end if
  75.   if int(cmdo/16)=8 and x8xfg=0 then:x8xfg=1:txou8x$="0x8X:waitsamples:"+str$(cmdo mod 16):x8xsc+=1:end if
  76.   if int(cmdo/16)<>7 and x7xfg=1 then:print #2,txou7x$:x7xsc=0:x7xfg=0:end if
  77.   if int(cmdo/16)<>8 and x8xfg=1 then:print #2,txou8x$:x8xsc=0:x8xfg=0:end if
  78.   if int(cmdo/16)=7 and x7xsc>31 then:print #2,txou7x$:x7xsc=0:x7xfg=0:end if
  79.   if int(cmdo/16)=8 and x8xsc>31 then:print #2,txou8x$:x8xsc=0:x8xfg=0:end if
  80.   if cmdo=0x4f then:dd=readbyte(1)
  81.     txou$="0x4F:gamegearpsgstereo:"+hxfx$(dd,2):print #2,txou$:end if
  82.   if cmdo=0x50 then:dd=readbyte(1)
  83.     txou$="0x50:psgsn764xx:"+hxfx$(dd,2):print #2,txou$:end if
  84.   if cmdo=0x51 then:aa=readbyte(1):dd=readbyte(1)
  85.     txou$="0x51:ym2413valreg:"+hxfx$(aa,2)+":"+hxfx$(dd,2):print #2,txou$:end if
  86.   if cmdo=0x52 then:aa=readbyte(1):dd=readbyte(1)
  87.     txou$="0x52:ym2612port0valreg:"+hxfx$(aa,2)+":"+hxfx$(dd,2):print #2,txou$:end if
  88.   if cmdo=0x53 then:aa=readbyte(1):dd=readbyte(1)
  89.     txou$="0x53:ym2612port1valreg:"+hxfx$(aa,2)+":"+hxfx$(dd,2):print #2,txou$:end if
  90.   if cmdo=0x54 then:aa=readbyte(1):dd=readbyte(1)
  91.     txou$="0x54:ym2151valreg:"+hxfx$(aa,2)+":"+hxfx$(dd,2):print #2,txou$:end if
  92.   if cmdo=0x61 then:n0=readbyte(1):n1=readbyte(1)
  93.     txou$="0x61:waitsamples:"+str$(n0+(n1*256)):print #2,txou$:end if
  94.   if cmdo=0x62 then:print #2,"wait735samples":end if
  95.   if cmdo=0x63 then:print #2,"wait882samples":end if
  96.   if cmdo=0x66 then:print #2,"endsounddata":eosd=1:exit while:end if
  97.   if cmdo=0x67 then:
  98.     '- firstvalues
  99.     v0=readbyte(1):v1=readbyte(1):vle=(v1*256)+v0
  100.     txou$="v01:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+")":print #2,txou$
  101.     '- size of data
  102.     v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1)
  103.     vle=(v3*16777216)+(v2*65536)+(v1*256)+v0:datasz=vle
  104.     txou$="size:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$
  105.     '- hexdump of data
  106.     'print #2,"(hexdump_data:)":
  107.     txou$="hexdump:"
  108.     for i=0 to datasz-1:a1=readbyte(1):txou$=txou$+hxfx$(a1,2)
  109.       if (i mod 32)=31 then:print #2,txou$:txou$="hexdump:":end if:next
  110.     end if:wend
  111. print#2," ":print#2,"#file_tail:":i=1:txou$="hexdump:":tch$=""
  112. while eof(1)=0
  113.   a1=readbyte(1):txou$=txou$+hxfx$(a1,2)
  114.   if (a1>=32 and a1<=127) then:tch$+=chr$(a1):else:tch$+=".":end if
  115.   if (i-1 mod 16)=15 then:print #2,txou$+":"+tch$:txou$="hexdump:":tch$="":end if:i+=1:wend
  116. '---------------------------- emptying string and closing files ------
  117. print #2,txou$+":"+tch$:close #1: close #2
  118.  
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement