mod2hexdump.sdlbasic 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. '- .mod to hexdump converter
  2. '- copyleft Paulo Silva, oct'20
  3. '-------------------------------
  4. '- bugs:
  5. '- weird conversion from .mod files with channel amount different than 4
  6. '-------------------------------
  7. function nttfrq$(freqb)
  8. e$= "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
  9. e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
  10. e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
  11. e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
  12. e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
  13. e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
  14. e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
  15. e$=e$+"C-8C#8D-8D#8E-8F-8F#8G-8G#8A-8A#8B-8..."
  16. tmq=141-(int((log(freqb*.99)/log(2))*12))
  17. if tmq<1 then:tmq=1:end if
  18. if tmq>97 then:tmq=97:end if
  19. return mid$(e$,(tmq*3)-2,3)
  20. end function
  21. dim dmp[900000]
  22. dim smplng[64]
  23. finp$="tune.mod"
  24. if argc>2 then:finp$=argv(2):end if
  25. fout2$=finp$+"_hexdump.txt":fout3$=finp$+"_hexdump_debug.txt"
  26. open finp$ for input as #1
  27. open fout2$ for output as #2
  28. bcntr=0
  29. while eof(1)=0 and bcntr<900000:
  30. brd=readbyte(1)
  31. dmp[bcntr]=brd
  32. bcntr+=1
  33. end while
  34. '- header
  35. print #2,";- .mod hexdump":print #2,""
  36. '- songname
  37. txou$=""
  38. ascou$=""
  39. for rd=1 to 20
  40. brd=dmp[0+rd-1]
  41. txou$+=ucase$(right$(hex$(0x100+brd),2))
  42. if brd>=32 then:
  43. ascou$+=chr$(brd)
  44. end if
  45. next
  46. txou$+=" ;- Songname: \""+ascou$+"\""
  47. print #2,txou$:print #2,""
  48. '- samples
  49. for smpl=1 to 31
  50. print #2,";Sample "+right$("000"+str$(smpl),2)
  51. txou$="":ascou$="":valou=0
  52. for rd=1 to 22
  53. brd=dmp[20+((smpl-1)*30)+rd-1]
  54. txou$+=ucase$(right$(hex$(0x100+brd),2))
  55. if brd>=32 then:
  56. ascou$+=chr$(brd)
  57. end if
  58. next
  59. txou$+=" ;- Sample Name "+right$("000"+str$(smpl),2)+": \""+ascou$+"\""
  60. print #2,txou$:
  61. txou$="":ascou$="":valou=0
  62. for rd=1 to 2
  63. brd=dmp[42+((smpl-1)*30)+rd-1]
  64. txou$+=ucase$(right$(hex$(0x100+brd),2))
  65. valou=(valou*256)+brd
  66. next
  67. smplng[smpl]=valou
  68. txou$+=" ;- Sample Lenght "+right$("000"+str$(smpl),2)+": "+str$(valou*2)
  69. print #2,txou$
  70. txou$="":ascou$="":valou=0
  71. for rd=1 to 1
  72. brd=dmp[44+((smpl-1)*30)+rd-1]
  73. txou$+=ucase$(right$(hex$(0x100+brd),2))
  74. valou=(valou*256)+brd
  75. next
  76. txou$+=" ;- Sample Finetune "+right$("000"+str$(smpl),2)+": "+str$(((valou+8)mod 16)-8)
  77. print #2,txou$
  78. txou$="":ascou$="":valou=0
  79. for rd=1 to 1
  80. brd=dmp[45+((smpl-1)*30)+rd-1]
  81. txou$+=ucase$(right$(hex$(0x100+brd),2))
  82. valou=(valou*256)+brd
  83. next
  84. txou$+=" ;- Sample Volume "+right$("000"+str$(smpl),2)+": "+str$(valou)
  85. print #2,txou$
  86. txou$="":ascou$="":valou=0
  87. for rd=1 to 2
  88. brd=dmp[46+((smpl-1)*30)+rd-1]
  89. txou$+=ucase$(right$(hex$(0x100+brd),2))
  90. valou=(valou*256)+brd
  91. next
  92. txou$+=" ;- Sample Repeat Point "+right$("000"+str$(smpl),2)+": "+str$(valou*2)
  93. print #2,txou$
  94. txou$="":ascou$="":valou=0
  95. for rd=1 to 2
  96. brd=dmp[48+((smpl-1)*30)+rd-1]
  97. txou$+=ucase$(right$(hex$(0x100+brd),2))
  98. valou=(valou*256)+brd
  99. next
  100. txou$+=" ;- Sample Repeat Lenght "+right$("000"+str$(smpl),2)+": "+str$(valou*2)
  101. print #2,txou$
  102. print #2,""
  103. next
  104. txou$="":ascou$="":valou=0
  105. for rd=1 to 1
  106. brd=dmp[950+rd-1]
  107. txou$+=ucase$(right$(hex$(0x100+brd),2))
  108. valou=(valou*256)+brd
  109. next
  110. txou$+=" ;- Song Lenght: "
  111. print #2,txou$
  112. txou$="":ascou$="":valou=0
  113. for rd=1 to 1
  114. brd=dmp[951+rd-1]
  115. txou$+=ucase$(right$(hex$(0x100+brd),2))
  116. valou=(valou*256)+brd
  117. next
  118. txou$+=" ;- Flag: "
  119. print #2,txou$
  120. print #2,""
  121. '- song positions
  122. mxptn=0
  123. print #2,";- Song Positions:"
  124. for smpl=1 to 128 step 8
  125. 'print #2,";Sample "+str$(smpl)
  126. txou$="":ascou$="":valou=0
  127. for rd=1 to 8
  128. brd=dmp[952+((smpl-1)*1)+rd-1]
  129. if brd>=mxptn then:mxptn=brd:end if
  130. txou$+=ucase$(right$(hex$(0x100+brd),2))+" "
  131. next
  132. 'txou$+=" ;- Name: \""+ascou$+"\""
  133. print #2,txou$:
  134. next
  135. print #2,""
  136. '- signature
  137. txou$="":ascou$="":valou=0
  138. for rd=1 to 4
  139. brd=dmp[1080+rd-1]
  140. txou$+=ucase$(right$(hex$(0x100+brd),2))+" "
  141. if brd>=32 then:
  142. ascou$+=chr$(brd)
  143. end if
  144. next
  145. print #2,txou$+" ;- Signature: \""+ascou$+"\""
  146. print #2,""
  147. sgnt1$=ascou$
  148. chanamt=4
  149. if sgnt1$="M.K." then:
  150. chanamt=4
  151. end if
  152. if right$(sgnt1$,3)="CHN" or right$(sgnt1$,3)="FLT" then:
  153. chanamt=val(mid$(sgnt1$,1,1))
  154. end if
  155. if right$(sgnt1$,2)="CH" or right$(sgnt1$,2)="FL" then:
  156. chanamt=(val(mid$(sgnt1$,1,1)))*10+(val(mid$(sgnt1$,2,1)))
  157. end if
  158. txoutpt$=";-|"
  159. for iqq=0 to chanamt-1
  160. txoutpt$+=" ... .. ... |"
  161. next
  162. '- patterns
  163. print #2,";- Patterns:":print #2,""
  164. for patrn=0 to mxptn
  165. print #2,";Pattern "+ucase$( right$( hex$(0x100+patrn) ,2) )
  166. for rowl=0 to 63
  167. txou$="":ascou$="":valou=0
  168. 'txoub$=";-| ... .. ... | ... .. ... | ... .. ... | ... .. ... |"
  169. txoub$=txoutpt$
  170. for rdr=0 to chanamt-1
  171. vlq0=dmp[1084+(patrn*(chanamt*256))+0+(rdr*4)+(rowl*(chanamt*4))]
  172. vlq1=dmp[1084+(patrn*(chanamt*256))+1+(rdr*4)+(rowl*(chanamt*4))]
  173. vlq2=dmp[1084+(patrn*(chanamt*256))+2+(rdr*4)+(rowl*(chanamt*4))]
  174. vlq3=dmp[1084+(patrn*(chanamt*256))+3+(rdr*4)+(rowl*(chanamt*4))]
  175. vfrq= (bitwiseand (vlq0,15)*256)+vlq1
  176. vsmp= (bitwiseand (vlq0,240))+(bitwiseand (vlq2,240)/16)
  177. veff= (bitwiseand (vlq2,15)*256)+vlq3
  178. if vfrq<>0 then:
  179. txoub$= replace$(4+(13*rdr),txoub$,nttfrq$(vfrq))
  180. end if
  181. if vsmp<>0 then:
  182. txoub$= replace$(8+(13*rdr),txoub$,ucase$(right$( hex$(0x1000+vsmp ),2)))
  183. end if
  184. if veff<>0 then:
  185. txoub$= replace$(11+(13*rdr),txoub$,ucase$(right$( hex$(0x1000+veff ),3)))
  186. end if
  187. for rdn=0 to 3
  188. brd=dmp[1084+(patrn*(chanamt*256))+rdn+(rdr*4)+(rowl*(chanamt*4))]
  189. txou$+=ucase$(right$(hex$(0x100+brd),2))
  190. next
  191. txou$+=" "
  192. next
  193. txou$+=txoub$
  194. print #2,txou$:
  195. next
  196. print #2,""
  197. next
  198. adrsmp=1084+((mxptn+1)*(chanamt*256))
  199. close #1
  200. open finp$ for input as #1
  201. for zrd=1 to adrsmp
  202. zdum=readbyte(1)
  203. next
  204. '- samples
  205. print #2,";- Samples:":
  206. print #2,""
  207. for smpl=1 to 31
  208. print #2,";Sample Hexdump "+right$("000"+str$(smpl),2)
  209. txou$="":ascou$="":valou=0
  210. for rd=0 to (smplng[smpl]*2)-1
  211. brd=readbyte(1)
  212. txou$+=ucase$(right$(hex$(0x100+brd),2))
  213. if bitwiseand (rd,31)=31 then:
  214. print #2,txou$
  215. txou$=""
  216. end if
  217. next
  218. print #2,txou$
  219. print #2,""
  220. next
  221. print #2,""
  222. print #2,";- end of file"
  223. print #2,""
  224. close #1:close #2