Vgm2OpenMPTClipboardTxtAy38910K051649.sdlbas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. #! /usr/bin/sdlbrt
  2. finp$="tune.vgm"
  3. '- .vgm to VortexTracker .txt converter - AY-3-8910 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. '- - 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. ltxtm$= "|...........|...........|...........|...........|...........|...........|...........|...........":ltxcr$=ltxtm$
  15. 'ltxtm$="....|..|--- .... ....|--- .... ....|--- .... ....":ltxcr$=ltxtm$
  16. freq0=0:freq1=0:freq2=0:vol0=0:vol1=0:vol2=0
  17. patsz=64:patc=0:patid=0:freqq=0
  18. hdram=0x40:vgmv=0:veof=0
  19. freqk0=0:freqk1=0:freqk2=0:freqk3=0:freqk4=0
  20. volk0=0:volk1=0:volk2=0:volk3=0:volk4=0
  21. dim hdrv[256]
  22. dim wfc0[32],wfc1[32],wfc2[32],wfc3[32],wfc4[32]
  23. if argc>2 then:finp$=argv(2):end if
  24. fout2$=finp$+"_asciimod.txt":fout3$=finp$+"_asciimod_debug.txt"
  25. frmc=0:frmr=300:trg=0
  26. frmi=735
  27. if argc>3 then:
  28. if argv(3)="1" or ucase$(argv(2))="-PAL" then
  29. frmi=882:end if:end if
  30. debug=0
  31. if argc>4 then:
  32. if argv(4)="1" or ucase$(argv(2))="-DEBUG" then
  33. debug=1:end if:end if
  34. '- fix: 0x0FE=440hz=A-4
  35. function nttfrq$(freqb)
  36. e$= "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  37. e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  38. e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  39. e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  40. e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  41. e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  42. e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  43. e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8---"
  44. tmq=141-(int((log(freqb*.99)/log(2))*12))
  45. if tmq<1 then:tmq=1:end if
  46. if tmq>97 then:tmq=97:end if
  47. return mid$(e$,(tmq*3)-2,3)
  48. end function
  49. open finp$ for input as #1
  50. for i=0 to 255
  51. hdrv[i]=readbyte(1)
  52. next
  53. close #1
  54. hdram=0x040
  55. vgmv=hdrv[8]+hdrv[9]*256
  56. if vgmv>=0x0150 then:hdram=0x080:end if
  57. if vgmv>=0x0160 then:hdram=0x0C0:end if
  58. if vgmv>=0x0170 then:hdram=0x100:end if
  59. '- wrong information???
  60. ttsam=hdrv[0x18]+hdrv[0x19]*256+hdrv[0x1A]*65536+hdrv[0x1B]*16777216
  61. hsam$="PlayOrder=L0"
  62. for i=1 to (ttsam/(frmi*patsz))-1
  63. hsam$=hsam$+","+str$(i)
  64. next
  65. open finp$ for input as #1
  66. open fout2$ for output as #2
  67. open fout3$ for output as #3
  68. print #2,"[Module]"
  69. print #2,"Format:mod"
  70. print #2,"Title:"
  71. print #2," "
  72. for i=0 to 4
  73. print #2,"[SampleInfo"+hex$(i)+"]"
  74. print #2,"Name:SquareWave"
  75. print #2,"Lenght:0x0020"
  76. print #2,"Finetune:0"
  77. print #2,"Volume:0x40"
  78. print #2,"RepeatPoint:0x0000"
  79. print #2,"RepeatLenght:0x0020"
  80. print #2," "
  81. next
  82. print #2,"[MoreInfo]"
  83. print #2,"SongLenght:8"
  84. print #2,"VersionFlag1:0x00"
  85. print #2,"PlayOrder:0,1,2,3,4,5,6,7"
  86. print #2,"VersionFlag2:8CHN"
  87. print #2," "
  88. print #2,"[Pattern0]"
  89. print #2,"ModPlug Tracker MOD"
  90. '- the amount of header bytes depends on vgm format version
  91. for eee=0 to hdram-1:q0=readbyte(1):next '- read offset byte first
  92. txou1$=" #("+str$(0)+")"
  93. while veof=0:
  94. q0=readbyte(1)
  95. '- vgm eof command
  96. if q0=0x66 then:
  97. veof=1
  98. print #3,"--vgm-eof--"
  99. print #2," "
  100. end if
  101. '- delay 1 byte (1..16 samples)
  102. if bitwiseand(q0,0x70)=0x70 then
  103. frmc=frmc+bitwiseand(q0,0xF)+1
  104. txou1$=" #("+str$(frmc)+")"
  105. 'print #3,txou1$
  106. end if
  107. '- delay 3 bytes (0..65535 samples)
  108. if q0=0x61 then
  109. q0=readbyte(1)
  110. frmc=frmc+q0
  111. q0=readbyte(1)
  112. frmc=frmc+(q0*256)
  113. txou1$=" #("+str$(frmc)+")"
  114. 'print #3,txou1$
  115. end if
  116. '- 1 ntsc frame delay, 735 samples
  117. if q0=0x62 then
  118. frmc=frmc+735
  119. txou1$=" #("+str$(frmc)+")"
  120. 'print #3,txou1$
  121. end if
  122. '- 1 pal frame delay, 882 samples
  123. if q0=0x63 then
  124. frmc=frmc+882
  125. txou1$=" #("+str$(frmc)+")"
  126. 'print #3,txou1$
  127. end if
  128. '- updates frameout pulses
  129. while frmr<frmc
  130. '- writes F7F and F01 in the firsts lines of the first pattern
  131. if (patc<1 and patid=0) then
  132. ltxcr$=replace$(93,ltxcr$,"F7F")
  133. end if
  134. if (patc=1 and patid=0) then
  135. ltxcr$=replace$(93,ltxcr$,"F01")
  136. end if
  137. '- creates a new pattern
  138. if patc>(patsz-1) then:
  139. print #2," "
  140. patid=patid+1:patc=0
  141. txou9$="[Pattern"+str$(patid)+"]"
  142. print #2,txou9$
  143. print #2,"ModPlug Tracker MOD"
  144. end if
  145. '- writes a pattern line in each frame
  146. if trg=0 then
  147. print #3,"--frameout-unchanged--"
  148. print #2,ltxtm$
  149. else
  150. print #3,"--frameout--"
  151. print #2,ltxcr$
  152. ltxcr$=ltxtm$
  153. trg=0
  154. end if
  155. frmr=frmr+frmi
  156. patc=patc+1
  157. end while
  158. '- token 0xA0 gets registers and values to AY-3-8910 output
  159. if q0=0xA0 then
  160. q0=readbyte(1)
  161. '- channel 0, fine
  162. if q0=0 then
  163. q0=readbyte(1)
  164. freq0= bitwiseor((bitwiseand(freq0,0xF00)),(bitwiseand(q0,0x0FF)))
  165. ltxtm1$=ltxtm$
  166. ltxtm2$=replace$(1,ltxtm1$,nttfrq$(freq0)+"01")
  167. ltxcr$=replace$(1,ltxcr$,nttfrq$(freq0)+"01")
  168. print #3,ltxtm2$
  169. trg=1
  170. end if
  171. '- channel 0, coarse
  172. if q0=1 then
  173. q0=readbyte(1)
  174. freq0= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq0,0x0FF)) )
  175. ltxtm1$=ltxtm$
  176. ltxtm2$=replace$(1,ltxtm1$,nttfrq$(freq0)+"01")
  177. ltxcr$=replace$(1,ltxcr$,nttfrq$(freq0)+"01")
  178. print #3,ltxtm2$
  179. trg=1
  180. end if
  181. '- channel 1, fine
  182. if q0=2 then
  183. q0=readbyte(1)
  184. freq1= bitwiseor ( (bitwiseand(freq1,0xF00)),(bitwiseand(q0,0x0FF)) )
  185. ltxtm1$=ltxtm$
  186. ltxtm2$=replace$(13,ltxtm1$,nttfrq$(freq1)+"01")
  187. ltxcr$=replace$(13,ltxcr$,nttfrq$(freq1)+"01")
  188. print #3,ltxtm2$
  189. trg=1
  190. end if
  191. '- channel 1, coarse
  192. if q0=3 then
  193. q0=readbyte(1)
  194. freq1= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq1,0x0FF)) )
  195. ltxtm1$=ltxtm$
  196. ltxtm2$=replace$(13,ltxtm1$,nttfrq$(freq1)+"01")
  197. ltxcr$=replace$(13,ltxcr$,nttfrq$(freq1)+"01")
  198. print #3,ltxtm2$
  199. trg=1
  200. end if
  201. '- channel 2, fine
  202. if q0=4 then
  203. q0=readbyte(1)
  204. freq2= bitwiseor ( (bitwiseand(freq2,0xF00)),(bitwiseand(q0,0x0FF)) )
  205. ltxtm1$=ltxtm$
  206. ltxtm2$=replace$(25,ltxtm1$,nttfrq$(freq2)+"01")
  207. ltxcr$=replace$(25,ltxcr$,nttfrq$(freq2)+"01")
  208. print #3,ltxtm2$
  209. trg=1
  210. end if
  211. '- channel 2, coarse
  212. if q0=5 then
  213. q0=readbyte(1)
  214. freq2= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freq2,0x0FF)) )
  215. ltxtm1$=ltxtm$
  216. ltxtm2$=replace$(25,ltxtm1$,nttfrq$(freq2)+"01")
  217. ltxcr$=replace$(25,ltxcr$,nttfrq$(freq2)+"01")
  218. print #3,ltxtm2$
  219. trg=1
  220. end if
  221. '?????
  222. if q0=6 then
  223. print #3,ltxtm$
  224. end if
  225. '?????
  226. 'if q0=7 then
  227. ' q0=readbyte(1)
  228. ' ltxtm1$=ltxtm$
  229. ' ltxtm2$=left$(ltxtm1$,31)+ right$(bin$(512+q0),8) +right$(ltxtm1$,2)+txou1$
  230. ' print #3,ltxtm2$
  231. ' trg=1
  232. ' end if
  233. '- channel 1, volume
  234. if q0=8 then
  235. q0=readbyte(1)
  236. vol0= bitwiseand(q0,0xF)
  237. ltxtm1$=ltxtm$
  238. ltxtm2$=replace$(9,ltxtm1$,"C"+ucase$(right$(hex$(0x100+vol0*4),2)))
  239. ltxcr$=replace$(9,ltxcr$,"C"+ucase$(right$(hex$(0x100+vol0*4),2)))
  240. print #3,ltxtm2$
  241. trg=1
  242. end if
  243. '- channel 2, volume
  244. if q0=9 then
  245. q0=readbyte(1)
  246. vol1= bitwiseand(q0,0xF)
  247. ltxtm1$=ltxtm$
  248. ltxtm2$=replace$(21,ltxtm1$,"C"+ucase$(right$(hex$(0x100+vol1*4),2)))
  249. ltxcr$=replace$(21,ltxcr$,"C"+ucase$(right$(hex$(0x100+vol1*4),2)))
  250. print #3,ltxtm2$
  251. trg=1
  252. end if
  253. '- channel 3, volume
  254. if q0=10 then
  255. q0=readbyte(1)
  256. vol2= bitwiseand(q0,0xF)
  257. ltxtm1$=ltxtm$
  258. ltxtm2$=replace$(33,ltxtm1$,"C"+ucase$(right$(hex$(0x100+vol2*4),2)))
  259. ltxcr$=replace$(33,ltxcr$,"C"+ucase$(right$(hex$(0x100+vol2*4),2)))
  260. print #3,ltxtm2$
  261. trg=1
  262. end if
  263. end if
  264. '- token 0xD2 gets registers and values to K051649 output
  265. if q0=0xD2 then
  266. q0=readbyte(1)
  267. if q0=0x00 then '- write waveform
  268. q0=readbyte(1)
  269. if int(q0/32)=0 then
  270. q1=readbyte(1)
  271. wfc0[bitwiseand(q0,31)]=q1
  272. end if
  273. if int(q0/32)=1 then
  274. q1=readbyte(1)
  275. wfc1[bitwiseand(q0,31)]=q1
  276. end if
  277. if int(q0/32)=2 then
  278. q2=readbyte(1)
  279. wfc2[bitwiseand(q0,31)]=q2
  280. end if
  281. if int(q0/32)=3 then
  282. q3=readbyte(1)
  283. wfc3[bitwiseand(q0,31)]=q3
  284. end if
  285. if int(q0/32)=3 then
  286. q4=readbyte(1)
  287. wfc4[bitwiseand(q0,31)]=q4
  288. end if
  289. end if
  290. if q0=0x01 then '- set frequency
  291. q0=readbyte(1)
  292. if q0=0 then
  293. q0=readbyte(1)
  294. freqk0= bitwiseor((bitwiseand(freqk0,0xF00)),(bitwiseand(q0,0x0FF)))
  295. ltxtm1$=ltxtm$
  296. ltxtm2$=replace$(37,ltxtm1$,nttfrq$(freqk0)+"02")
  297. ltxcr$=replace$(37,ltxcr$,nttfrq$(freqk0)+"02")
  298. print #3,ltxtm2$
  299. trg=1
  300. end if
  301. if q0=1 then
  302. q0=readbyte(1)
  303. freqk0= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freqk0,0x0FF)) )
  304. ltxtm1$=ltxtm$
  305. ltxtm2$=replace$(37,ltxtm1$,nttfrq$(freqk0)+"02")
  306. ltxcr$=replace$(37,ltxcr$,nttfrq$(freqk0)+"02")
  307. print #3,ltxtm2$
  308. trg=1
  309. end if
  310. if q0=2 then
  311. q0=readbyte(1)
  312. freqk1= bitwiseor((bitwiseand(freqk1,0xF00)),(bitwiseand(q0,0x0FF)))
  313. ltxtm1$=ltxtm$
  314. ltxtm2$=replace$(49,ltxtm1$,nttfrq$(freqk1)+"03")
  315. ltxcr$=replace$(49,ltxcr$,nttfrq$(freqk1)+"03")
  316. print #3,ltxtm2$
  317. trg=1
  318. end if
  319. if q0=3 then
  320. q0=readbyte(1)
  321. freqk1= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freqk1,0x0FF)) )
  322. ltxtm1$=ltxtm$
  323. ltxtm2$=replace$(49,ltxtm1$,nttfrq$(freqk1)+"03")
  324. ltxcr$=replace$(49,ltxcr$,nttfrq$(freqk1)+"03")
  325. print #3,ltxtm2$
  326. trg=1
  327. end if
  328. if q0=4 then
  329. q0=readbyte(1)
  330. freqk2= bitwiseor((bitwiseand(freqk2,0xF00)),(bitwiseand(q0,0x0FF)))
  331. ltxtm1$=ltxtm$
  332. ltxtm2$=replace$(61,ltxtm1$,nttfrq$(freqk2)+"04")
  333. ltxcr$=replace$(61,ltxcr$,nttfrq$(freqk2)+"04")
  334. print #3,ltxtm2$
  335. trg=1
  336. end if
  337. if q0=5 then
  338. q0=readbyte(1)
  339. freqk2= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freqk2,0x0FF)) )
  340. ltxtm1$=ltxtm$
  341. ltxtm2$=replace$(61,ltxtm1$,nttfrq$(freqk2)+"04")
  342. ltxcr$=replace$(61,ltxcr$,nttfrq$(freqk2)+"04")
  343. print #3,ltxtm2$
  344. trg=1
  345. end if
  346. if q0=6 then
  347. q0=readbyte(1)
  348. freqk3= bitwiseor((bitwiseand(freqk3,0xF00)),(bitwiseand(q0,0x0FF)))
  349. ltxtm1$=ltxtm$
  350. ltxtm2$=replace$(73,ltxtm1$,nttfrq$(freqk3)+"05")
  351. ltxcr$=replace$(73,ltxcr$,nttfrq$(freqk3)+"05")
  352. print #3,ltxtm2$
  353. trg=1
  354. end if
  355. if q0=7 then
  356. q0=readbyte(1)
  357. freqk3= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freqk3,0x0FF)) )
  358. ltxtm1$=ltxtm$
  359. ltxtm2$=replace$(73,ltxtm1$,nttfrq$(freqk3)+"05")
  360. ltxcr$=replace$(73,ltxcr$,nttfrq$(freqk3)+"05")
  361. print #3,ltxtm2$
  362. trg=1
  363. end if
  364. if q0=8 then
  365. q0=readbyte(1)
  366. freqk4= bitwiseor((bitwiseand(freqk4,0xF00)),(bitwiseand(q0,0x0FF)))
  367. ltxtm1$=ltxtm$
  368. ltxtm2$=replace$(85,ltxtm1$,nttfrq$(freqk4)+"05")
  369. ltxcr$=replace$(85,ltxcr$,nttfrq$(freqk4)+"05")
  370. print #3,ltxtm2$
  371. trg=1
  372. end if
  373. if q0=9 then
  374. q0=readbyte(1)
  375. freqk4= bitwiseor ( (bitwiseand(q0*256,0xF00)),(bitwiseand(freqk4,0x0FF)) )
  376. ltxtm1$=ltxtm$
  377. ltxtm2$=replace$(85,ltxtm1$,nttfrq$(freqk4)+"05")
  378. ltxcr$=replace$(85,ltxcr$,nttfrq$(freqk4)+"05")
  379. print #3,ltxtm2$
  380. trg=1
  381. end if
  382. end if
  383. if q0=0x02 then '- set volume
  384. q0=readbyte(1)
  385. if q0=0 then
  386. q0=readbyte(1)
  387. volk0= bitwiseand(q0,0xF)
  388. ltxtm1$=ltxtm$
  389. ltxtm2$=replace$(45,ltxtm1$,"C"+ucase$(right$(hex$(0x100+volk0*4),2)))
  390. ltxcr$=replace$(45,ltxcr$,"C"+ucase$(right$(hex$(0x100+volk0*4),2)))
  391. print #3,ltxtm2$
  392. trg=1
  393. end if
  394. if q0=1 then
  395. q0=readbyte(1)
  396. volk1= bitwiseand(q0,0xF)
  397. ltxtm1$=ltxtm$
  398. ltxtm2$=replace$(57,ltxtm1$,"C"+ucase$(right$(hex$(0x100+volk1*4),2)))
  399. ltxcr$=replace$(57,ltxcr$,"C"+ucase$(right$(hex$(0x100+volk1*4),2)))
  400. print #3,ltxtm2$
  401. trg=1
  402. end if
  403. if q0=2 then
  404. q0=readbyte(1)
  405. volk2= bitwiseand(q0,0xF)
  406. ltxtm1$=ltxtm$
  407. ltxtm2$=replace$(69,ltxtm1$,"C"+ucase$(right$(hex$(0x100+volk2*4),2)))
  408. ltxcr$=replace$(69,ltxcr$,"C"+ucase$(right$(hex$(0x100+volk2*4),2)))
  409. print #3,ltxtm2$
  410. trg=1
  411. end if
  412. if q0=3 then
  413. q0=readbyte(1)
  414. volk3= bitwiseand(q0,0xF)
  415. ltxtm1$=ltxtm$
  416. ltxtm2$=replace$(81,ltxtm1$,"C"+ucase$(right$(hex$(0x100+volk3*4),2)))
  417. ltxcr$=replace$(81,ltxcr$,"C"+ucase$(right$(hex$(0x100+volk3*4),2)))
  418. print #3,ltxtm2$
  419. trg=1
  420. end if
  421. if q0=4 then
  422. q0=readbyte(1)
  423. volk4= bitwiseand(q0,0xF)
  424. ltxtm1$=ltxtm$
  425. ltxtm2$=replace$(93,ltxtm1$,"C"+ucase$(right$(hex$(0x100+volk4*4),2)))
  426. ltxcr$=replace$(93,ltxcr$,"C"+ucase$(right$(hex$(0x100+volk4*4),2)))
  427. print #3,ltxtm2$
  428. trg=1
  429. end if
  430. end if
  431. end if
  432. if eof(1)<>0 then:veof=1:end if
  433. wend
  434. print #2," "
  435. print #2,"[Sample0]"
  436. print #2,"7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F80808080808080808080808080808080"
  437. print #2," "
  438. txousm$=""
  439. for i=0 to 31
  440. txousm$=txousm$+ucase$(right$(hex$(0x180+wfc0[i]),2))
  441. next
  442. print #2,"[Sample1]"
  443. print #2,txousm$
  444. print #2," "
  445. txousm$=""
  446. for i=0 to 31
  447. txousm$=txousm$+ucase$(right$(hex$(0x180+wfc1[i]),2))
  448. next
  449. print #2,"[Sample2]"
  450. print #2,txousm$
  451. print #2," "
  452. txousm$=""
  453. for i=0 to 31
  454. txousm$=txousm$+ucase$(right$(hex$(0x180+wfc2[i]),2))
  455. next
  456. print #2,"[Sample3]"
  457. print #2,txousm$
  458. print #2," "
  459. txousm$=""
  460. for i=0 to 31
  461. txousm$=txousm$+ucase$(right$(hex$(0x180+wfc3[i]),2))
  462. next
  463. print #2,"[Sample4]"
  464. print #2,txousm$
  465. print #2," "
  466. txousm$=""
  467. for i=0 to 31
  468. txousm$=txousm$+ucase$(right$(hex$(0x180+wfc4[i]),2))
  469. next
  470. print #2,"[Sample5]"
  471. print #2,txousm$
  472. print #2," "
  473. close #1:close #2:close #3
  474. if debug=0 then:
  475. shell("rm "+fout3$)
  476. end if