Advertisement
Guest User

Vgm2VortexTrackerTxtAy_19.sdlbas

a guest
Feb 26th, 2016
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/sdlbrt
  2. finp$="tune.vgm"
  3.  
  4. '- .vgm to VortexTracker .txt converter - AY-3-8910 version
  5. '- copyleft Paulo Silva, feb'16
  6. '-------------------------------
  7. '- bugs:
  8. '- - an acute sound might appear because an issue related to volume 0 that VortexTracker doesnt support, R-- note used instead (and the converter should store which note/frequency is for a probable volume changing, and set back the note/frequency value back)
  9. '- - doesn't read yet the author/title information
  10. '- - 'L' will be useful for the loop point location
  11. '- - probably will need a sample counter before converting
  12. '- - missing noise support
  13. '- - frequncy inaccuracy from the germanic notation formula probably fixed, needs more testing
  14. '-------------------------------
  15.  
  16. ltxtm$="....|..|--- .... ....|--- .... ....|--- .... ....":ltxcr$=ltxtm$
  17. freq0=0:freq1=0:freq2=0:vol0=0:vol1=0:vol2=0
  18. patsz=64:patc=0:patid=0:freqq=0
  19. hdram=0x40:vgmv=0:veof=0
  20. dim hdrv[256]
  21.  
  22. if argc>2 then:finp$=argv(2):end if
  23. fout2$=finp$+"_vt.txt":fout3$=finp$+"_vt_debug.txt"
  24.  
  25. frmc=0:frmr=300:trg=0
  26.  
  27. frmi=735
  28. if argc>3 then:
  29.   if argv(3)="1" or ucase$(argv(2))="-PAL" then
  30.     frmi=882:end if:end if
  31.  
  32. debug=0
  33. if argc>4 then:
  34.   if argv(4)="1" or ucase$(argv(2))="-DEBUG" then
  35.     debug=1:end if:end if
  36.  
  37. '- fix: 0x0FE=440hz=A-4
  38. function nttfrq$(freqb)
  39.   e$=   "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  40.   e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  41.   e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  42.   e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  43.   e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  44.   e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  45.   e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  46.   e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8---"
  47.   tmq=141-(int((log(freqb*.99)/log(2))*12))
  48.   if tmq<1 then:tmq=1:end if
  49.   if tmq>97 then:tmq=97:end if
  50.   return mid$(e$,(tmq*3)-2,3)
  51.   end function
  52.  
  53. open finp$ for input as #1
  54. for i=0 to 255
  55.   hdrv[i]=readbyte(1)
  56.   next
  57. close #1
  58.  
  59. hdram=0x040
  60. vgmv=hdrv[8]+hdrv[9]*256
  61. if vgmv>=0x0150 then:hdram=0x080:end if
  62. if vgmv>=0x0170 then:hdram=0x100:end if
  63.  
  64. '- wrong information???
  65. ttsam=hdrv[0x18]+hdrv[0x19]*256+hdrv[0x1A]*65536+hdrv[0x1B]*16777216
  66. hsam$="PlayOrder=L0"
  67. for i=1 to (ttsam/(frmi*patsz))-1
  68.   hsam$=hsam$+","+str$(i)
  69.   next
  70.  
  71. open finp$ for input as #1
  72. open fout2$ for output as #2
  73. open fout3$ for output as #3
  74.  
  75. print #2,"[Module]"
  76. print #2,"VortexTrackerII=1"
  77. print #2,"Version=3.6"
  78. print #2,"Title="
  79. print #2,"Author="
  80. print #2,"NoteTable=2"
  81. print #2,"Speed=1"
  82. print #2,hsam$
  83. print #2," "
  84. print #2,"[Ornament1]":print #2,"L0":print #2," "
  85. print #2,"[Sample1]":print #2,"Tne +000_ +00_ F_ L":print #2," "
  86. print #2,"[Pattern0]"
  87.  
  88. '- the amount of header bytes depends on vgm format version
  89. for eee=0 to hdram-1:q0=readbyte(1):next  '- read offset byte first
  90. txou1$="    #("+str$(0)+")"
  91.  
  92. while veof=0:
  93.   q0=readbyte(1)
  94.  
  95.   '- vgm eof command
  96.   if q0=0x66 then:
  97.     veof=1
  98.     print #3,"--vgm-eof--"
  99.     print #2," "
  100.     end if
  101.  
  102.   '- delay 1 byte (1..16 samples)
  103.   if bitwiseand(q0,0x70)=0x70 then
  104.     frmc=frmc+bitwiseand(q0,0xF)+1
  105.     txou1$="    #("+str$(frmc)+")"
  106.     'print #3,txou1$
  107.     end if
  108.  
  109.   '- delay 3 bytes (0..65535 samples)
  110.   if q0=0x61 then
  111.     q0=readbyte(1)
  112.     frmc=frmc+q0
  113.     q0=readbyte(1)
  114.     frmc=frmc+(q0*256)
  115.     txou1$="    #("+str$(frmc)+")"
  116.     'print #3,txou1$
  117.     end if
  118.  
  119.   '- 1 ntsc frame delay, 735 samples
  120.   if q0=0x62 then
  121.     frmc=frmc+735
  122.     txou1$="    #("+str$(frmc)+")"
  123.     'print #3,txou1$
  124.     end if
  125.  
  126.   '- 1 pal frame delay, 882 samples
  127.   if q0=0x63 then
  128.     frmc=frmc+882
  129.     txou1$="    #("+str$(frmc)+")"
  130.     'print #3,txou1$
  131.     end if
  132.  
  133.  
  134.  
  135.   '- updates frameout pulses
  136.   while frmr<frmc
  137.  
  138.     '- writes 1F in the first line of the first pattern
  139.     if (patc<1 and patid=0) then
  140.       ltxcr$=replace$(12,ltxcr$,"1F")
  141.       ltxcr$=replace$(26,ltxcr$,"1F")
  142.       ltxcr$=replace$(40,ltxcr$,"1F")
  143.       end if
  144.  
  145.     '- creates a new pattern  
  146.     if patc>(patsz-1) then:
  147.       print #2," "
  148.       patid=patid+1:patc=0
  149.       txou9$="[Pattern"+str$(patid)+"]"
  150.       print #2,txou9$
  151.       end if
  152.  
  153.     '- writes a pattern line in each frame
  154.     if trg=0 then
  155.       print #3,"--frameout-unchanged--"
  156.       print #2,ltxtm$
  157.     else
  158.       print #3,"--frameout--"
  159.       print #2,ltxcr$
  160.       ltxcr$=ltxtm$
  161.       trg=0
  162.       end if
  163.  
  164.     frmr=frmr+frmi
  165.     patc=patc+1
  166.     end while
  167.  
  168.  
  169.  
  170.   '- token 0xA0 gets registers and values to AY-3-8910 output
  171.   if q0=0xA0 then
  172.     q0=readbyte(1)
  173.  
  174.     '- channel 0, fine
  175.     if q0=0 then
  176.       q0=readbyte(1)
  177.       freq0= bitwiseor((bitwiseand(freq0,0xF00)),(bitwiseand(q0,0x0FF)))
  178.       ltxtm1$=ltxtm$
  179.       ltxtm2$=replace$(8,ltxtm1$,nttfrq$(freq0))
  180.       ltxcr$=replace$(8,ltxcr$,nttfrq$(freq0))
  181.       print #3,ltxtm2$
  182.       trg=1
  183.       end if
  184.  
  185.     '- channel 0, coarse
  186.     if q0=1 then
  187.       q0=readbyte(1)
  188.       freq0= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq0,0x0FF)) )
  189.       ltxtm1$=ltxtm$
  190.       ltxtm2$=replace$(8,ltxtm1$,nttfrq$(freq0))
  191.       ltxcr$=replace$(8,ltxcr$,nttfrq$(freq0))
  192.       print #3,ltxtm2$
  193.       trg=1
  194.       end if
  195.  
  196.     '- channel 1, fine
  197.     if q0=2 then
  198.       q0=readbyte(1)
  199.       freq1= bitwiseor ( (bitwiseand(freq1,0xF00)),(bitwiseand(q0,0x0FF)) )
  200.       ltxtm1$=ltxtm$
  201.       ltxtm2$=replace$(22,ltxtm1$,nttfrq$(freq1))
  202.       ltxcr$=replace$(22,ltxcr$,nttfrq$(freq1))
  203.       print #3,ltxtm2$
  204.       trg=1
  205.       end if
  206.  
  207.     '- channel 1, coarse
  208.     if q0=3 then
  209.       q0=readbyte(1)
  210.       freq1= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq1,0x0FF)) )
  211.       ltxtm1$=ltxtm$
  212.       ltxtm2$=replace$(22,ltxtm1$,nttfrq$(freq1))
  213.       ltxcr$=replace$(22,ltxcr$,nttfrq$(freq1))
  214.       print #3,ltxtm2$
  215.       trg=1
  216.       end if
  217.  
  218.     '- channel 2, fine
  219.     if q0=4 then
  220.       q0=readbyte(1)
  221.       freq2= bitwiseor ( (bitwiseand(freq2,0xF00)),(bitwiseand(q0,0x0FF)) )
  222.       ltxtm1$=ltxtm$
  223.       ltxtm2$=replace$(36,ltxtm1$,nttfrq$(freq2))
  224.       ltxcr$=replace$(36,ltxcr$,nttfrq$(freq2))
  225.       print #3,ltxtm2$
  226.       trg=1
  227.       end if
  228.  
  229.     '- channel 2, coarse
  230.     if q0=5 then
  231.       q0=readbyte(1)
  232.       freq2= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq2,0x0FF)) )
  233.       ltxtm1$=ltxtm$
  234.       ltxtm2$=replace$(36,ltxtm1$,nttfrq$(freq2))
  235.       ltxcr$=replace$(36,ltxcr$,nttfrq$(freq2))
  236.       print #3,ltxtm2$
  237.       trg=1
  238.       end if
  239.  
  240.     '?????
  241.     if q0=6 then
  242.       print #3,ltxtm$
  243.       end if
  244.  
  245.     '?????
  246.     'if q0=7 then
  247.     '  q0=readbyte(1)
  248.     '  ltxtm1$=ltxtm$
  249.     '  ltxtm2$=left$(ltxtm1$,31)+  right$(bin$(512+q0),8)  +right$(ltxtm1$,2)+txou1$
  250.     '  print #3,ltxtm2$
  251.     '  trg=1
  252.     '  end if
  253.  
  254.     '- channel 1, volume
  255.     if q0=8 then
  256.       q0=readbyte(1)
  257.       vol0= bitwiseand(q0,0xF)
  258.       ltxtm1$=ltxtm$
  259.       ltxtm2$=replace$(15,ltxtm1$,ucase$(right$(hex$(0x10+vol0),1)))
  260.       ltxcr$=replace$(15,ltxcr$,ucase$(right$(hex$(0x10+vol0),1)))
  261.       print #3,ltxtm2$
  262.       trg=1
  263.       end if
  264.  
  265.     '- channel 2, volume
  266.     if q0=9 then
  267.       q0=readbyte(1)
  268.       vol1= bitwiseand(q0,0xF)
  269.       ltxtm1$=ltxtm$
  270.       ltxtm2$=replace$(29,ltxtm1$,ucase$(right$(hex$(0x10+vol1),1)))
  271.       ltxcr$=replace$(29,ltxcr$,ucase$(right$(hex$(0x10+vol1),1)))
  272.       print #3,ltxtm2$
  273.       trg=1
  274.       end if
  275.  
  276.     '- channel 3, volume
  277.     if q0=10 then
  278.       q0=readbyte(1)
  279.       vol2= bitwiseand(q0,0xF)
  280.       ltxtm1$=ltxtm$
  281.       ltxtm2$=replace$(43,ltxtm1$,ucase$(right$(hex$(0x10+vol2),1)))
  282.       ltxcr$=replace$(43,ltxcr$,ucase$(right$(hex$(0x10+vol2),1)))
  283.       print #3,ltxtm2$
  284.       trg=1
  285.       end if
  286.  
  287.     end if
  288.  
  289.   if eof(1)<>0 then:veof=1:end if
  290.   wend
  291.  
  292. close #1:close #2:close #3
  293.  
  294. if debug=0 then:
  295.   shell("rm "+fout3$)
  296.   end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement