SHARE
TWEET

Vgm2VortexTrackerTxtAy_16.sdlbas

a guest Feb 25th, 2016 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/sdlbrt
  2. finp$="Vulgus_arcade_02_MainBgm.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 fout3$ for output as #2
  51. open fout2$ for output as #3
  52.  
  53. print #3,"[Module]"
  54. print #3,"VortexTrackerII=1"
  55. print #3,"Version=3.6"
  56. print #3,"Title="
  57. print #3,"Author="
  58. print #3,"NoteTable=2"
  59. print #3,"Speed=1"
  60. print #3,hsam$
  61. print #3," "
  62. print #3,"[Ornament1]":print #3,"L0":print #3," "
  63. print #3,"[Sample1]":print #3,"Tne +000_ +00_ F_ L":print #3," "
  64. print #3,"[Pattern0]"
  65.  
  66. '- read 256 dummy bytes from the header - i have to know how to deal with this better later
  67. '- the amount of header bytes depends on vgm format version
  68. for eee=0 to hdram-1:q0=readbyte(1):next  '- read offset byte first
  69.  
  70. txou1$="    #("+str$(0)+")"
  71.  
  72.  
  73.  
  74. while eof(1)=0
  75. q0=readbyte(1)
  76.  
  77.  
  78. '- delay 1 byte (1..16 samples)
  79. if bitwiseand(q0,0x70)=0x70 then
  80.   frmc=frmc+bitwiseand(q0,0xF)+1
  81.   txou1$="    #("+str$(frmc)+")"
  82.   'print #2,txou1$
  83.   end if
  84.  
  85. '- delay 3 bytes (0..65535 samples)
  86. if q0=0x61 then
  87.   q0=readbyte(1)
  88.   frmc=frmc+q0
  89.   q0=readbyte(1)
  90.   frmc=frmc+(q0*256)
  91.   txou1$="    #("+str$(frmc)+")"
  92.   'print #2,txou1$
  93.   end if
  94.  
  95. '- 1 ntsc frame delay, 735 samples
  96. if q0=0x62 then
  97.   frmc=frmc+735
  98.   txou1$="    #("+str$(frmc)+")"
  99.   'print #2,txou1$
  100.   end if
  101.  
  102. '- 1 pal frame delay, 882 samples
  103. if q0=0x63 then
  104.   frmc=frmc+882
  105.   txou1$="    #("+str$(frmc)+")"
  106.   'print #2,txou1$
  107.   end if
  108.  
  109.  
  110.  
  111. '- updates frameout pulses
  112. while frmr<frmc
  113.  
  114.   '- writes 1F in the first line of the first pattern
  115.   if (patc<1 and patid=0) then
  116.     ltxcr$=replace$(12,ltxcr$,"1F")
  117.     ltxcr$=replace$(26,ltxcr$,"1F")
  118.     ltxcr$=replace$(40,ltxcr$,"1F")
  119.     end if
  120.  
  121.   '- creates a new pattern  
  122.   if patc>(patsz-1) then:
  123.     print #3," "
  124.     patid=patid+1:patc=0
  125.     txou9$="[Pattern"+str$(patid)+"]"
  126.     print #3,txou9$
  127.     end if
  128.  
  129.   '- writes a pattern line in each frame
  130.   if trg=0 then
  131.     print #2,"--frameout-unchanged--"
  132.     print #3,ltxtm$
  133.   else
  134.     print #2,"--frameout--"
  135.     print #3,ltxcr$
  136.     ltxcr$=ltxtm$
  137.     trg=0
  138.     end if
  139.  
  140.   frmr=frmr+frmi
  141.   patc=patc+1
  142.   end while
  143.  
  144.  
  145.  
  146. '- token 0xA0 gets registers and values to AY-3-8910 output
  147. if q0=0xA0 then
  148.   q0=readbyte(1)
  149.  
  150.   '- channel 0, fine
  151.   if q0=0 then
  152.     q0=readbyte(1)
  153.     freq0= bitwiseor((bitwiseand(freq0,0xF00)),(bitwiseand(q0,0x0FF)))
  154.     ltxtm1$=ltxtm$
  155.     ltxtm2$=replace$(8,ltxtm1$,nttfrq$(freq0))
  156.     ltxcr$=replace$(8,ltxcr$,nttfrq$(freq0))
  157.     print #2,ltxtm2$
  158.     trg=1
  159.     end if
  160.  
  161.   '- channel 0, coarse
  162.   if q0=1 then
  163.     q0=readbyte(1)
  164.     freq0= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq0,0x0FF)) )
  165.     ltxtm1$=ltxtm$
  166.     ltxtm2$=replace$(8,ltxtm1$,nttfrq$(freq0))
  167.     ltxcr$=replace$(8,ltxcr$,nttfrq$(freq0))
  168.     print #2,ltxtm2$
  169.     trg=1
  170.     end if
  171.  
  172.   '- channel 1, fine
  173.   if q0=2 then
  174.     q0=readbyte(1)
  175.     freq1= bitwiseor ( (bitwiseand(freq1,0xF00)),(bitwiseand(q0,0x0FF)) )
  176.     ltxtm1$=ltxtm$
  177.     ltxtm2$=replace$(22,ltxtm1$,nttfrq$(freq1))
  178.     ltxcr$=replace$(22,ltxcr$,nttfrq$(freq1))
  179.     print #2,ltxtm2$
  180.     trg=1
  181.     end if
  182.  
  183.   '- channel 1, coarse
  184.   if q0=3 then
  185.     q0=readbyte(1)
  186.     freq1= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq1,0x0FF)) )
  187.     ltxtm1$=ltxtm$
  188.     ltxtm2$=replace$(22,ltxtm1$,nttfrq$(freq1))
  189.     ltxcr$=replace$(22,ltxcr$,nttfrq$(freq1))
  190.     print #2,ltxtm2$
  191.     trg=1
  192.     end if
  193.  
  194.   '- channel 2, fine
  195.   if q0=4 then
  196.     q0=readbyte(1)
  197.     freq2= bitwiseor ( (bitwiseand(freq2,0xF00)),(bitwiseand(q0,0x0FF)) )
  198.     ltxtm1$=ltxtm$
  199.     ltxtm2$=replace$(36,ltxtm1$,nttfrq$(freq2))
  200.     ltxcr$=replace$(36,ltxcr$,nttfrq$(freq2))
  201.     print #2,ltxtm2$
  202.     trg=1
  203.     end if
  204.  
  205.   '- channel 2, coarse
  206.   if q0=5 then
  207.     q0=readbyte(1)
  208.     freq2= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq2,0x0FF)) )
  209.     ltxtm1$=ltxtm$
  210.     ltxtm2$=replace$(36,ltxtm1$,nttfrq$(freq2))
  211.     ltxcr$=replace$(36,ltxcr$,nttfrq$(freq2))
  212.     print #2,ltxtm2$
  213.     trg=1
  214.     end if
  215.  
  216.   '?????
  217.   if q0=6 then
  218.     print #2,ltxtm$
  219.     end if
  220.  
  221.   '?????
  222.   'if q0=7 then
  223.   '  q0=readbyte(1)
  224.   '  ltxtm1$=ltxtm$
  225.   '  ltxtm2$=left$(ltxtm1$,31)+  right$(bin$(512+q0),8)  +right$(ltxtm1$,2)+txou1$
  226.   '  print #2,ltxtm2$
  227.   '  trg=1
  228.   '  end if
  229.  
  230.   '- channel 1, volume
  231.   if q0=8 then
  232.     q0=readbyte(1)
  233.     vol0= bitwiseand(q0,0xF)
  234.     ltxtm1$=ltxtm$
  235.     ltxtm2$=replace$(15,ltxtm1$,ucase$(right$(hex$(0x10+vol0),1)))
  236.     ltxcr$=replace$(15,ltxcr$,ucase$(right$(hex$(0x10+vol0),1)))
  237.     print #2,ltxtm2$
  238.     trg=1
  239.     end if
  240.  
  241.   '- channel 2, volume
  242.   if q0=9 then
  243.     q0=readbyte(1)
  244.     vol1= bitwiseand(q0,0xF)
  245.     ltxtm1$=ltxtm$
  246.     ltxtm2$=replace$(29,ltxtm1$,ucase$(right$(hex$(0x10+vol1),1)))
  247.     ltxcr$=replace$(29,ltxcr$,ucase$(right$(hex$(0x10+vol1),1)))
  248.     print #2,ltxtm2$
  249.     trg=1
  250.     end if
  251.  
  252.   '- channel 3, volume
  253.   if q0=10 then
  254.     q0=readbyte(1)
  255.     vol2= bitwiseand(q0,0xF)
  256.     ltxtm1$=ltxtm$
  257.     ltxtm2$=replace$(43,ltxtm1$,ucase$(right$(hex$(0x10+vol2),1)))
  258.     ltxcr$=replace$(43,ltxcr$,ucase$(right$(hex$(0x10+vol2),1)))
  259.     print #2,ltxtm2$
  260.     trg=1
  261.     end if
  262.  
  263.   end if
  264.  
  265. wend
  266. close #1:close #2:close #3
  267.  
  268. if debug=0 then:
  269.   shell("rm "+fout3$)
  270.   end if
RAW Paste Data
Top