and this is how to load and print out the
contents of the first pattern of a .xm module
' initial release of .xm library
base=LoadBank("corona.xm")
Print "total size"+BankSize(base)
modname:String=getstring(base,17,36)
Print "name:"+modname
tracker:String=getstring(base,38,57)
Print "made with:"+tracker
hs=PeekByte(base,60)+PeekByte(base,61)*256+PeekByte(base,62)*65536+PeekByte(base,63)*16777216
Print "header size:"+hs
hs:+60 ' gives end of header
slen=getword(base,64)
Print "song length:"+slen
restart=getword(base,66)
Print "song restart:"+restart
chans=getword(base,68)
Print "channels:"+chans
pats=getword(base,70)
Print "pattern:"+pats
instrm=getword(base,72)
Print "instruments:"+instrm
flags=getword(base,74)
Print "flags:"+flags
Local s:String
If flags & 1 Then s="Linear " Else s="Amiga "
Print s+"freq table"
tempo=getword(base,76)
Print "tempo:"+tempo
bmp=getword(base,78)
Print "bmp:"+bmp
patheadlen=PeekByte(base,hs)+PeekByte(base,hs+1)*256+PeekByte(base,hs+2)*65536+PeekByte(base,hs+3)*16777216
Print "pattern head length:"+patheadlen
rows=getword(base,hs+5)
Print "rows:"+rows
patsize=getword(base,hs+7)
Print "pattern data size:"+patsize
patbase=hs+9
Print "pattern data start:"+patbase
line:String=""
For l=1 To rows
For i=1 To chans
line:+readnote(base,patbase)+" :: "
Next
Print line
line=""
next
I'd be delighted if some one would add to this as part
of a comunity project.
oops forgot this
' Period = 10*12*16*4 - Note*16*4 - FineTune/2;
' Frequency = 8363*2^((6*12*16*4 - Period) / (12*16*4));
' honest guv
Function readnote:String(where,from Var)
Global notestr:String[]=["C-","C#","D-","D#","E-","F-","F#","G-","G#","A-","A#","B-"]
Local s:String,c:Byte,n:Byte
s=""
c=PeekByte(where,from)
from:+1
If(c&128) Then
If(c&1) Then
n=PeekByte(where,from)-1
s:+ " N"+notestr[(n Mod 12)]+Byte(n/12)
from:+1
Else
s:+ " "
EndIf
If(c&2) Then
s:+ " I"+Right(Hex(PeekByte(where,from)),2)
from:+1
Else
s:+ " "
EndIf
If(c&4) Then
s:+ " V"+Right(Hex(PeekByte(where,from)-16),2)
from:+1
Else
s:+ " "
EndIf
If(c&8) Then
s:+ " E"+Right(Hex(PeekByte(where,from)),2)
from:+1
Else
s:+ " "
EndIf
If(c&16) Then
s:+ " D"+Right(Hex(PeekByte(where,from)),2)
from:+1
Else
s:+ " "
EndIf
Else
s:+ " N"+notestr[(c Mod 12)-1]+Byte(c/12)
s:+ " I"+Right(Hex(PeekByte(where,from)),2)
from:+1
s:+ " V"+Right(Hex(PeekByte(where,from)-16),2)
from:+1
s:+ " E"+Right(Hex(PeekByte(where,from)),2)
from:+1
s:+ " D"+Right(Hex(PeekByte(where,from)),2)
from:+1
EndIf
Return s
EndFunction
Function getword:Int(where,start)
Return PeekByte(where,start)+PeekByte(where,start+1)*256
End Function
Function getstring:String(where,start,last)
Local s:String=""
For Local x=start To last
If PeekByte(where,x)<>0 Then s:+Chr(PeekByte(where,x))
'Print s
Next
Return s
End Function