Vgm2FamiTrackerTxtC03051x2.sdlbasic 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. #! /usr/bin/sdlbrt
  2. finp$="tune.vgm"
  3. '- .vgm to FamiTracker .txt converter - C03051 (x2) version
  4. '- copyleft Paulo Silva, oct'20
  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. '- - doesn't 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. ' "....|..|--- .... ....|--- .... ....|--- .... ...."
  15. ' "ROW 00 : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ..."
  16. 'ltxtm$="....|..|--- .... ....|--- .... ....|--- .... ....":ltxcr$=ltxtm$
  17. ltxtm$="ROW .. : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ... : ... .. . ...":ltxcr$=ltxtm$
  18. freq0=0:freq1=0:freq2=0:vol0=0:vol1=0:vol2=0
  19. patsz=64:patc=0:patid=0:freqq=0
  20. hdram=0x40:vgmv=0:veof=0
  21. dim hdrv[256]
  22. if argc>2 then:finp$=argv(2):end if
  23. fout2$=finp$+"_famitracker.txt":fout3$=finp$+"_famitracker_debug.txt"
  24. frmc=0:frmr=300:trg=0
  25. frmi=735
  26. if argc>3 then:
  27. if argv(3)="1" or ucase$(argv(2))="-PAL" then
  28. frmi=882:end if:end if
  29. debug=0
  30. if argc>4 then:
  31. if argv(4)="1" or ucase$(argv(2))="-DEBUG" then
  32. debug=1:end if:end if
  33. '- fix: 0x0FE=440hz=A-4
  34. function nttfrq$(freqb)
  35. e$= "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  36. e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  37. e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  38. e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  39. e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  40. e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  41. e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  42. e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8..."
  43. tmq=(119-(int((log(freqb*.99)/log(2))*12)))
  44. if tmq<1 then:tmq=1:end if
  45. if tmq>84 then:tmq=84:end if
  46. return mid$(e$,(tmq*3)-2,3)
  47. end function
  48. open finp$ for input as #1
  49. for i=0 to 255
  50. hdrv[i]=readbyte(1)
  51. next
  52. close #1
  53. hdram=0x040
  54. vgmv=hdrv[8]+hdrv[9]*256
  55. if vgmv>=0x0150 then:hdram=0x080:end if
  56. if vgmv>=0x0170 then:hdram=0x100:end if
  57. '- wrong information???
  58. ttsam=hdrv[0x18]+hdrv[0x19]*256+hdrv[0x1A]*65536+hdrv[0x1B]*16777216
  59. hsam$="PlayOrder=L0"
  60. for i=1 to (ttsam/(frmi*patsz))-1
  61. hsam$=hsam$+","+str$(i)
  62. next
  63. open finp$ for input as #1
  64. open fout2$ for output as #2
  65. open fout3$ for output as #3
  66. print #2,"# FamiTracker text format":print #2,""
  67. print #2,"# Module information"
  68. print #2,"TITLE \"\""
  69. print #2,"AUTHOR \"\""
  70. print #2,"COPYRIGHT \"\"":print #2,""
  71. print #2,"# Module comment"
  72. print #2,"COMMENT \"\"":print #2,""
  73. print #2,"# Global settings"
  74. print #2,"MACHINE 0"
  75. print #2,"FRAMERATE 0"
  76. print #2,"EXPANSION 16"
  77. print #2,"VIBRATO 1"
  78. print #2,"SPLIT 32":print #2,""
  79. print #2,"# Namco 163 global settings"
  80. print #2,"N163CHANNELS 8":print #2,""
  81. print #2,"# Macros":print #2,""
  82. print #2,"# DPCM samples":print #2,""
  83. print #2,"# Detune settings":print #2,""
  84. print #2,"# Grooves":print #2,""
  85. print #2,"# Tracks using default groove"
  86. print #2,"# Instruments"
  87. 'print #2,"INST2A03 0 -1 -1 -1 -1 -1 \"instrument01\"":print #2,""
  88. print #2,"INSTN163 0 -1 -1 -1 -1 -1 32 0 1 \"New instrument\""
  89. print #2,"N163WAVE 0 0 : 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
  90. print #2,"# Tracks":print #2,""
  91. print #2,"TRACK "+str$(patsz)+" 1 128 \"test\""
  92. print #2,"COLUMNS : 1 1 1 1 1 1 1 1 1 1 1 1 1":print #2,""
  93. 'print #2,"ORDER 00 : 00 00 00 00 00 00 00 00 00 00 00 00 00"
  94. 'print #2,"ORDER 01 : 01 01 01 01 01 01 01 01 01 01 01 01 01"
  95. 'print #2,"ORDER 02 : 02 02 02 02 02 02 02 02 02 02 02 02 02"
  96. 'print #2,"ORDER 03 : 03 03 03 03 03 03 03 03 03 03 03 03 03"
  97. 'print #2,"ORDER 04 : 04 04 04 04 04 04 04 04 04 04 04 04 04"
  98. 'print #2,"ORDER 05 : 05 05 05 05 05 05 05 05 05 05 05 05 05"
  99. 'print #2,"ORDER 06 : 06 06 06 06 06 06 06 06 06 06 06 06 06"
  100. 'print #2,"ORDER 07 : 07 07 07 07 07 07 07 07 07 07 07 07 07"
  101. 'print #2,"ORDER 08 : 08 08 08 08 08 08 08 08 08 08 08 08 08"
  102. 'print #2,"ORDER 09 : 09 09 09 09 09 09 09 09 09 09 09 09 09"
  103. 'print #2,"ORDER 0A : 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A 0A"
  104. 'print #2,"ORDER 0B : 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B 0B"
  105. 'print #2,"ORDER 0C : 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C 0C"
  106. 'print #2,"ORDER 0D : 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D 0D"
  107. 'print #2,"ORDER 0E : 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E 0E"
  108. 'print #2,"ORDER 0F : 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F 0F"
  109. 'print #2,""
  110. 'print #2,"[Module]"
  111. 'print #2,"VortexTrackerII=1"
  112. 'print #2,"Version=3.6"
  113. 'print #2,"Title="
  114. 'print #2,"Author="
  115. 'print #2,"NoteTable=2"
  116. 'print #2,"Speed=1"
  117. 'print #2,hsam$
  118. 'print #2," "
  119. 'print #2,"[Ornament1]":print #2,"L0":print #2," "
  120. 'print #2,"[Sample1]":print #2,"Tne +000_ +00_ F_ L":print #2," "
  121. print #2,"Pattern 00"
  122. '- the amount of header bytes depends on vgm format version
  123. for eee=0 to hdram-1:q0=readbyte(1):next '- read offset byte first
  124. txou1$=" #("+str$(0)+")"
  125. while veof=0:
  126. q0=readbyte(1)
  127. '- vgm eof command
  128. if q0=0x66 then:
  129. veof=1
  130. print #3,"--vgm-eof--"
  131. print #2,""
  132. print #2,"# End of export"
  133. end if
  134. '- delay 1 byte (1..16 samples)
  135. if bitwiseand(q0,0x70)=0x70 then
  136. frmc=frmc+bitwiseand(q0,0xF)+1
  137. txou1$=" #("+str$(frmc)+")"
  138. 'print #3,txou1$
  139. end if
  140. '- delay 3 bytes (0..65535 samples)
  141. if q0=0x61 then
  142. q0=readbyte(1)
  143. frmc=frmc+q0
  144. q0=readbyte(1)
  145. frmc=frmc+(q0*256)
  146. txou1$=" #("+str$(frmc)+")"
  147. 'print #3,txou1$
  148. end if
  149. '- 1 ntsc frame delay, 735 samples
  150. if q0=0x62 then
  151. frmc=frmc+735
  152. txou1$=" #("+str$(frmc)+")"
  153. 'print #3,txou1$
  154. end if
  155. '- 1 pal frame delay, 882 samples
  156. if q0=0x63 then
  157. frmc=frmc+882
  158. txou1$=" #("+str$(frmc)+")"
  159. 'print #3,txou1$
  160. end if
  161. '- updates frameout pulses
  162. while frmr<frmc
  163. '- writes 1F in the first line of the first pattern
  164. 'if (patc<1 and patid=0) then
  165. 'ltxcr$=replace$(12,ltxcr$,"1F")
  166. 'ltxcr$=replace$(26,ltxcr$,"1F")
  167. 'ltxcr$=replace$(40,ltxcr$,"1F")
  168. 'end if
  169. '- creates a new pattern
  170. if patc>(patsz-1) then:
  171. print #2," "
  172. patid=patid+1:patc=0
  173. 'txou9$="Pattern "+str$(patid)+"]"
  174. txou9$="Pattern "+right$("00000"+ucase$(hex$(patid)),2)
  175. print #2,txou9$
  176. end if
  177. '- writes a pattern line in each frame
  178. if trg=0 then
  179. print #3,"--frameout-unchanged--"
  180. 'print #2,ltxtm$
  181. ltxcr$=ltxtm$
  182. ltxcr$=replace$(4,ltxcr$, right$("00000"+ucase$(hex$(patc)),2) ) '?????? <-----
  183. print #2,ltxcr$
  184. else
  185. print #3,"--frameout--"
  186. ltxcr$=replace$(4,ltxcr$, right$("00000"+ucase$(hex$(patc)),2) ) '?????? <-----
  187. print #2,ltxcr$
  188. ltxcr$=ltxtm$
  189. trg=0
  190. end if
  191. frmr=frmr+frmi
  192. patc=patc+1
  193. end while
  194. '- token 0xBB gets registers and values to C03051 output
  195. if q0=0xBB then
  196. q0=readbyte(1)
  197. '- channel 0, fine
  198. if q0=0 then
  199. q0=readbyte(1)
  200. freq0=q0 ' bitwiseor((bitwiseand(freq0,0xF00)),(bitwiseand(q0,0x0FF)))
  201. ltxtm1$=ltxtm$
  202. ltxtm2$=replace$(9+75,ltxtm1$,nttfrq$(freq0))
  203. ltxcr$=replace$(9+75,ltxcr$,nttfrq$(freq0))
  204. ltxcr$=replace$(13+75,ltxcr$,"00")
  205. print #3,ltxtm2$
  206. trg=1
  207. end if
  208. '- channel 1, fine
  209. if q0=2 then
  210. q0=readbyte(1)
  211. freq1=q0 ' bitwiseor ( (bitwiseand(freq1,0xF00)),(bitwiseand(q0,0x0FF)) )
  212. ltxtm1$=ltxtm$
  213. ltxtm2$=replace$(24+75,ltxtm1$,nttfrq$(freq1))
  214. ltxcr$=replace$(24+75,ltxcr$,nttfrq$(freq1))
  215. ltxcr$=replace$(28+75,ltxcr$,"00")
  216. print #3,ltxtm2$
  217. trg=1
  218. end if
  219. '- channel 2, fine
  220. if q0=4 then
  221. q0=readbyte(1)
  222. freq2=q0 ' bitwiseor ( (bitwiseand(freq2,0xF00)),(bitwiseand(q0,0x0FF)) )
  223. ltxtm1$=ltxtm$
  224. ltxtm2$=replace$(39+75,ltxtm1$,nttfrq$(freq2))
  225. ltxcr$=replace$(39+75,ltxcr$,nttfrq$(freq2))
  226. ltxcr$=replace$(43+75,ltxcr$,"00")
  227. print #3,ltxtm2$
  228. trg=1
  229. end if
  230. '- channel 3, fine
  231. if q0=6 then
  232. q0=readbyte(1)
  233. freq3=q0 ' bitwiseor ( (bitwiseand(freq2,0xF00)),(bitwiseand(q0,0x0FF)) )
  234. ltxtm1$=ltxtm$
  235. ltxtm2$=replace$(54+75,ltxtm1$,nttfrq$(freq2))
  236. ltxcr$=replace$(54+75,ltxcr$,nttfrq$(freq2))
  237. ltxcr$=replace$(58+75,ltxcr$,"00")
  238. print #3,ltxtm2$
  239. trg=1
  240. end if
  241. '- channel 4, fine
  242. if q0=0x80 then
  243. q0=readbyte(1)
  244. freq0=q0 ' bitwiseor((bitwiseand(freq0,0xF00)),(bitwiseand(q0,0x0FF)))
  245. ltxtm1$=ltxtm$
  246. ltxtm2$=replace$(69+75,ltxtm1$,nttfrq$(freq0))
  247. ltxcr$=replace$(69+75,ltxcr$,nttfrq$(freq0))
  248. ltxcr$=replace$(73+75,ltxcr$,"00")
  249. print #3,ltxtm2$
  250. trg=1
  251. end if
  252. '- channel 5, fine
  253. if q0=0x82 then
  254. q0=readbyte(1)
  255. freq1=q0 ' bitwiseor ( (bitwiseand(freq1,0xF00)),(bitwiseand(q0,0x0FF)) )
  256. ltxtm1$=ltxtm$
  257. ltxtm2$=replace$(84+75,ltxtm1$,nttfrq$(freq1))
  258. ltxcr$=replace$(84+75,ltxcr$,nttfrq$(freq1))
  259. ltxcr$=replace$(88+75,ltxcr$,"00")
  260. print #3,ltxtm2$
  261. trg=1
  262. end if
  263. '- channel 6, fine
  264. if q0=0x84 then
  265. q0=readbyte(1)
  266. freq2=q0 ' bitwiseor ( (bitwiseand(freq2,0xF00)),(bitwiseand(q0,0x0FF)) )
  267. ltxtm1$=ltxtm$
  268. ltxtm2$=replace$(99+75,ltxtm1$,nttfrq$(freq2))
  269. ltxcr$=replace$(99+75,ltxcr$,nttfrq$(freq2))
  270. ltxcr$=replace$(103+75,ltxcr$,"00")
  271. print #3,ltxtm2$
  272. trg=1
  273. end if
  274. '- channel 7, fine
  275. if q0=0x86 then
  276. q0=readbyte(1)
  277. freq3=q0 ' bitwiseor ( (bitwiseand(freq2,0xF00)),(bitwiseand(q0,0x0FF)) )
  278. ltxtm1$=ltxtm$
  279. ltxtm2$=replace$(114+75,ltxtm1$,nttfrq$(freq2))
  280. ltxcr$=replace$(114+75,ltxcr$,nttfrq$(freq2))
  281. ltxcr$=replace$(118+75,ltxcr$,"00")
  282. print #3,ltxtm2$
  283. trg=1
  284. end if
  285. '?????
  286. if q0=6 then
  287. print #3,ltxtm$
  288. end if
  289. '?????
  290. 'if q0=7 then
  291. ' q0=readbyte(1)
  292. ' ltxtm1$=ltxtm$
  293. ' ltxtm2$=left$(ltxtm1$,31)+ right$(bin$(512+q0),8) +right$(ltxtm1$,2)+txou1$
  294. ' print #3,ltxtm2$
  295. ' trg=1
  296. ' end if
  297. '- channel 1, volume
  298. if q0=1 then
  299. q0=readbyte(1)
  300. vol0= bitwiseand(q0,0xF)
  301. ltxtm1$=ltxtm$
  302. ltxtm2$=replace$(16+75,ltxtm1$,ucase$(right$(hex$(0x10+vol0),1)))
  303. ltxcr$=replace$(16+75,ltxcr$,ucase$(right$(hex$(0x10+vol0),1)))
  304. print #3,ltxtm2$
  305. trg=1
  306. end if
  307. '- channel 2, volume
  308. if q0=3 then
  309. q0=readbyte(1)
  310. vol1= bitwiseand(q0,0xF)
  311. ltxtm1$=ltxtm$
  312. ltxtm2$=replace$(31+75,ltxtm1$,ucase$(right$(hex$(0x10+vol1),1)))
  313. ltxcr$=replace$(31+75,ltxcr$,ucase$(right$(hex$(0x10+vol1),1)))
  314. print #3,ltxtm2$
  315. trg=1
  316. end if
  317. '- channel 3, volume
  318. if q0=5 then
  319. q0=readbyte(1)
  320. vol2= bitwiseand(q0,0xF)
  321. ltxtm1$=ltxtm$
  322. ltxtm2$=replace$(46+75,ltxtm1$,ucase$(right$(hex$(0x10+vol2),1)))
  323. ltxcr$=replace$(46+75,ltxcr$,ucase$(right$(hex$(0x10+vol2),1)))
  324. print #3,ltxtm2$
  325. trg=1
  326. end if
  327. '- channel 4, volume
  328. if q0=7 then
  329. q0=readbyte(1)
  330. vol3= bitwiseand(q0,0xF)
  331. ltxtm1$=ltxtm$
  332. ltxtm2$=replace$(61+75,ltxtm1$,ucase$(right$(hex$(0x10+vol2),1)))
  333. ltxcr$=replace$(61+75,ltxcr$,ucase$(right$(hex$(0x10+vol2),1)))
  334. print #3,ltxtm2$
  335. trg=1
  336. end if
  337. '- channel 5, volume
  338. if q0=0x81 then
  339. q0=readbyte(1)
  340. vol0= bitwiseand(q0,0xF)
  341. ltxtm1$=ltxtm$
  342. ltxtm2$=replace$(76+75,ltxtm1$,ucase$(right$(hex$(0x10+vol0),1)))
  343. ltxcr$=replace$(76+75,ltxcr$,ucase$(right$(hex$(0x10+vol0),1)))
  344. print #3,ltxtm2$
  345. trg=1
  346. end if
  347. '- channel 6, volume
  348. if q0=0x83 then
  349. q0=readbyte(1)
  350. vol1= bitwiseand(q0,0xF)
  351. ltxtm1$=ltxtm$
  352. ltxtm2$=replace$(91+75,ltxtm1$,ucase$(right$(hex$(0x10+vol1),1)))
  353. ltxcr$=replace$(91+75,ltxcr$,ucase$(right$(hex$(0x10+vol1),1)))
  354. print #3,ltxtm2$
  355. trg=1
  356. end if
  357. '- channel 7, volume
  358. if q0=0x85 then
  359. q0=readbyte(1)
  360. vol2= bitwiseand(q0,0xF)
  361. ltxtm1$=ltxtm$
  362. ltxtm2$=replace$(106+75,ltxtm1$,ucase$(right$(hex$(0x10+vol2),1)))
  363. ltxcr$=replace$(106+75,ltxcr$,ucase$(right$(hex$(0x10+vol2),1)))
  364. print #3,ltxtm2$
  365. trg=1
  366. end if
  367. '- channel 8, volume
  368. if q0=0x87 then
  369. q0=readbyte(1)
  370. vol3= bitwiseand(q0,0xF)
  371. ltxtm1$=ltxtm$
  372. ltxtm2$=replace$(121+75,ltxtm1$,ucase$(right$(hex$(0x10+vol2),1)))
  373. ltxcr$=replace$(121+75,ltxcr$,ucase$(right$(hex$(0x10+vol2),1)))
  374. print #3,ltxtm2$
  375. trg=1
  376. end if
  377. end if
  378. if eof(1)<>0 then
  379. veof=1
  380. print #2,""
  381. print #2,"# End of export"
  382. end if
  383. wend
  384. for eeq=0 to patid
  385. txou$="ORDER "+right$(hex$(0x100+eeq),2)+" :"
  386. for eer=0 to 12
  387. txou$=txou$+" "+right$(hex$(0x100+eeq),2)
  388. next
  389. print #2,txou$
  390. next
  391. print #2,""
  392. close #1:close #2:close #3
  393. if debug=0 then:
  394. shell("rm "+fout3$)
  395. end if