PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
ahx_rpc.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
16#include <tamtypes.h>
17#include <kernel.h>
18#include <sifrpc.h>
19#include <stdarg.h>
20#include <string.h>
21#include <stdlib.h>
22#include <fcntl.h>
23#include <unistd.h>
24#include <stdio.h>
25#include "ahx_rpc.h"
26
27static unsigned sbuff[64] __attribute__((aligned (64)));
28static struct t_SifRpcClientData cd0;
30#define IOP_MEM 0xbc000000
31char* songbuffer_addr;
32int ahx_init_done = 0;
33
39void iop_readwrite(void *addr, void *buf, u32 size, u32 read)
40{
41 DI();
42 ee_kmode_enter();
43 if (read) memcpy(buf, (void *)((u8 *)addr + IOP_MEM), size); else memcpy((void *)((u8 *)addr + IOP_MEM), buf, size);
44 ee_kmode_exit();
45 EI();
46}
47
49{
50 // struct t_SifDmaTransfer sdt;
51
52 // if already init'd, exit
53 if (ahx_init_done) return 0;
54
55 // bind rpc
56 while(1){
57 int i;
58
59 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1; // bind error
60 if (cd0.server != 0) break;
61 i = 0x10000;
62 while(i--);
63 }
64
65 SifCallRpc(&cd0,AHX_INIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
66
67 songbuffer_addr = (char*)sbuff[1];
68
69 // set flag, init done
70 ahx_init_done = 1;
71 return 0;
72}
73
75{
76 while(1){
77 int i;
78
79 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
80 if (cd0.server != 0) break;
81 i = 0x10000;
82 while(i--);
83 }
84 SifCallRpc(&cd0,AHX_PLAY,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
85 return 0;
86}
87
89{
90 while(1){
91 int i;
92
93 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
94 if (cd0.server != 0) break;
95 i = 0x10000;
96 while(i--);
97 }
98 SifCallRpc(&cd0,AHX_PAUSE,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
99 return 0;
100}
101
102int AHX_SubSong(int songNo)
103{
104 while(1){
105 int i;
106
107 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
108 if (cd0.server != 0) break;
109 i = 0x10000;
110 while(i--);
111 }
112 sbuff[0] = (unsigned)songNo;
113 SifCallRpc(&cd0,AHX_PAUSE,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
114 return 0;
115}
116
117int AHX_SetVolume(int volumePercentage)
118{
119 while(1){
120 int i;
121
122 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
123 if (cd0.server != 0) break;
124 i = 0x10000;
125 while(i--);
126 }
127 sbuff[0] = (unsigned)volumePercentage;
128 SifCallRpc(&cd0,AHX_QUIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
129 return 0;
130}
131
132int AHX_SetBoost(int boostValue)
133{
134 while(1){
135 int i;
136
137 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
138 if (cd0.server != 0) break;
139 i = 0x10000;
140 while(i--);
141 }
142 sbuff[0] = (unsigned)boostValue;
143 SifCallRpc(&cd0,AHX_SETBOOST,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
144 return 0;
145}
146
148{
149 while(1){
150 int i;
151
152 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
153 if (cd0.server != 0) break;
154 i = 0x10000;
155 while(i--);
156 }
157 SifCallRpc(&cd0,AHX_OVERSAMPLING,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
158 return 0;
159}
160
162{
163 while(1){
164 int i;
165
166 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
167 if (cd0.server != 0) break;
168 i = 0x10000;
169 while(i--);
170 }
171 SifCallRpc(&cd0,AHX_QUIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
172 return 0;
173}
174
175int AHX_LoadSongBuffer(char* songdata, int songsize)
176{
177 // write song data to IOP song buffer
178 iop_readwrite(songbuffer_addr, songdata, songsize, 0);
179
180 while(1){
181 int i;
182
183 if (SifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1;
184 if (cd0.server != 0) break;
185 i = 0x10000;
186 while(i--);
187 }
188
189 // set oversample and boost
190 sbuff[0] = (unsigned)songsize;
191
192 // call rpc
193 SifCallRpc(&cd0,AHX_LOADSONG,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
194
195 // return number of sub-songs
196 return (int)sbuff[1];
197}
198
199int AHX_LoadSong(char* filename)
200{
201 int fd, fdSize;
202 char* buffer;
203
204 fd = open(filename, O_RDONLY);
205 if(fd < 0)
206 {
207 printf("ERROR LOADING SONG\n");
208 return -1;
209 }
210 fdSize = lseek(fd, 0, SEEK_END);
211 lseek(fd, 0, SEEK_SET);
212 buffer = malloc(fdSize);
213 if(!buffer)
214 {
215 printf("ERROR ALLOCATING SONG MEMORY SONG\n");
216 return -1;
217 }
218 read(fd, buffer, fdSize);
219 close(fd);
220 return AHX_LoadSongBuffer(buffer, fdSize);
221}
int AHX_SetBoost(int boostValue)
Definition ahx_rpc.c:132
#define IOP_MEM
Definition ahx_rpc.c:30
int AHX_LoadSongBuffer(char *songdata, int songsize)
Definition ahx_rpc.c:175
int AHX_Init()
Definition ahx_rpc.c:48
int AHX_Play()
Definition ahx_rpc.c:74
void iop_readwrite(void *addr, void *buf, u32 size, u32 read)
Definition ahx_rpc.c:39
int AHX_SetVolume(int volumePercentage)
Definition ahx_rpc.c:117
int AHX_SubSong(int songNo)
Definition ahx_rpc.c:102
int AHX_ToggleOversampling()
Definition ahx_rpc.c:147
int AHX_Quit()
Definition ahx_rpc.c:161
int AHX_Pause()
Definition ahx_rpc.c:88
int AHX_LoadSong(char *filename)
Definition ahx_rpc.c:199