1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_PlayerHeap.cpp
4
5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Revision: 22284 $
14 *---------------------------------------------------------------------------*/
15
16 #include "precompiled.h"
17
18 #include <nw/snd/snd_PlayerHeap.h>
19 #include <nw/snd/snd_SoundThread.h>
20 #include <nw/snd/snd_DisposeCallbackManager.h>
21
22 namespace nw {
23 namespace snd {
24 namespace internal {
25
26 /*---------------------------------------------------------------------------*
27 Name: SoundHeap
28
29 Description: コンストラクタ
30
31 Arguments: 無し
32
33 Returns: 無し
34 *---------------------------------------------------------------------------*/
PlayerHeap()35 PlayerHeap::PlayerHeap()
36 : m_pSound( NULL ),
37 m_pPlayer( NULL ),
38 m_pStartAddress( NULL ),
39 m_pEndAddress( NULL ),
40 m_pAllocAddress( NULL )
41 {
42 }
43
44 /*---------------------------------------------------------------------------*
45 Name: ~PlayerHeap
46
47 Description: デストラクタ
48
49 Arguments: 無し
50
51 Returns: 無し
52 *---------------------------------------------------------------------------*/
~PlayerHeap()53 PlayerHeap::~PlayerHeap()
54 {
55 Destroy();
56 }
57
58 /*---------------------------------------------------------------------------*
59 Name: Create
60
61 Description:
62
63 Arguments: startAddress -
64 size -
65
66 Returns:
67 *---------------------------------------------------------------------------*/
Create(void * startAddress,size_t size)68 bool PlayerHeap::Create( void* startAddress, size_t size )
69 {
70 void* endAddress = ut::AddOffsetToPtr( startAddress, size );
71 startAddress = ut::RoundUp( startAddress, 32 );
72 if ( startAddress > endAddress ) return false;
73
74 m_pStartAddress = startAddress;
75 m_pEndAddress = endAddress;
76 m_pAllocAddress = m_pStartAddress;
77
78 return true;
79 }
80
81 /*---------------------------------------------------------------------------*
82 Name: Destroy
83
84 Description:
85
86 Arguments: なし
87
88 Returns: なし
89 *---------------------------------------------------------------------------*/
Destroy()90 void PlayerHeap::Destroy()
91 {
92 Clear();
93 m_pAllocAddress = NULL;
94 }
95
96 /*---------------------------------------------------------------------------*
97 Name: Alloc
98
99 Description:
100
101 Arguments: size -
102
103 Returns:
104 *---------------------------------------------------------------------------*/
Alloc(size_t size)105 void* PlayerHeap::Alloc( size_t size )
106 {
107 NW_ALIGN32_ASSERT( m_pAllocAddress );
108
109 void* endp = ut::AddOffsetToPtr( m_pAllocAddress, size );
110 if ( endp > m_pEndAddress ) return NULL;
111
112 void* allocAddress = m_pAllocAddress;
113 m_pAllocAddress = ut::RoundUp( endp, 32 );
114 return allocAddress;
115 }
116
117 /*---------------------------------------------------------------------------*
118 Name: Clear
119
120 Description:
121
122 Arguments: なし
123
124 Returns: なし
125 *---------------------------------------------------------------------------*/
Clear()126 void PlayerHeap::Clear()
127 {
128 internal::DriverCommandManager& cmdmgr = internal::DriverCommandManager::GetInstance();
129
130 internal::DriverCommandInvalidateData* command =
131 cmdmgr.AllocCommand<internal::DriverCommandInvalidateData>();
132 command->id = internal::DRIVER_COMMAND_INVALIDATE_DATA;
133 command->mem = m_pStartAddress;
134 command->size = static_cast<unsigned long>( ut::GetOffsetFromPtr( m_pStartAddress, m_pAllocAddress ) );
135 cmdmgr.PushCommand(command);
136
137 m_pAllocAddress = m_pStartAddress;
138 }
139
140 /*---------------------------------------------------------------------------*
141 Name: GetFreeSize
142
143 Description:
144
145 Arguments: なし
146
147 Returns:
148 *---------------------------------------------------------------------------*/
GetFreeSize() const149 size_t PlayerHeap::GetFreeSize() const
150 {
151 size_t offset = ut::GetOffsetFromPtr( m_pAllocAddress, m_pEndAddress );
152 NW_ASSERT( offset >= 0 );
153 // return static_cast<size_t>( offset );
154 return offset;
155 }
156
157 /*---------------------------------------------------------------------------*
158 Name: AttachSound
159
160 Description: サウンドと結びつける
161
162 Arguments: sound - 結びつけるサウンド
163
164 Returns: None.
165 *---------------------------------------------------------------------------*/
AttachSound(BasicSound * sound)166 void PlayerHeap::AttachSound( BasicSound* sound )
167 {
168 NW_NULL_ASSERT( sound );
169 NW_ASSERT( m_pSound == NULL );
170
171 m_pSound = sound;
172 }
173
174 /*---------------------------------------------------------------------------*
175 Name: DetachSound
176
177 Description: サウンドと切り離す
178
179 Arguments: sound - 切り離すサウンド
180
181 Returns: None.
182 *---------------------------------------------------------------------------*/
DetachSound(BasicSound * sound)183 void PlayerHeap::DetachSound( BasicSound* sound )
184 {
185 NW_NULL_ASSERT( sound );
186 NW_ASSERT( sound == m_pSound );
187 (void)sound;
188
189 m_pSound = NULL;
190 }
191
192
193 } // namespace nw::snd::internal
194 } // namespace nw::snd
195 } // namespace nw
196
197