SHARE
TWEET

Vgm2VortexTrackerTxtSn_17.sdlbas

a guest Feb 26th, 2016 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/sdlbrt
  2. finp$="MrGoemon_Arcade_02_Stage1.vgm"
  3. fout2$=finp$+"_vt.txt"
  4. fout3$=finp$+"_vt_debug.txt"
  5.  
  6. frmc=0:frmi=735:frmr=300:trg=0
  7. ltxtm$="....|..|--- .... ....|--- .... ....|--- .... ...."
  8. ltxcr$=ltxtm$
  9. freq0=0:freq1=0:freq2=0
  10. vol0=0:vol1=0:vol2=0
  11. freqq=0:debug=0
  12. patsz=64:patc=0:patid=0
  13. hdram=0x40:vgmv=0
  14. dim hdrv[256]
  15.  
  16. '- fix: 0x0FE=440hz=A-4
  17. function nttfrq$(freqb)
  18.   e$=   "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  19.   e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  20.   e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  21.   e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  22.   e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  23.   e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  24.   e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  25.   e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8"
  26.   tmq=141-(int((log(freqb)/log(2))*12))
  27.   if tmq<1 then:tmq=1:end if
  28.   if tmq>96 then:tmq=96:end if
  29.   return mid$(e$,(tmq*3)-2,3)
  30.   end function
  31.  
  32. open finp$ for input as #1
  33. for i=0 to 255
  34.   hdrv[i]=readbyte(1)
  35.   next
  36. close #1
  37.  
  38. hdram=0x040
  39. vgmv=hdrv[8]+hdrv[9]*256
  40. if vgmv>=0x0150 then:hdram=0x080:end if
  41. if vgmv>=0x0170 then:hdram=0x100:end if
  42.  
  43. ttsam=hdrv[0x18]+hdrv[0x19]*256+hdrv[0x1A]*65536+hdrv[0x1B]*16777216
  44. hsam$="PlayOrder=L0"
  45. for i=1 to (ttsam/(frmi*patsz))-1
  46.   hsam$=hsam$+","+str$(i)
  47.   next
  48.  
  49. open finp$ for input as #1
  50. open fout2$ for output as #2
  51. open fout3$ for output as #3
  52.  
  53. print #2,"[Module]"
  54. print #2,"VortexTrackerII=1"
  55. print #2,"Version=3.6"
  56. print #2,"Title="
  57. print #2,"Author="
  58. print #2,"NoteTable=2"
  59. print #2,"Speed=1"
  60. print #2,hsam$
  61. print #2," "
  62. print #2,"[Ornament1]":print #2,"L0":print #2," "
  63. print #2,"[Sample1]":print #2,"Tne +000_ +00_ F_ L":print #2," "
  64. print #2,"[Pattern0]"
  65.  
  66. '- the amount of header bytes depends on vgm format version
  67. for eee=0 to hdram-1:q0=readbyte(1):next  '- read offset byte first
  68. txou1$="    #("+str$(0)+")"
  69.  
  70. while eof(1)=0
  71. q0=readbyte(1)
  72.  
  73. '- delay 1 byte (1..16 samples)
  74. if bitwiseand(q0,0xF0)=0x70 then
  75.   frmc=frmc+bitwiseand(q0,0xF)+1
  76.   txou1$="    #("+str$(frmc)+")"
  77.   'print #3,txou1$
  78.   end if
  79.  
  80. '- delay 3 bytes (0..65535 samples)
  81. if q0=0x61 then
  82.   q0=readbyte(1)
  83.   frmc=frmc+q0
  84.   q0=readbyte(1)
  85.   frmc=frmc+(q0*256)
  86.   txou1$="    #("+str$(frmc)+")"
  87.   'print #3,txou1$
  88.   end if
  89.  
  90. '- 1 ntsc frame delay, 735 samples
  91. if q0=0x62 then
  92.   frmc=frmc+735
  93.   txou1$="    #("+str$(frmc)+")"
  94.   'print #3,txou1$
  95.   end if
  96.  
  97. '- 1 pal frame delay, 882 samples
  98. if q0=0x63 then
  99.   frmc=frmc+882
  100.   txou1$="    #("+str$(frmc)+")"
  101.   'print #3,txou1$
  102.   end if
  103.  
  104. '- updates frameout pulses
  105. while frmr<frmc
  106.  
  107.   '- writes 1F in the first line of the first pattern
  108.   if (patc<1 and patid=0) then
  109.     ltxcr$=replace$(12,ltxcr$,"1F")
  110.     ltxcr$=replace$(26,ltxcr$,"1F")
  111.     ltxcr$=replace$(40,ltxcr$,"1F")
  112.     end if
  113.  
  114.   '- creates a new pattern  
  115.   if patc>(patsz-1) then:
  116.     print #2," "
  117.     patid=patid+1:patc=0
  118.     txou9$="[Pattern"+str$(patid)+"]"
  119.     print #2,txou9$
  120.     end if
  121.  
  122.   '- writes a pattern line in each frame
  123.   if trg=0 then
  124.     print #3,"--frameout-unchanged--"
  125.     print #2,ltxtm$
  126.   else
  127.     print #3,"--frameout--"
  128.     print #2,ltxcr$
  129.     ltxcr$=ltxtm$
  130.     trg=0
  131.     end if
  132.  
  133.   frmr=frmr+frmi
  134.   patc=patc+1
  135.   end while
  136.  
  137. if q0=0x50 then
  138.   q0=readbyte(1)
  139.  
  140.   if bitwiseand (q0,128)=0 then
  141.  
  142.     '- channel 0 - coarse
  143.     if freqq=0 then
  144.       freq0= bitwiseor ( (bitwiseand(q0,0x3F))*16,(bitwiseand(freq0,0x00F)) )
  145.       ltxtm1$=ltxtm$
  146.       ltxtm2$=replace$(8,ltxtm1$,nttfrq$(freq0))
  147.       ltxcr$=replace$(8,ltxcr$,nttfrq$(freq0))
  148.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  149.       trg=1
  150.       end if
  151.  
  152.     '- channel 1 - coarse
  153.     if freqq=1 then
  154.       freq1= bitwiseor ( (bitwiseand(q0,0x3F))*16,(bitwiseand(freq1,0x00F)) )
  155.       ltxtm1$=ltxtm$
  156.       ltxtm2$=replace$(22,ltxtm1$,nttfrq$(freq1))
  157.       ltxcr$=replace$(22,ltxcr$,nttfrq$(freq1))
  158.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  159.       trg=1
  160.       end if
  161.  
  162.     '- channel 2 - coarse
  163.     if freqq=2 then
  164.       freq2= bitwiseor ( (bitwiseand(q0,0x3F))*16,(bitwiseand(freq2,0x00F)) )
  165.       ltxtm1$=ltxtm$
  166.       ltxtm2$=replace$(36,ltxtm1$,nttfrq$(freq2))
  167.       ltxcr$=replace$(36,ltxcr$,nttfrq$(freq2))
  168.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  169.       trg=1
  170.       end if
  171.  
  172.     end if
  173.  
  174.   if bitwiseand (q0,128)=128 then
  175.  
  176.     '- channel 0 - fine
  177.     if bitwiseand (q0,0xF0)=0x80  then '- tone ch0
  178.       freqq=0
  179.       freq0= bitwiseor ( (bitwiseand(freq0,0xFF0)),(bitwiseand(q0,0x00F)) )
  180.       ltxtm1$=ltxtm$
  181.       ltxtm2$=replace$(8,ltxtm1$,nttfrq$(freq0))
  182.       ltxcr$=replace$(8,ltxcr$,nttfrq$(freq0))
  183.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  184.       trg=1
  185.       end if
  186.  
  187.     '- channel 1 - fine
  188.     if bitwiseand (q0,0xF0)=0xA0  then '- tone ch1
  189.       freqq=1
  190.       freq1= bitwiseor ( (bitwiseand(freq1,0xFF0)),(bitwiseand(q0,0x00F)) )
  191.       ltxtm1$=ltxtm$
  192.       ltxtm2$=replace$(22,ltxtm1$,nttfrq$(freq1))
  193.       ltxcr$=replace$(22,ltxcr$,nttfrq$(freq1))
  194.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  195.       trg=1
  196.       end if
  197.  
  198.     '- channel 2 - fine
  199.     if bitwiseand (q0,0xF0)=0xC0  then '- tone ch2
  200.       freqq=2
  201.       freq2= bitwiseor ( (bitwiseand(freq2,0xFF0)),(bitwiseand(q0,0x00F)) )
  202.       ltxtm1$=ltxtm$
  203.       ltxtm2$=replace$(36,ltxtm1$,nttfrq$(freq2))
  204.       ltxcr$=replace$(36,ltxcr$,nttfrq$(freq2))
  205.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  206.       trg=1
  207.       end if
  208.  
  209.     'if bitwiseand (q0,0xF0)=0xE0  then '- freq noise
  210.     '  end if
  211.  
  212.     '- channel 0 - volume
  213.     if bitwiseand (q0,0xF0)=0x90  then '- volume ch0
  214.       'freqq=0
  215.       vol0=15-bitwiseand(q0,0xF)
  216.       ltxtm1$=ltxtm$
  217.       ltxtm2$=replace$(15,ltxtm1$,ucase$(right$(hex$(0x10+vol0),1)))
  218.       ltxcr$=replace$(15,ltxcr$,ucase$(right$(hex$(0x10+vol0),1)))
  219.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  220.       trg=1
  221.       end if
  222.  
  223.     '- channel 1 - volume
  224.     if bitwiseand (q0,0xF0)=0xB0  then '- volume ch1
  225.       'freqq=1
  226.       vol1=15-bitwiseand(q0,0xF)
  227.       ltxtm1$=ltxtm$
  228.       ltxtm2$=replace$(29,ltxtm1$,ucase$(right$(hex$(0x10+vol1),1)))
  229.       ltxcr$=replace$(29,ltxcr$,ucase$(right$(hex$(0x10+vol1),1)))
  230.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  231.       trg=1
  232.       end if
  233.  
  234.     '- channel 2 - volume
  235.     if bitwiseand (q0,0xF0)=0xD0  then '- volume ch2
  236.       'freqq=2
  237.       vol2=15-bitwiseand(q0,0xF)
  238.       ltxtm1$=ltxtm$
  239.       ltxtm2$=replace$(43,ltxtm1$,ucase$(right$(hex$(0x10+vol2),1)))
  240.       ltxcr$=replace$(43,ltxcr$,ucase$(right$(hex$(0x10+vol2),1)))
  241.       print #3,ltxtm2$+"    #("+str$(frmc)+")"
  242.       trg=1
  243.       end if
  244.  
  245.     'if bitwiseand (q0,0xF0)=0xF0  then '- volume ch3
  246.     '  end if
  247.  
  248.     end if
  249.  
  250.   end if
  251.  
  252. wend
  253. close #1:close #2:close #3
  254.  
  255. if debug=0 then:
  256.   shell("rm "+fout3$)
  257.   end if
RAW Paste Data
Top