123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- #! /usr/bin/sdlbrt
- finp$="F1Spirit_msx_01_F1Shuffle.vgm"
- cbstr$="org.tildearrow.furnace - Pattern Data (103)"
- '- .vgm to furnace tracker clipboard converter - AY-3-8910 , k051649
- '- copyleft nitrofurano, may'22
- '-------------------------------
- '- bugs:
- '- - pattern-long delay maybe related to sample data transfering?
- '-------------------------------
- ltxtm$="...........|...........|...........|...........|...........|...........|...........|...........|":ltxcr$=ltxtm$
- instch$="0102030404040404"
- dim frqaa[16],frqka[16],volaa[16],volka[16],wfca[32,32]
- dim hdrv[256],wfc0[32],wfc1[32],wfc2[32],wfc3[32],wfc4[32]
- frqaa[0]=0:frqaa[1]=0:frqaa[2]=0:volaa[0]=0:volaa[1]=0:volaa[2]=0
- patsz=64:patc=0:patid=0:freqq=0:hdram=0x40:vgmv=0:veof=0
- frqka[0]=0:frqka[1]=0:frqka[2]=0:frqka[3]=0:frqka[4]=0
- volka[0]=0:volka[1]=0:volka[2]=0:volka[3]=0:volka[4]=0
-
- if argc>2 then:finp$=argv(2):end if
- fout2$=finp$+"_furnaceclipboard.txt":fout3$=finp$+"_furnaceclipboard_debug.txt"
-
- frmc=0:frmr=300:trg=0
-
- frmi=735
- if argc>3 then:
- if argv(3)="1" or ucase$(argv(2))="-PAL" then
- frmi=882:end if:end if
-
- debug=0
- if argc>4 then:
- if argv(4)="1" or ucase$(argv(2))="-DEBUG" then
- debug=1:end if:end if
- debug=1 '- remove this linecode later... xD
-
- '- fix: 0x0FE=440hz=A-4
- function nttfrq$(freqb)
- e$= "C-1C#1D-1D#1E-1F-1F#1G-1G#1A-1A#1B-1"
- e$=e$+"C-2C#2D-2D#2E-2F-2F#2G-2G#2A-2A#2B-2"
- e$=e$+"C-3C#3D-3D#3E-3F-3F#3G-3G#3A-3A#3B-3"
- e$=e$+"C-4C#4D-4D#4E-4F-4F#4G-4G#4A-4A#4B-4"
- e$=e$+"C-5C#5D-5D#5E-5F-5F#5G-5G#5A-5A#5B-5"
- e$=e$+"C-6C#6D-6D#6E-6F-6F#6G-6G#6A-6A#6B-6"
- e$=e$+"C-7C#7D-7D#7E-7F-7F#7G-7G#7A-7A#7B-7"
- e$=e$+"B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7"
- e$=e$+"B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7B-7..."
- tmq=141-(int((log(freqb*.99)/log(2))*12))
- if tmq<1 then:tmq=1:end if
- if tmq>97 then:tmq=97:end if
- return mid$(e$,(tmq*3)-2,3)
- end function
-
- open finp$ for input as #1
- for i=0 to 255
- hdrv[i]=readbyte(1)
- next
- close #1
-
- hdram=0x040
- vgmv=hdrv[8]+hdrv[9]*256
- if vgmv>=0x0150 then:hdram=0x080:end if
- if vgmv>=0x0160 then:hdram=0x0C0:end if
- if vgmv>=0x0170 then:hdram=0x100:end if
- '- wrong information???
- ttsam=hdrv[0x18]+hdrv[0x19]*256+hdrv[0x1A]*65536+hdrv[0x1B]*16777216
- hsam$="PlayOrder=L0"
- for i=1 to (ttsam/(frmi*patsz))-1
- hsam$=hsam$+","+str$(i)
- next
-
- open finp$ for input as #1
- open fout2$ for output as #2
- open fout3$ for output as #3
- print #2,"---------8<----------------------------------------------"
- print #2,"[Pattern00]"
- print #2," "
- print #2,cbstr$
- print #2,"0"
- '- the amount of header bytes depends on vgm format version
- for eee=0 to hdram-1:q0=readbyte(1):next '- read offset byte first
- txou1$=" #("+str$(0)+")"
-
- while veof=0:
- q0=readbyte(1)
-
- '- vgm eof command
- if q0=0x66 then:
- veof=1
- print #3,"--vgm-eof--"
- print #2," "
- end if
-
- '- delay 1 byte (1..16 samples)
- if bitwiseand(q0,0x70)=0x70 then
- frmc=frmc+bitwiseand(q0,0xF)+1
- txou1$=" #("+str$(frmc)+")"
- 'print #3,txou1$
- end if
-
- '- delay 3 bytes (0..65535 samples)
- if q0=0x61 then
- q0=readbyte(1)
- frmc=frmc+q0
- q0=readbyte(1)
- frmc=frmc+(q0*256)
- txou1$=" #("+str$(frmc)+")"
- 'print #3,txou1$
- end if
-
- '- 1 ntsc frame delay, 735 samples
- if q0=0x62 then
- frmc=frmc+735
- txou1$=" #("+str$(frmc)+")"
- 'print #3,txou1$
- end if
-
- '- 1 pal frame delay, 882 samples
- if q0=0x63 then
- frmc=frmc+882
- txou1$=" #("+str$(frmc)+")"
- 'print #3,txou1$
- end if
- '- updates frameout pulses
- while frmr<frmc
-
- '- creates a new pattern
- if patc>(patsz-1) then:
- print #2," "
- patid=patid+1:patc=0
- txou9$="[Pattern"+ucase$(right$(hex$(0x100+patid),2))+"]"
- print #2,"---------8<----------------------------------------------"
- print #2,txou9$
- print #2,""
- print #2,cbstr$
- print #2,"0"
- end if
-
- '- writes a pattern line in each frame
- if trg=0 then
- print #3,"--frameout-unchanged--"
- print #2,ltxtm$
- else
- print #3,"--frameout--"
- print #2,ltxcr$
- ltxcr$=ltxtm$
- trg=0
- end if
-
- frmr=frmr+frmi
- patc=patc+1
- end while
-
- '-------------------------------------------------------------------------------
- '- ay
-
- '- token 0xA0 gets registers and values to AY-3-8910 output
- if q0=0xA0 then
- q0=readbyte(1)
- '-------------------------------------------------------------------------------
- '- frequencies/notes on ay - channel 0 to 2
- if (q0>=0 and q0<=5) then
- q0qq=q0
- qqch=int(q0/2)
- q0=readbyte(1)
- if q0qq mod 2=0 then
- frqaa[qqch]=bitwiseor((bitwiseand(frqaa[qqch],0xF00)),(bitwiseand(q0,0x0FF))) '- fine
- else
- frqaa[qqch]=bitwiseor((bitwiseand(q0*256,0xF00)),(bitwiseand(frqaa[qqch],0x0FF))) '- coarse
- end if
- ltxtm1$=ltxtm$
- ltxtm2$=replace$((12*qqch),ltxtm1$,nttfrq$(frqaa[qqch])+"00")
- ltxcr$=replace$((12*qqch),ltxcr$,nttfrq$(frqaa[qqch])+"00")
- print #3,ltxtm2$
- trg=1
- end if
- '-------------------------------------------------------------------------------
- '- volume on ay, channels 0 to 2
- if (q0>=8 and q0<=10) then
- chqq=q0-8
- q0=readbyte(1)
- volaa[chqq]=bitwiseand(q0,0x0F)
- ltxtm1$=ltxtm$
- ltxtm2$=replace$((12*chqq)+5,ltxtm1$,""+ucase$(right$(hex$(0x100+volaa[chqq]*1),2)))
- ltxcr$=replace$((12*chqq)+5,ltxcr$,""+ucase$(right$(hex$(0x100+volaa[chqq]*1),2)))
- print #3,ltxtm2$
- trg=1
- end if
- '-------------------------------------------------------------------------------
- '-
- '?????
- if q0=6 then
- print #3,ltxtm$
- end if
- '?????
- 'if q0=7 then
- ' q0=readbyte(1)
- ' ltxtm1$=ltxtm$
- ' ltxtm2$=left$(ltxtm1$,31)+ right$(bin$(512+q0),8) +right$(ltxtm1$,2)+txou1$
- ' print #3,ltxtm2$
- ' trg=1
- ' end if
- '-------------------------------------------------------------------------------
- end if
- '-------------------------------------------------------------------------------
- '- k051649
- '- token 0xD2 gets registers and values to K051649 output
- if q0=0xD2 then
- q0=readbyte(1)
- '-------------------------------------------------------------------------------
- '- k051649 waveform '(bug? why it does create delay?) - change to bidimensional array?
- if q0=0x00 then '- write waveform
- q0=readbyte(1)
- q2=int(q0/32)
- if (q2>=0 and q2<=4) then '- verificar diferença entre k051649 e k052539?
- q1=readbyte(1)
- wfca[q2,bitwiseand(q0,31)]=q1
- if q2=3 then:
- wfca[4,bitwiseand(q0,31)]=q1
- end if
- end if
- end if
- '-------------------------------------------------------------------------------
- '- k051649 frequency/notes - channels 0 to 4
- if q0=0x01 then '- set frequency
- q0=readbyte(1)
- if (q0>=0 and q0<=9) then
- q0qq=q0
- qqch=int(q0/2)
- q0=readbyte(1)
- if q0qq mod 2=0 then
- frqka[qqch]=bitwiseor((bitwiseand(frqka[qqch],0xF00)),(bitwiseand(q0,0x0FF))) '- fine
- else
- frqka[qqch]=bitwiseor((bitwiseand(q0*256,0xF00)),(bitwiseand(frqka[qqch],0x0FF))) '- coarse
- end if
- ltxtm1$=ltxtm$
- ltxtm2$=replace$((12*(qqch+3)),ltxtm1$,nttfrq$(frqka[qqch])+ mid$(instch$,qqch*2+1,2) )
- ltxcr$=replace$((12*(qqch+3)),ltxcr$,nttfrq$(frqka[qqch])+ mid$(instch$,qqch*2+1,2) )
- print #3,ltxtm2$
- trg=1
- end if
- end if
- '-------------------------------------------------------------------------------
- '- k051649 volume - channels 0 to 4
- if q0=0x02 then '- set volume
- q0=readbyte(1)
- if (q0>=0 and q0<=4) then
- chqq=q0
- q0=readbyte(1)
- volka[chqq]= bitwiseand(q0,0x0F)
- ltxtm1$=ltxtm$
- ltxtm2$=replace$((12*(chqq+3))+5,ltxtm1$,""+ucase$(right$(hex$(0x100+volka[chqq]*1),2)))
- ltxcr$=replace$((12*(chqq+3))+5,ltxcr$,""+ucase$(right$(hex$(0x100+volka[chqq]*1),2)))
- print #3,ltxtm2$
- trg=1
- end if
- end if
- '-------------------------------------------------------------------------------
- end if
- '-------------------------------------------------------------------------------
- if eof(1)<>0 then:veof=1:end if
- wend
- print #2," "
- print #2,"[Waveform0] (hex)"
- print #2,"1F 1F 1F 1F 1F 1F 1F 1F 1F 1F 1F 1F 1F 1F 1F 1F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 "
- print #2," "
- for j=0 to 4
- txousm$=""
- for i=0 to 31
- txousm$=txousm$+ucase$(right$(hex$(0x100+int(wfca[j,i]/8)),2))+" "
- next
- print #2,"[Waveform"+right$(hex$(j+1),1)+"] (hex)"
- print #2,txousm$
- print #2," "
- next
- '--------------------------------
- close #1:close #2:close #3
-
- if debug=0 then:
- shell("rm "+fout3$)
- end if
|