Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
716 lvd 1
#ifndef VS1001_H
2
#define VS1001_H
3
#include "util.h"
4
 
5
#undef SD_SEND
6
 
7
// S_CTRL bits
8
const u8 _MPNCS  = 2;
9
const u8 _MPXRS  = 4;
10
const u8 _MPHLF  = 8;
11
 
12
// S_STAT bits
13
const u8 _MPDRQ  = 1;
14
 
15
const u8 S_CTRL  = 0x11; // RW
16
const u8 S_STAT  = 0x12; // R
17
 
18
const u8 SD_SEND = 0x13; // W
19
const u8 SD_READ = 0x13; // R
20
const u8 SD_RSTR = 0x14; // R
21
 
22
const u8 MD_SEND = 0x14; // W same as SD_RSTR!!!
23
 
24
const u8 MC_SEND = 0x15; // W
25
const u8 MC_READ = 0x15; // R
26
 
27
class TRingBuffer
28
{
29
    TCriticalSection CritSect;
30
    TEvent NotEmpty;
31
    const u32 Size;
32
    u8 Buf[4*1024];
33
    u32 WrPos;
34
    u32 RdPos;
35
    u32 Count;
36
    bool Dreq;
37
    bool Cancelled;
38
public:
39
    TRingBuffer() : NotEmpty(FALSE), Size(4*1024)
40
    {
41
        Cancelled = false;
42
        Reset();
43
    }
44
    void Cancel()
45
    {
46
        CritSect.Lock();
47
        Cancelled = true;
48
        NotEmpty.Set();
49
        CritSect.Unlock();
50
    }
51
    void Reset();
52
    void Put(u8 Val);
53
    u32 Get(void *Data, u32 ReqLen);
54
    bool GetDreq() const { return Dreq; }
55
};
56
 
57
class TVs1001
58
{
59
    enum TRegs
60
    {
61
       MODE = 0,   // RW
62
       STATUS,     // RW
63
       INT_FCTLH,  // NA
64
       CLOCKF,     // RW
65
       DECODE_TIME,// R
66
       AUDATA,     // R
67
       WRAM_W,     // W
68
       WRAMADDR_W, // W
69
       HDAT0,      // R
70
       HDAT1,      // R
71
       AIADDR,     // RW
72
       VOL,        // RW
73
       RESERVED,   // NA
74
       AICTRL0,    // RW
75
       AICTRL1,    // RW
76
       REG_COUNT
77
    };
78
 
79
    static const u8 SM_RESET = 4;
80
 
81
    enum TState { ST_IDLE, ST_RD, ST_WR, ST_RD_IDX, ST_WR_IDX, ST_RD_MSB, ST_RD_LSB, ST_WR_MSB, ST_WR_LSB };
82
    enum TCmd { CMD_WR = 2, CMD_RD = 3 };
83
    u16 Regs[REG_COUNT];
84
    TState CurState;
85
    bool nCs;
86
    int Idx;
87
    u8 Msb, Lsb;
88
    TRingBuffer RingBuffer;
89
    TEvent EventStreamClose;
90
    HANDLE ThreadHandle;
91
    HSTREAM Mp3Stream;
92
    static BASS_FILEPROCS Procs;
93
public:
94
    TVs1001();
95
    void Reset();
96
    void ShutDown();
97
    void SetNcs(bool nCs);
98
    void Wr(u8 Val); // sdi mpeg data write
99
    void WrCmd(u8 Val); // sci write
100
    u8 Rd(); // sci read
101
    void Play(); // play buffered data
102
    bool GetDreq() const { return RingBuffer.GetDreq(); }
103
private:
104
    void Wr(int Idx, u16 Val); // sci write
105
    u16 Rd(int Idx); // sci read
106
 
107
    void SoftReset();
108
    void SetVol(u16 Vol);
109
    u16 GetDecodeTime();
110
 
111
    void Thread();
112
    void StreamClose();
113
    QWORD StreamLen();
114
    DWORD StreamRead(void *Buffer, DWORD Length);
115
    BOOL StreamSeek(QWORD offset);
116
 
117
    static unsigned CALLBACK Thread(void *This)
118
    {
119
        ((TVs1001 *)This)->Thread();
120
        return 0;
121
    }
122
 
123
    static void CALLBACK StreamClose(void *This)
124
    { ((TVs1001 *)This)->StreamClose(); }
125
 
126
    static QWORD CALLBACK StreamLen(void *This)
127
    { return ((TVs1001 *)This)->StreamLen(); }
128
 
129
    static DWORD CALLBACK StreamRead(void *Buffer, DWORD Length, void *This)
130
    { return ((TVs1001 *)This)->StreamRead(Buffer, Length); }
131
 
132
    static BOOL CALLBACK StreamSeek(QWORD offset, void *This)
133
    { return ((TVs1001 *)This)->StreamSeek(offset); }
134
 
135
    static const char *State2Str(TState State);
136
};
137
 
138
extern TVs1001 Vs1001;
139
#endif