'--- vgm to txt converter - Paulo Silva - march '08 - GPL - runs on sdlBasic finp$="ghz.vgm": fout$=finp$+".txt" '--------------------------------------------------------------------- '--- define variables and arrays songname$="":mkflag$="":npatt=0:nflag=0 dim samplename$[32],samplelngth[32],sampleftune[32],samplevolum[32],samplereppt[32],samplerepln[32],pattseq[128] '----------------------------------------------- functions ----------- function hxfx$(a,b) tmpq$="":for i=1 to b:tmpq$+="0":next:tmpr$=ucase$(right$(tmpq$+hex$(a),b)):hxfx$=tmpr$:end function '--- open document open finp$ for input as #1:open fout$ for output as #2 '----------------------------------------------- converter code ------ '------ reading 64 bytes header print #2,"#vgm_txt":print #2,"#header:" '--- read file header v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):fhead$=chr$(v0)+chr$(v1)+chr$(v2)+chr$(v3) txou$="fileheader:"+fhead$+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- eof offset v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="eofoffset:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- version v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="version:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- sn76489clock v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="sn76489clock:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- ym2413clock v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="ym2413clock:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- gd3offset v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="gd3offset:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- totalsamples v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="totalsamples:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- loopoffset v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="loopoffset:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- loopsamples v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="loopsamples:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- rate v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="rate:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- sn76489feedback v0=readbyte(1):v1=readbyte(1):vle=(v1*256)+v0 txou$="sn76489feedback:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+")":print #2,txou$ '--- sn76489shiftregisterwidth v0=readbyte(1):vle=v0:txou$="sn76489shiftregisterwidth:"+str$(vle)+":("+hxfx$(v0,2)+")":print #2,txou$ '--- reserved v0=readbyte(1):vle=v0:txou$="reserved:"+str$(vle)+":("+hxfx$(v0,2)+")":print #2,txou$ '--- ym2612clock v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="ym2612clock:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- ym2151clock v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="ym2151clock:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- vgmdataoffset v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="vgmdataoffset:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- reserved v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="reserved:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '--- reserved v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1):vle=(v3*16777216)+(v2*65536)+(v1*256)+v0 txou$="reserved:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '-------- reading data print #2," ":print #2,"#data:" eosd=0:x7xsc=0:x8xsc=0:x7xfg=0:x8xfg=0:cmsc=0 while (eof(1)=0 or eosd=0) cmdo=readbyte(1):setcaption("command:"+str$(cmsc)):cmsc+=1 if int(cmdo/16)=7 and x7xfg=1 then:x7xfg=1:txou7x$+=","+str$(cmdo mod 16):x7xsc+=1:end if if int(cmdo/16)=8 and x8xfg=1 then:x8xfg=1:txou8x$+=","+str$(cmdo mod 16):x8xsc+=1:end if if int(cmdo/16)=7 and x7xfg=0 then:x7xfg=1:txou7x$="0x7X:waitsamples:"+str$(cmdo mod 16):x7xsc+=1:end if if int(cmdo/16)=8 and x8xfg=0 then:x8xfg=1:txou8x$="0x8X:waitsamples:"+str$(cmdo mod 16):x8xsc+=1:end if if int(cmdo/16)<>7 and x7xfg=1 then:print #2,txou7x$:x7xsc=0:x7xfg=0:end if if int(cmdo/16)<>8 and x8xfg=1 then:print #2,txou8x$:x8xsc=0:x8xfg=0:end if if int(cmdo/16)=7 and x7xsc>31 then:print #2,txou7x$:x7xsc=0:x7xfg=0:end if if int(cmdo/16)=8 and x8xsc>31 then:print #2,txou8x$:x8xsc=0:x8xfg=0:end if if cmdo=0x4f then:dd=readbyte(1) txou$="0x4F:gamegearpsgstereo:"+hxfx$(dd,2):print #2,txou$:end if if cmdo=0x50 then:dd=readbyte(1) txou$="0x50:psgsn764xx:"+hxfx$(dd,2):print #2,txou$:end if if cmdo=0x51 then:aa=readbyte(1):dd=readbyte(1) txou$="0x51:ym2413valreg:"+hxfx$(aa,2)+":"+hxfx$(dd,2):print #2,txou$:end if if cmdo=0x52 then:aa=readbyte(1):dd=readbyte(1) txou$="0x52:ym2612port0valreg:"+hxfx$(aa,2)+":"+hxfx$(dd,2):print #2,txou$:end if if cmdo=0x53 then:aa=readbyte(1):dd=readbyte(1) txou$="0x53:ym2612port1valreg:"+hxfx$(aa,2)+":"+hxfx$(dd,2):print #2,txou$:end if if cmdo=0x54 then:aa=readbyte(1):dd=readbyte(1) txou$="0x54:ym2151valreg:"+hxfx$(aa,2)+":"+hxfx$(dd,2):print #2,txou$:end if if cmdo=0x61 then:n0=readbyte(1):n1=readbyte(1) txou$="0x61:waitsamples:"+str$(n0+(n1*256)):print #2,txou$:end if if cmdo=0x62 then:print #2,"wait735samples":end if if cmdo=0x63 then:print #2,"wait882samples":end if if cmdo=0x66 then:print #2,"endsounddata":eosd=1:exit while:end if if cmdo=0x67 then: '- firstvalues v0=readbyte(1):v1=readbyte(1):vle=(v1*256)+v0 txou$="v01:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+")":print #2,txou$ '- size of data v0=readbyte(1):v1=readbyte(1):v2=readbyte(1):v3=readbyte(1) vle=(v3*16777216)+(v2*65536)+(v1*256)+v0:datasz=vle txou$="size:"+str$(vle)+":("+hxfx$(v0,2)+hxfx$(v1,2)+hxfx$(v2,2)+hxfx$(v3,2)+")":print #2,txou$ '- hexdump of data 'print #2,"(hexdump_data:)": txou$="hexdump:" for i=0 to datasz-1:a1=readbyte(1):txou$=txou$+hxfx$(a1,2) if (i mod 32)=31 then:print #2,txou$:txou$="hexdump:":end if:next end if:wend print#2," ":print#2,"#file_tail:":i=1:txou$="hexdump:":tch$="" while eof(1)=0 a1=readbyte(1):txou$=txou$+hxfx$(a1,2) if (a1>=32 and a1<=127) then:tch$+=chr$(a1):else:tch$+=".":end if if (i-1 mod 16)=15 then:print #2,txou$+":"+tch$:txou$="hexdump:":tch$="":end if:i+=1:wend '---------------------------- emptying string and closing files ------ print #2,txou$+":"+tch$:close #1: close #2