PS2SDK
PS2 Homebrew Libraries
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 <iopcontrol.h>
26 #include "ahx_rpc.h"
27 
28 static unsigned sbuff[64] __attribute__((aligned (64)));
29 static struct t_SifRpcClientData cd0;
31 #define IOP_MEM 0xbc000000
32 char* songbuffer_addr;
33 
39 void 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 
48 static int AHX_BindRpc_Impl(void)
49 {
51  memset(&cd0, 0, sizeof(cd0));
52 
53  if (cd0.server) return 0;
54 
55  // bind rpc
56  while(1){
57  int i;
58 
59  if (sceSifBindRpc( &cd0, AHX_IRX, 0) < 0) return -1; // bind error
60  if (cd0.server != 0) break;
61  i = 0x10000;
62  while(i--);
63  }
64  return 0;
65 }
66 
67 #define AHX_BINDRPC() \
68  { \
69  int ret; \
70  ret = AHX_BindRpc_Impl(); \
71  if (ret) \
72  return ret; \
73  }
74 
75 int AHX_Init()
76 {
77  AHX_BINDRPC();
78 
79  sceSifCallRpc(&cd0,AHX_INIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
80 
81  songbuffer_addr = (char*)sbuff[1];
82 
83  return 0;
84 }
85 
86 int AHX_Play()
87 {
88  AHX_BINDRPC();
89 
90  sceSifCallRpc(&cd0,AHX_PLAY,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
91  return 0;
92 }
93 
94 int AHX_Pause()
95 {
96  AHX_BINDRPC();
97 
98  sceSifCallRpc(&cd0,AHX_PAUSE,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
99  return 0;
100 }
101 
102 int AHX_SubSong(int songNo)
103 {
104  AHX_BINDRPC();
105 
106  sbuff[0] = (unsigned)songNo;
107  sceSifCallRpc(&cd0,AHX_PAUSE,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
108  return 0;
109 }
110 
111 int AHX_SetVolume(int volumePercentage)
112 {
113  AHX_BINDRPC();
114 
115  sbuff[0] = (unsigned)volumePercentage;
116  sceSifCallRpc(&cd0,AHX_QUIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
117  return 0;
118 }
119 
120 int AHX_SetBoost(int boostValue)
121 {
122  AHX_BINDRPC();
123 
124  sbuff[0] = (unsigned)boostValue;
125  sceSifCallRpc(&cd0,AHX_SETBOOST,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
126  return 0;
127 }
128 
130 {
131  AHX_BINDRPC();
132 
133  sceSifCallRpc(&cd0,AHX_OVERSAMPLING,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
134  return 0;
135 }
136 
137 int AHX_Quit()
138 {
139  AHX_BINDRPC();
140 
141  sceSifCallRpc(&cd0,AHX_QUIT,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
142  return 0;
143 }
144 
145 int AHX_LoadSongBuffer(char* songdata, int songsize)
146 {
147  // write song data to IOP song buffer
148  iop_readwrite(songbuffer_addr, songdata, songsize, 0);
149 
150  AHX_BINDRPC();
151 
152  // set oversample and boost
153  sbuff[0] = (unsigned)songsize;
154 
155  // call rpc
156  sceSifCallRpc(&cd0,AHX_LOADSONG,0,(void*)(&sbuff[0]),64,(void*)(&sbuff[0]),64,NULL,NULL);
157 
158  // return number of sub-songs
159  return (int)sbuff[1];
160 }
161 
162 int AHX_LoadSong(char* filename)
163 {
164  int fd, fdSize;
165  char* buffer;
166 
167  fd = open(filename, O_RDONLY);
168  if(fd < 0)
169  {
170  printf("ERROR LOADING SONG\n");
171  return -1;
172  }
173  fdSize = lseek(fd, 0, SEEK_END);
174  lseek(fd, 0, SEEK_SET);
175  buffer = malloc(fdSize);
176  if(!buffer)
177  {
178  printf("ERROR ALLOCATING SONG MEMORY SONG\n");
179  return -1;
180  }
181  read(fd, buffer, fdSize);
182  close(fd);
183  return AHX_LoadSongBuffer(buffer, fdSize);
184 }
kernel.h
AHX_ToggleOversampling
int AHX_ToggleOversampling()
Definition: ahx_rpc.c:129
AHX_LoadSongBuffer
int AHX_LoadSongBuffer(char *songdata, int songsize)
Definition: ahx_rpc.c:145
iopcontrol.h
AHX_LoadSong
int AHX_LoadSong(char *filename)
Definition: ahx_rpc.c:162
AHX_SubSong
int AHX_SubSong(int songNo)
Definition: ahx_rpc.c:102
AHX_Quit
int AHX_Quit()
Definition: ahx_rpc.c:137
tamtypes.h
HasIopRebootedSinceLastCall
static int HasIopRebootedSinceLastCall(void)
Definition: iopcontrol.h:47
stdio.h
AHX_Init
int AHX_Init()
Definition: ahx_rpc.c:75
AHX_SetVolume
int AHX_SetVolume(int volumePercentage)
Definition: ahx_rpc.c:111
t_SifRpcClientData
Definition: sifrpc-common.h:134
AHX_Pause
int AHX_Pause()
Definition: ahx_rpc.c:94
__attribute__
Definition: gif_registers.h:38
AHX_SetBoost
int AHX_SetBoost(int boostValue)
Definition: ahx_rpc.c:120
AHX_Play
int AHX_Play()
Definition: ahx_rpc.c:86
stdlib.h
ahx_rpc.h
iop_readwrite
void iop_readwrite(void *addr, void *buf, u32 size, u32 read)
Definition: ahx_rpc.c:39
IOP_MEM
#define IOP_MEM
Definition: ahx_rpc.c:31