converter_b_ym2151x2_1b.sdlbas 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. function lstinf$(a$,b$,c$)
  2. adra=1:adrb=1:blngt=len(b$):d$=""
  3. while adrb<=blngt
  4. if mid$ (a$,adra,1)=mid$ (b$,adrb,1) then:adrb+=1:end if
  5. adra=adra+1
  6. end while
  7. while mid$(a$,adra,1)<>left$(c$,1)
  8. d$=d$+mid$(a$,adra,1):adra=adra+1
  9. end while
  10. lstinf$=d$
  11. end function
  12. function vldc(a$)
  13. t0$="!"+a$+".0.0.0."
  14. t1$=lstinf$(t0$,"!",".")
  15. t2$=lstinf$(t0$,".",".")
  16. t3=10^(len(t2$))
  17. vldc=val(t1$)+(val(t2$)/t3)
  18. end function
  19. dim chfq[16],chvl[16]
  20. dim wlt[16]
  21. wlt[0]=0:wlt[1]=1:wlt[2]=3:wlt[3]=4
  22. wlt[4]=5:wlt[5]=7:wlt[6]=8:wlt[7]=9 '
  23. wlt[8]=11:wlt[9]=12:wlt[10]=13:wlt[11]=15 '
  24. wlt[12]=15:wlt[13]=15:wlt[14]=15:wlt[15]=15
  25. ' 0 2 3 4 6 7 8 10 11 12 14 15
  26. finp$="_.csv"
  27. if argc>2 then:finp$=argv(2):end if
  28. print"56676D20" '- vgm
  29. print"FFFFFF0F" '- lenght
  30. print"60010000" '- version
  31. print"0000000000000000" '- clock: sn76489,ym2413
  32. print"D50B0000" '- gd3
  33. print"50D80400" '- total samples
  34. print"67000000" '- loop
  35. print"00000000" '- loop
  36. print"3C000000" '- rate
  37. print"0000000000000000" '- flags, ym2612
  38. print"999E3640" '- ym2151
  39. print"4C000000" '- offset
  40. print"00000000000000000000000000000000"
  41. print"00000000000000000000000000000000"
  42. print"00000000000000000000000000000000"
  43. print"00000000000000000000000000000000"
  44. print"0000000000000000"
  45. print""
  46. print";- registers reset?"
  47. print"540102 541800 541B00 5419FF 54197F "
  48. print"540800 5420C0 54607F 54687F 54707F 54787F "
  49. print"540801 5421C0 54617F 54697F 54717F 54797F "
  50. print"540802 5422C0 54627F 546A7F 54727F 547A7F "
  51. print"540803 5423C0 54637F 546B7F 54737F 547B7F "
  52. print"540804 5424C0 54647F 546C7F 54747F 547C7F "
  53. print"540805 5425C0 54657F 546D7F 54757F 547D7F "
  54. print"540806 5426C0 54667F 546E7F 54767F 547E7F "
  55. print"540807 5427C0 54677F 546F7F 54777F 547F7F"
  56. print"A40102 A41800 A41B00 A419FF A4197F "
  57. print"A40800 A420C0 A4607F A4687F A4707F A4787F "
  58. print"A40801 A421C0 A4617F A4697F A4717F A4797F "
  59. print"A40802 A422C0 A4627F A46A7F A4727F A47A7F "
  60. print"A40803 A423C0 A4637F A46B7F A4737F A47B7F "
  61. print"A40804 A424C0 A4647F A46C7F A4747F A47C7F "
  62. print"A40805 A425C0 A4657F A46D7F A4757F A47D7F "
  63. print"A40806 A426C0 A4667F A46E7F A4767F A47E7F "
  64. print"A40807 A427C0 A4677F A46F7F A4777F A47F7F"
  65. print""
  66. 'print";-?"
  67. 'print"C002007F C003007F C00A007F C00B007F"
  68. 'print"C012007F C013007F C01A007F C01B007F"
  69. 'print"C022007F C023007F"
  70. 'print""
  71. print";- instruments?"
  72. print"544032 54601D 54800E 54A00E 54C000 54E04A"
  73. print"544851 546816 54880E 54A80E 54C800 54E83A"
  74. print"545051 547019 549014 54B000 54D000 54F00A"
  75. print"545831 54781E 549814 54B802 54D801 54F83A"
  76. print"5420FB 543800 540878 542800 543000"
  77. print"544132 54611D 54810E 54A10E 54C100 54E14A"
  78. print"544951 546916 54890E 54A90E 54C900 54E93A"
  79. print"545151 547119 549114 54B100 54D100 54F10A"
  80. print"545931 54791E 549914 54B902 54D901 54F93A"
  81. print"5421FB 543900 540879 54290E 543100"
  82. print"544232 54621D 54820E 54A20E 54C200 54E24A"
  83. print"544A51 546A16 548A0E 54AA0E 54CA00 54EA3A"
  84. print"545251 547219 549214 54B200 54D200 54F20A"
  85. print"545A31 547A1E 549A14 54BA02 54DA01 54FA3A"
  86. print"5422FB 543A00 54087A 542A1E 543200"
  87. print"544332 54631D 54830E 54A30E 54C300 54E34A"
  88. print"544B51 546B16 548B0E 54AB0E 54CB00 54EB3A"
  89. print"545351 547319 549314 54B300 54D300 54F30A"
  90. print"545B31 547B1E 549B14 54BB02 54DB01 54FB3A"
  91. print"5423FB 543B00 54087B 542B2E 543300"
  92. print"544432 54641D 54840E 54A40E 54C400 54E44A"
  93. print"544C51 546C16 548C0E 54AC0E 54CC00 54EC3A"
  94. print"545451 547419 549414 54B400 54D400 54F40A"
  95. print"545C31 547C1E 549C14 54BC02 54DC01 54FC3A"
  96. print"5424FB 543C00 54087C 542C3E 543400"
  97. print"544532 54651D 54850E 54A50E 54C500 54E54A"
  98. print"544D51 546D16 548D0E 54AD0E 54CD00 54ED3A"
  99. print"545551 547519 549514 54B500 54D500 54F50A"
  100. print"545D31 547D1E 549D14 54BD02 54DD01 54FD3A"
  101. print"5425FB 543D00 54087D 542D4E 543500"
  102. print"544632 54661D 54860E 54A60E 54C600 54E64A"
  103. print"544E51 546E16 548E0E 54AE0E 54CE00 54EE3A"
  104. print"545651 547619 549614 54B600 54D600 54F60A"
  105. print"545E31 547E1E 549E14 54BE02 54DE01 54FE3A"
  106. print"5426FB 543E00 54087E 542E5E 543600"
  107. print"544732 54671D 54870E 54A70E 54C700 54E74A "
  108. print"544F51 546F16 548F0E 54AF0E 54CF00 54EF3A "
  109. print"545751 547719 549714 54B700 54D700 54F70A "
  110. print"545F31 547F1E 549F14 54BF02 54DF01 54FF3A "
  111. print"5427FB 543F00 54087F 542F6E 543700"
  112. print"A44032 A4601D A4800E A4A00E A4C000 A4E04A"
  113. print"A44851 A46816 A4880E A4A80E A4C800 A4E83A"
  114. print"A45051 A47019 A49014 A4B000 A4D000 A4F00A"
  115. print"A45831 A4781E A49814 A4B802 A4D801 A4F83A"
  116. print"A420FB A43800 A40878 A42800 A43000"
  117. print"A44132 A4611D A4810E A4A10E A4C100 A4E14A"
  118. print"A44951 A46916 A4890E A4A90E A4C900 A4E93A"
  119. print"A45151 A47119 A49114 A4B100 A4D100 A4F10A"
  120. print"A45931 A4791E A49914 A4B902 A4D901 A4F93A"
  121. print"A421FB A43900 A40879 A4290E A43100"
  122. print"A44232 A4621D A4820E A4A20E A4C200 A4E24A"
  123. print"A44A51 A46A16 A48A0E A4AA0E A4CA00 A4EA3A"
  124. print"A45251 A47219 A49214 A4B200 A4D200 A4F20A"
  125. print"A45A31 A47A1E A49A14 A4BA02 A4DA01 A4FA3A"
  126. print"A422FB A43A00 A4087A A42A1E A43200"
  127. print"A44332 A4631D A4830E A4A30E A4C300 A4E34A"
  128. print"A44B51 A46B16 A48B0E A4AB0E A4CB00 A4EB3A"
  129. print"A45351 A47319 A49314 A4B300 A4D300 A4F30A"
  130. print"A45B31 A47B1E A49B14 A4BB02 A4DB01 A4FB3A"
  131. print"A423FB A43B00 A4087B A42B2E A43300"
  132. print"A44432 A4641D A4840E A4A40E A4C400 A4E44A"
  133. print"A44C51 A46C16 A48C0E A4AC0E A4CC00 A4EC3A"
  134. print"A45451 A47419 A49414 A4B400 A4D400 A4F40A"
  135. print"A45C31 A47C1E A49C14 A4BC02 A4DC01 A4FC3A"
  136. print"A424FB A43C00 A4087C A42C3E A43400"
  137. print"A44532 A4651D A4850E A4A50E A4C500 A4E54A"
  138. print"A44D51 A46D16 A48D0E A4AD0E A4CD00 A4ED3A"
  139. print"A45551 A47519 A49514 A4B500 A4D500 A4F50A"
  140. print"A45D31 A47D1E A49D14 A4BD02 A4DD01 A4FD3A"
  141. print"A425FB A43D00 A4087D A42D4E A43500"
  142. print"A44632 A4661D A4860E A4A60E A4C600 A4E64A"
  143. print"A44E51 A46E16 A48E0E A4AE0E A4CE00 A4EE3A"
  144. print"A45651 A47619 A49614 A4B600 A4D600 A4F60A"
  145. print"A45E31 A47E1E A49E14 A4BE02 A4DE01 A4FE3A"
  146. print"A426FB A43E00 A4087E A42E5E A43600"
  147. print"A44732 A4671D A4870E A4A70E A4C700 A4E74A "
  148. print"A44F51 A46F16 A48F0E A4AF0E A4CF00 A4EF3A "
  149. print"A45751 A47719 A49714 A4B700 A4D700 A4F70A "
  150. print"A45F31 A47F1E A49F14 A4BF02 A4DF01 A4FF3A "
  151. print"A427FB A43F00 A4087F A42F6E A43700"
  152. lct=0
  153. open finp$ for input as #1
  154. while eof(1)=0
  155. file input #1,txrd$
  156. setcaption("b:"+str$(lct)):lct+=1
  157. if mid$(txrd$,1,1)="[" then:
  158. if mid$(txrd$,2,1)="f" then:
  159. chid=val(mid$(txrd$,3,2))
  160. chid=chid mod 16 'ym2151x2 has 16 channels
  161. chfqv=vldc(lstinf$(txrd$,":","]"))
  162. chfqv-=(2/12) '- <- c
  163. chfqvo=int(chfqv)
  164. 'if chfqvo<1 then:chfqvo=1:end if
  165. 'if chfqvo>8 then:chfqvo=8:end if
  166. chfqvf=chfqv-chfqvo
  167. chfqv1a1=chfqvf*12
  168. chfqv1a2=int(chfqv1a1)
  169. 'chfqv1a2b=chfqv1a2+int((chfqv1a2+2)/3) '- <-
  170. chfqv1a2b=wlt[chfqv1a2] '- <-
  171. chfqv1a3=chfqv1a1-chfqv1a2
  172. chfqv1a3b=(int(chfqv1a3*64))*4
  173. 'chfqv3=int(644*2^chfqvf)
  174. 'chfqv3a=chfqv3 mod 256
  175. 'chfqv3b=int(chfqv3/256)
  176. 'chfqv5=(chfqvo*8+chfqv3b)
  177. 'chfqv2=int(26.6984611843*2^(8-chfqv))
  178. 'if chfqv2>2047 then:chfqv2=2047:end if
  179. 'if chfqv2<0 then:chfqv2=0:end if
  180. 'chchrfq$=right$("000"+hex$(chfqv2),3)
  181. if int(chid/8)=0 then
  182. txrgo$="54080"+right$("0"+hex$(chid mod 8),1)
  183. txrgo$+=" 54087"+right$("0"+hex$(8+(chid mod 8)),1)
  184. txrgo$+=" 542"+right$("0"+hex$(8+(chid mod 8)),1)+right$("0"+hex$(chfqvo),1)+right$("0"+hex$(chfqv1a2b),1)
  185. txrgo$+=" 543"+right$("0"+hex$(chid mod 8),1)+right$("00"+hex$(chfqv1a3b),2)
  186. else
  187. txrgo$="A4080"+right$("0"+hex$(chid mod 8),1)
  188. txrgo$+=" A4087"+right$("0"+hex$(8+(chid mod 8)),1)
  189. txrgo$+=" A42"+right$("0"+hex$(8+(chid mod 8)),1)+right$("0"+hex$(chfqvo),1)+right$("0"+hex$(chfqv1a2b),1)
  190. txrgo$+=" A43"+right$("0"+hex$(chid mod 8),1)+right$("00"+hex$(chfqv1a3b),2)
  191. end if
  192. 'txrgo$+=" 54A4"+right$("00"+hex$(chfqv5),2)
  193. 'txrgo$+=" 54A0"+right$("00"+hex$(chfqv3a),2)
  194. 'txrgo$+=" 5428F"+right$("0"+hex$(chid),1)
  195. print ucase$(txrgo$)
  196. end if
  197. 'if mid$(txrd$,2,1)="v" then:
  198. ' chid=val(mid$(txrd$,3,2))
  199. ' chid=chid mod 16 'ym2151x2 has 16 channels
  200. ' chvlv=vldc(lstinf$(txrd$,":","]"))*0x10
  201. ' chchrvl$=right$("00"+hex$(chvlv),2)
  202. ' txrgo$="A0"+right$("00"+hex$(8+chid),2)+chchrvl$
  203. ' print ucase$(txrgo$)
  204. ' end if
  205. if mid$(txrd$,2,3)="wvb" then:
  206. wvblv=vldc(lstinf$(txrd$,":","]"))
  207. wvblv2=wvblv*44100
  208. wvblv3a=wvblv2 mod 65536
  209. wvblv3b=int(wvblv2/65536)
  210. wvblv3as$=ucase$(right$("0000"+hex$(wvblv3a),4))
  211. for ii=1 to wvblv3b:print"61FFFF":next
  212. print "61"+mid$(wvblv3as$,3,2)+mid$(wvblv3as$,1,2)
  213. end if
  214. end if
  215. wend
  216. print:print "66":print
  217. close #1
  218. '
  219. ' 0 1 2 3 4 5 6 7 8 9 10 11
  220. ' -2 0 1 2 4 5 6 8 9 10 12 13
  221. ' 0 2 3 4 6 7 8 10 11 12 14 15
  222. ' 0 1 1 1 2 2 2 3 3 3 4 4
  223. ' n+int((n+2)/3)
  224. '