Vgm2VortexTrackerTxtSn76489.sdlbas 7.8 KB

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