summaryrefslogtreecommitdiff
path: root/src/JSystem/JAudio/JASChGlobal.cpp
blob: 6d7181e089e744b90ca3a7b20e5531ba84b6e4d5 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// Generated by dtk
// Translation Unit: JASChGlobal.cpp
//

#include "JSystem/JSystem.h" // IWYU pragma: keep

#include "JSystem/JAudio/JASChGlobal.h"
#include "JSystem/JAudio/JASChAllocQueue.h"
#include "JSystem/JAudio/JASChannel.h"
#include "JSystem/JAudio/JASChannelMgr.h"
#include "JSystem/JAudio/JASSystemHeap.h"
#include "JSystem/JKernel/JKRSolidHeap.h"
#include "JSystem/JUtility/JUTAssert.h"

JASystem::TChannelMgr* JASystem::TGlobalChannel::sChannelMgr;
JASystem::TChannel* JASystem::TGlobalChannel::sChannel;
JASystem::TOscillator* JASystem::TGlobalChannel::sOscillator;

/* 8028AAEC-8028AB58       .text getChannelHandle__Q28JASystem14TGlobalChannelFUl */
JASystem::TChannel* JASystem::TGlobalChannel::getChannelHandle(u32 ch_num) {
    JUT_ASSERT(34, ch_num < (256));
    return sChannel + ch_num;
}

/* 8028AB58-8028AD50       .text init__Q28JASystem14TGlobalChannelFv */
void JASystem::TGlobalChannel::init() {
    sChannelMgr = new (JASDram, 32) TChannelMgr();
    JUT_ASSERT(44, sChannelMgr);
    TChannelMgr* mgr = sChannelMgr;
    mgr->init();
    sChannel = new (JASDram, 32) TChannel[256];
    JUT_ASSERT(50, sChannel);
    sOscillator = new (JASDram, 32) TOscillator[1024];
    JUT_ASSERT(52, sOscillator);
    for (int i = 0; i < 256; i++) {
        for (u32 j = 0; j < 4; j++) {
            sChannel[i].setOscillator(j, &sOscillator[i * 4 + j]);
        }
        sChannel[i].init();
        mgr->addListHead(&sChannel[i], 0);
        sChannel[i].field_0x4 = mgr;
    }
    mgr->field_0x0 = 256;
    OSReport("----- JASChannel size : %d\n", sizeof(TChannel));
}

/* 8028AD50-8028ADE8       .text alloc__Q28JASystem14TGlobalChannelFPQ28JASystem11TChannelMgrUl */
int JASystem::TGlobalChannel::alloc(TChannelMgr* param_1, u32 param_2) {
    int i;
    for (i = 0; i < param_2; i++) {
        TChannel* channel = sChannelMgr->getListHead(0);
        if (!channel) {
            break;
        }
        param_1->addListHead(channel, 0);
        channel->field_0x4 = param_1;
        channel->init();
    }
    param_1->field_0x0 += i;
    sChannelMgr->field_0x0 -= i;
    return i;
}

/* 8028ADE8-8028AE4C       .text release__Q28JASystem14TGlobalChannelFPQ28JASystem8TChannel */
int JASystem::TGlobalChannel::release(TChannel* param_1) {
    sChannelMgr->addListHead(param_1, 0);
    param_1->field_0x4->field_0x0--;
    sChannelMgr->field_0x0++;
    param_1->field_0x4 = sChannelMgr;
    return 0;
}

/* 8028AE4C-8028AF8C       .text releaseAll__Q28JASystem14TGlobalChannelFPQ28JASystem11TChannelMgr */
int JASystem::TGlobalChannel::releaseAll(TChannelMgr* param_1) {
    TChannel* channel;
    while (true) {
        channel = param_1->getListHead(0);
        if (!channel) {
            break;
        }
        sChannelMgr->addListHead(channel, 0);
        channel->field_0x4 = sChannelMgr;
    };
    while (true) {
        channel = param_1->getListHead(1);
        if (!channel) {
            break;
        }
        sChannelMgr->addListHead(channel, 1);
        channel->field_0x4 = sChannelMgr;
        channel->field_0xd4 = 1;
    }
    while (true) {
        channel = param_1->getListHead(2);
        if (!channel) {
            break;
        }
        sChannelMgr->addListHead(channel, 2);
        channel->field_0x4 = sChannelMgr;
        channel->field_0xd4 = 1;
    }
    while (true) {
        channel = param_1->getListHead(3);
        if (!channel) {
            break;
        }
        if (TDSPQueue::deleteQueue(channel)) {
            sChannelMgr->addListHead(channel, 0);
        } else {
            sChannelMgr->addListHead(channel, 3);
        }
        channel->field_0x4 = sChannelMgr;
    }
    sChannelMgr->field_0x0 += param_1->field_0x0;
    param_1->field_0x0 = 0;
    return 0;
}