summaryrefslogtreecommitdiff
path: root/fym.js
blob: 8ee4cc30eac4a484deca8f47dce6141b44850bf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
FYMReader = function(buffer) {
    var psgDump = pako.inflate(new Uint8Array(buffer));
    var ptr = 0;
    var frame = 0;

    function getInt() {
        var r = 0;
        for(var i = 0; i < 4; i++) r += psgDump[ptr++] << (8*i);
        return r;
    }

    function getStr() {
        var c, r = '';
        while(c = psgDump[ptr++]) r += String.fromCharCode(c);
        return r;
    }

    var offset = getInt();

    var frameCount = getInt();
    this.getFrameCount = function() {
        return frameCount;
    }

    var loopFrame = getInt();
    this.getLoopFrame = function() {
        return loopFrame;
    }

    var clockRate = getInt();
    this.getClockRate = function() {
        return clockRate;
    }

    var frameRate = getInt();
    this.getFrameRate = function() {
        return frameRate;
    }

    var trackName = getStr();
    this.getTrackName = function() {
        return trackName;
    }

    var authorName = getStr();
    this.getAuthorName = function() {
        return authorName;
    }

    var loopCount = 0;
    this.getLoopCount = function() {
        return loopCount;
    }

    this.getNextFrame = function() {
        var regs = [];
        for(var r = 0; r < 14; r++) {
            regs[r] = psgDump[r * frameCount + frame + offset];
        }
        if(++frame >= frameCount) {
            loopCount++;
            frame = loopFrame;
        }
        return regs;
    }
}