Vgm2FurnaceClipboardTxt_ym2413_01.sdlbas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #! /usr/bin/sdlbrt
  2. finp$="song.vgm"
  3. cbstr$="org.tildearrow.furnace - Pattern Data (103)"
  4. '- .vgm to furnace tracker clipboard converter - YM3526
  5. '- copyleft nitrofurano, may'22
  6. '-------------------------------
  7. '- bugs:
  8. '- - missing instruments, volume and percussion
  9. '-------------------------------
  10. ltxtm$="...........|...........|...........|...........|...........|...........|...........|...........|...........|":ltxcr$=ltxtm$
  11. instch$="0102030404040404"
  12. dim frqaa[16],frqka[16],volaa[16],volka[16],wfca[32,32]
  13. dim hdrv[256],wfc0[32],wfc1[32],wfc2[32],wfc3[32],wfc4[32]
  14. dim fnuml[16],fnumh[16],fblk[16],fnumw[16],ffqv[16]
  15. frqaa[0]=0:frqaa[1]=0:frqaa[2]=0:volaa[0]=0:volaa[1]=0:volaa[2]=0
  16. patsz=64:patc=0:patid=0:freqq=0:hdram=0x40:vgmv=0:veof=0
  17. frqka[0]=0:frqka[1]=0:frqka[2]=0:frqka[3]=0:frqka[4]=0
  18. volka[0]=0:volka[1]=0:volka[2]=0:volka[3]=0:volka[4]=0
  19. if argc>2 then:finp$=argv(2):end if
  20. fout2$=finp$+"_furnaceclipboard.txt":fout3$=finp$+"_furnaceclipboard_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. function nttfrq$(freqb)
  31. e$= "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  32. e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  33. e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  34. e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  35. e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  36. e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  37. e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  38. e$=e$+"B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7"
  39. e$=e$+"B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7..."
  40. tmq=(int((log(freqb)/log(2))*12))-91
  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>=0x0160 then:hdram=0x0C0:end if
  54. if vgmv>=0x0170 then:hdram=0x100:end if
  55. '- wrong information???
  56. ttsam=hdrv[0x18]+hdrv[0x19]*256+hdrv[0x1A]*65536+hdrv[0x1B]*16777216
  57. hsam$="PlayOrder=L0"
  58. for i=1 to (ttsam/(frmi*patsz))-1
  59. hsam$=hsam$+","+str$(i)
  60. next
  61. open finp$ for input as #1
  62. open fout2$ for output as #2
  63. open fout3$ for output as #3
  64. print #2,"---------8<----------------------------------------------"
  65. print #2,"[Pattern00]"
  66. print #2," "
  67. print #2,cbstr$
  68. print #2,"0"
  69. '- the amount of header bytes depends on vgm format version
  70. for eee=0 to hdram-1:q0=readbyte(1):next '- read offset byte first
  71. txou1$=" #("+str$(0)+")"
  72. while veof=0:
  73. q0=readbyte(1)
  74. '- vgm eof command
  75. if q0=0x66 then:
  76. veof=1
  77. print #3,"--vgm-eof--"
  78. print #2," "
  79. end if
  80. '- delay 1 byte (1..16 samples)
  81. if bitwiseand(q0,0x70)=0x70 then
  82. frmc=frmc+bitwiseand(q0,0xF)+1
  83. txou1$=" #("+str$(frmc)+")"
  84. 'print #3,txou1$
  85. end if
  86. '- delay 3 bytes (0..65535 samples)
  87. if q0=0x61 then
  88. q0=readbyte(1)
  89. frmc=frmc+q0
  90. q0=readbyte(1)
  91. frmc=frmc+(q0*256)
  92. txou1$=" #("+str$(frmc)+")"
  93. 'print #3,txou1$
  94. end if
  95. '- 1 ntsc frame delay, 735 samples
  96. if q0=0x62 then
  97. frmc=frmc+735
  98. txou1$=" #("+str$(frmc)+")"
  99. 'print #3,txou1$
  100. end if
  101. '- 1 pal frame delay, 882 samples
  102. if q0=0x63 then
  103. frmc=frmc+882
  104. txou1$=" #("+str$(frmc)+")"
  105. 'print #3,txou1$
  106. end if
  107. '- updates frameout pulses
  108. while frmr<frmc
  109. '- creates a new pattern
  110. if patc>(patsz-1) then:
  111. print #2," "
  112. patid=patid+1:patc=0
  113. txou9$="[Pattern"+ucase$(right$(hex$(0x100+patid),2))+"]"
  114. print #2,"---------8<----------------------------------------------"
  115. print #2,txou9$
  116. print #2,""
  117. print #2,cbstr$
  118. print #2,"0"
  119. end if
  120. '- writes a pattern line in each frame
  121. if trg=0 then
  122. print #3,"--frameout-unchanged--"
  123. print #2,ltxtm$
  124. else
  125. print #3,"--frameout--"
  126. print #2,ltxcr$
  127. ltxcr$=ltxtm$
  128. trg=0
  129. end if
  130. frmr=frmr+frmi
  131. patc=patc+1
  132. end while
  133. '-------------------------------------------------------------------------------
  134. '- YM2413
  135. '- token 0x51 gets registers and values to YM2413 output
  136. if q0=0x51 then
  137. q0=readbyte(1)
  138. '-------------------------------------------------------------------------------
  139. if bitwiseand(q0,0xF0)=0x10 then '- fnuml
  140. q3=bitwiseand(q0,0x0F)
  141. q0=readbyte(1)
  142. fnuml[q3]=q0
  143. fnumw[q3]=fnuml[q3]+(bitwiseand(fnumh[q3],0x01)*256)
  144. fblk[q3]=(bitwiseand(fnumh[q3],0x0E)/2)
  145. ffqv[q3]=fnumw[q3]*(2^fblk[q3])
  146. ltxtm1$=ltxtm$
  147. ltxtm2$=replace$((12*q3),ltxtm1$,nttfrq$(ffqv[q3])+"00")
  148. ltxcr$=replace$((12*q3),ltxcr$,nttfrq$(ffqv[q3])+"00")
  149. print #3,ltxtm2$
  150. trg=1
  151. end if
  152. if bitwiseand(q0,0xF0)=0x20 then '- fnumh
  153. q3=bitwiseand(q0,0x0F)
  154. q0=readbyte(1)
  155. fnumh[q3]=q0
  156. fnumw[q3]=fnuml[q3]+(bitwiseand(fnumh[q3],0x01)*256)
  157. fblk[q3]=(bitwiseand(fnumh[q3],0x0E)/2)
  158. ffqv[q3]=fnumw[q3]*(2^fblk[q3])
  159. ltxtm1$=ltxtm$
  160. ltxtm2$=replace$((12*q3),ltxtm1$,nttfrq$(ffqv[q3])+"00")
  161. ltxcr$=replace$((12*q3),ltxcr$,nttfrq$(ffqv[q3])+"00")
  162. print #3,ltxtm2$
  163. trg=1
  164. end if
  165. end if
  166. '-------------------------------------------------------------------------------
  167. if eof(1)<>0 then:veof=1:end if
  168. wend
  169. '--------------------------------
  170. close #1:close #2:close #3
  171. if debug=0 then:
  172. shell("rm "+fout3$)
  173. end if