converter_b_saa1099x2_1c.sdlbas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. '- frequencies are innacurate
  2. function lstinf$(a$,b$,c$)
  3. adra=1:adrb=1:blngt=len(b$):d$=""
  4. while adrb<=blngt
  5. if mid$ (a$,adra,1)=mid$ (b$,adrb,1) then:adrb+=1:end if
  6. adra=adra+1
  7. end while
  8. while mid$(a$,adra,1)<>left$(c$,1)
  9. d$=d$+mid$(a$,adra,1):adra=adra+1
  10. end while
  11. lstinf$=d$
  12. end function
  13. function vldc(a$)
  14. t0$="!"+a$+".0.0.0."
  15. t1$=lstinf$(t0$,"!",".")
  16. t2$=lstinf$(t0$,".",".")
  17. t3=10^(len(t2$))
  18. vldc=val(t1$)+(val(t2$)/t3)
  19. end function
  20. dim chfq[16],chvl[16]
  21. finp$="_.csv"
  22. if argc>2 then:finp$=argv(2):end if
  23. print"56676D20"
  24. print"FFFFFF00"
  25. print"71010000"
  26. print"0000000000000000"
  27. print"2F023000"
  28. print"34DA3000"
  29. print"0000000000000000"
  30. print"3C000000"
  31. print"000000000000000000000000"
  32. print"AC000000"
  33. print"00000000000000000000000000000000"
  34. print"00000000000000000000000000000000"
  35. print"00000000000000000000000000000000"
  36. print"00000000000000000000000000000000"
  37. print"00000000000000000000000000000000"
  38. print"00000000000000000000000000000000"
  39. print"00000000000000000000000000000000"
  40. print"00000000000000000000000000000000"
  41. print"00000000000000000000000000000000"
  42. print"00127A40"
  43. print"00000000000000000000000000000000"
  44. print"00000000"
  45. print"BD1C01 ;- saa1099: register 1C: frequency reset, sound enable"
  46. print"BD143F ;- saa1099: frequency enable %00111111"
  47. print"BD1500 ;- saa1099: noise enable %00000000"
  48. print"BD1840 ;- saa1099: envelope generator 0"
  49. print"BD1940 ;- saa1099: envelope generator 1"
  50. print"BD0800 ;- saa1099: frequency channel 0"
  51. print"BD0900 ;- saa1099: frequency channel 1"
  52. print"BD0A00 ;- saa1099: frequency channel 2"
  53. print"BD0B00 ;- saa1099: frequency channel 3"
  54. print"BD0C00 ;- saa1099: frequency channel 4"
  55. print"BD0D00 ;- saa1099: frequency channel 5"
  56. print"BD1000 ;- saa1099: octave channels 0 and 1"
  57. print"BD1100 ;- saa1099: octave channels 2 and 3"
  58. print"BD1200 ;- saa1099: octave channels 4 and 5"
  59. print"BD0000 ;- saa1099: volume channel 0"
  60. print"BD0100 ;- saa1099: volume channel 1"
  61. print"BD0200 ;- saa1099: volume channel 2"
  62. print"BD0300 ;- saa1099: volume channel 3"
  63. print"BD0400 ;- saa1099: volume channel 4"
  64. print"BD0500 ;- saa1099: volume channel 5"
  65. print"BD9C01 ;- saa1099: register 1C: frequency reset, sound enable"
  66. print"BD943F ;- saa1099: frequency enable %00111111"
  67. print"BD9500 ;- saa1099: noise enable %00000000"
  68. print"BD9840 ;- saa1099: envelope generator 0"
  69. print"BD9940 ;- saa1099: envelope generator 1"
  70. print"BD8800 ;- saa1099: frequency channel 0"
  71. print"BD8900 ;- saa1099: frequency channel 1"
  72. print"BD8A00 ;- saa1099: frequency channel 2"
  73. print"BD8B00 ;- saa1099: frequency channel 3"
  74. print"BD8C00 ;- saa1099: frequency channel 4"
  75. print"BD8D00 ;- saa1099: frequency channel 5"
  76. print"BD9000 ;- saa1099: octave channels 0 and 1"
  77. print"BD9100 ;- saa1099: octave channels 2 and 3"
  78. print"BD9200 ;- saa1099: octave channels 4 and 5"
  79. print"BD8000 ;- saa1099: volume channel 0"
  80. print"BD8100 ;- saa1099: volume channel 1"
  81. print"BD8200 ;- saa1099: volume channel 2"
  82. print"BD8300 ;- saa1099: volume channel 3"
  83. print"BD8400 ;- saa1099: volume channel 4"
  84. print"BD8500 ;- saa1099: volume channel 5"
  85. lct=0
  86. dim octtm[16]:dim octou[16]
  87. open finp$ for input as #1
  88. while eof(1)=0
  89. file input #1,txrd$
  90. setcaption("b:"+str$(lct)):lct+=1
  91. if mid$(txrd$,1,1)="[" then:
  92. if mid$(txrd$,2,1)="f" then:
  93. chid=val(mid$(txrd$,3,2))
  94. chid=chid mod 12 'saa1099x2 has 12 channels
  95. chfqv=vldc(lstinf$(txrd$,":","]"))
  96. freq=16.35159783129*2^chfqv
  97. chfqvoc=8-int( log(15625/freq)/log(2) )
  98. chfqvnt=511-int(((15625 *(2^chfqvoc) )/freq))
  99. octtm[chid]=chfqvoc mod 16
  100. octou[int(chid/2)]=octtm[int(chid/2)*2+1]*16+octtm[int(chid/2)*2]
  101. if int (chid/6)=0 then
  102. txrgo$="BD"+right$("00"+hex$(8+(chid mod 6)),2)+right$("00"+hex$(chfqvnt),2)
  103. txrgo$+=" BD"+right$("00"+hex$(16+int((chid mod 6)/2)),2)+right$("00"+hex$(octou[int(chid/2)]),2)
  104. else
  105. txrgo$="BD"+right$("00"+hex$(128+8+(chid mod 6)),2)+right$("00"+hex$(chfqvnt),2)
  106. txrgo$+=" BD"+right$("00"+hex$(128+16+int((chid mod 6)/2)),2)+right$("00"+hex$(octou[int(chid/2)]),2)
  107. end if
  108. print ucase$(txrgo$)
  109. end if
  110. if mid$(txrd$,2,1)="v" then:
  111. chid=val(mid$(txrd$,3,2))
  112. chid=chid mod 12 'saa1099x2 has 12 channels
  113. chvlv=vldc(lstinf$(txrd$,":","]"))*0x10
  114. chvlv=int(chvlv) mod 0x10
  115. chchrvl$=right$("00"+hex$(chvlv*0x11),2)
  116. if int (chid/6)=0 then
  117. txrgo$="BD"+right$("00"+hex$(chid mod 6),2)+chchrvl$
  118. else
  119. txrgo$="BD"+right$("00"+hex$(128+(chid mod 6)),2)+chchrvl$
  120. end if
  121. print ucase$(txrgo$)
  122. end if
  123. if mid$(txrd$,2,3)="wvb" then:
  124. wvblv=vldc(lstinf$(txrd$,":","]"))
  125. wvblv2=wvblv*44100
  126. wvblv3a=wvblv2 mod 65536
  127. wvblv3b=int(wvblv2/65536)
  128. wvblv3as$=ucase$(right$("0000"+hex$(wvblv3a),4))
  129. for ii=1 to wvblv3b:print"61FFFF":next
  130. print "61"+mid$(wvblv3as$,3,2)+mid$(wvblv3as$,1,2)
  131. end if
  132. end if
  133. wend
  134. print:print "66":print
  135. close #1
  136. 'from Simon Owen
  137. ' freq=(15625*(2^octave))/(511-note)
  138. ' octave=8-int(log2(15625/freq))
  139. ' note=511-int(((15625<<octave)/freq))
  140. 'octave=8-int( log(15625/freq)/log(2) )
  141. 'note=511-int(((15625 *(2^octave) )/freq))
  142. '16.35159783129*2^((9/12)+4) = 440hz