annotate src/video/ps3/SDL_ps3spe.c @ 3150:0cf7bff804ad gsoc2009_ps3

Code reviewed and added SPE API documentation.
author Martin Lowinski <martin@goldtopf.org>
date Sun, 19 Jul 2009 11:31:47 +0000
parents 0d8d1f870964
children cce01ba54174
rev   line source
3144
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
1 /*
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
4
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
9
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
13 Lesser General Public License for more details.
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
14
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
18
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
19 Sam Lantinga
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
20 slouken@libsdl.org
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
21 */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
22 #include "SDL_config.h"
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
23
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
24 #include "SDL_video.h"
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
25 #include "SDL_ps3spe_c.h"
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
26
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
27 #include "SDL_ps3video.h"
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
28 #include "SDL_ps3render_c.h"
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
29
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
30
3150
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
31 /* This SPE API basically provides 3 ways to run and control a program
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
32 * on the SPE:
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
33 * - Start and stop the program (keepalive=0).
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
34 * SPE_Start() will implicitly boot up the program, create a thread and run
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
35 * the context.
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
36 * SPE_Stop() will join the (terminated) thread (may block) and return.
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
37 * - Boot the program and run it (keepalive=0).
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
38 * SPE_Boot() will create a context and load the program and finally start
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
39 * the context with SPE_Start().
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
40 * SPE_Stop() will savely end the program.
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
41 * - Boot, Run and send messages to the program (keepalive=1).
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
42 * Start the program by using one of the methods described above. When
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
43 * received the READY-message the program is in its infinite loop waiting
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
44 * for new messages.
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
45 * Every time you run the program, send SPU_START and the address of the
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
46 * according struct using SPE_SendMsg().
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
47 * SPE_WaitForMsg() will than wait for SPU_FIN and is blocking.
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
48 * SPE_Shutdown() sends SPU_EXIT and finally stops the program.
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
49 *
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
50 * Therefor the SPE program
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
51 * - either runs once and returns
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
52 * - or runs in an infinite loop and is controlled by messages.
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
53 */
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
54
3144
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
55 /* Start the SPE thread */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
56 int SPE_Start(spu_data_t * spe_data)
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
57 {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
58 deprintf(2, "[PS3->SPU] Start SPE: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
59 if (!(spe_data->booted))
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
60 SPE_Boot(spe_data);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
61
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
62 /* To allow re-running of context, spe_ctx_entry has to be set before each call */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
63 spe_data->entry = SPE_DEFAULT_ENTRY;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
64 spe_data->error_code = 0;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
65
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
66 /* Create SPE thread and run */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
67 deprintf(2, "[PS3->SPU] Create Thread: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
68 if (pthread_create
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
69 (&spe_data->thread, NULL, (void *)&SPE_RunContext, (void *)spe_data)) {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
70 deprintf(2, "[PS3->SPU] Could not create pthread for spe: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
71 SDL_SetError("[PS3->SPU] Could not create pthread for spe");
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
72 return -1;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
73 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
74
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
75 if (spe_data->keepalive)
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
76 SPE_WaitForMsg(spe_data, SPU_READY);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
77 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
78
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
79 /* Stop the SPE thread */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
80 int SPE_Stop(spu_data_t * spe_data)
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
81 {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
82 deprintf(2, "[PS3->SPU] Stop SPE: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
83 /* Wait for SPE thread to complete */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
84 deprintf(2, "[PS3->SPU] Wait for SPE thread to complete: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
85 if (pthread_join(spe_data->thread, NULL)) {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
86 deprintf(2, "[PS3->SPU] Failed joining the thread: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
87 SDL_SetError("[PS3->SPU] Failed joining the thread");
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
88 return -1;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
89 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
90
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
91 return 0;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
92 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
93
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
94 /* Create SPE context and load program */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
95 int SPE_Boot(spu_data_t * spe_data)
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
96 {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
97 /* Create SPE context */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
98 deprintf(2, "[PS3->SPU] Create SPE Context: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
99 spe_data->ctx = spe_context_create(0, NULL);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
100 if (spe_data->ctx == NULL) {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
101 deprintf(2, "[PS3->SPU] Failed creating SPE context: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
102 SDL_SetError("[PS3->SPU] Failed creating SPE context");
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
103 return -1;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
104 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
105
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
106 /* Load SPE object into SPE local store */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
107 deprintf(2, "[PS3->SPU] Load Program into SPE: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
108 if (spe_program_load(spe_data->ctx, &spe_data->program)) {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
109 deprintf(2, "[PS3->SPU] Failed loading program into SPE context: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
110 SDL_SetError
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
111 ("[PS3->SPU] Failed loading program into SPE context");
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
112 return -1;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
113 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
114 spe_data->booted = 1;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
115 deprintf(2, "[PS3->SPU] SPE boot successful\n");
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
116
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
117 return 0;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
118 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
119
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
120 /* (Stop and) shutdown the SPE */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
121 int SPE_Shutdown(spu_data_t * spe_data)
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
122 {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
123 if (spe_data->keepalive && spe_data->booted) {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
124 SPE_SendMsg(spe_data, SPU_EXIT);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
125 SPE_Stop(spe_data);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
126 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
127
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
128 /* Destroy SPE context */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
129 deprintf(2, "[PS3->SPU] Destroy SPE context: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
130 if (spe_context_destroy(spe_data->ctx)) {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
131 deprintf(2, "[PS3->SPU] Failed destroying context: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
132 SDL_SetError("[PS3->SPU] Failed destroying context");
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
133 return -1;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
134 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
135 deprintf(2, "[PS3->SPU] SPE shutdown successful: %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
136 return 0;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
137 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
138
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
139 /* Send message to the SPE via mailboxe */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
140 int SPE_SendMsg(spu_data_t * spe_data, unsigned int msg)
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
141 {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
142 deprintf(2, "[PS3->SPU] Sending message %u to %s\n", msg, spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
143 /* Send one message, block until message was sent */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
144 unsigned int spe_in_mbox_msgs[1];
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
145 spe_in_mbox_msgs[0] = msg;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
146 int in_mbox_write = spe_in_mbox_write(spe_data->ctx, spe_in_mbox_msgs, 1, SPE_MBOX_ALL_BLOCKING);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
147
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
148 if (1 > in_mbox_write) {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
149 deprintf(2, "[PS3->SPU] No message could be written to %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
150 SDL_SetError("[PS3->SPU] No message could be written");
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
151 return -1;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
152 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
153 return 0;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
154 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
155
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
156
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
157 /* Read 1 message from SPE, block until at least 1 message was received */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
158 int SPE_WaitForMsg(spu_data_t * spe_data, unsigned int msg)
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
159 {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
160 deprintf(2, "[PS3->SPU] Waiting for message from %s\n", spe_data->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
161 unsigned int out_messages[1];
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
162 while (!spe_out_mbox_status(spe_data->ctx));
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
163 int mbox_read = spe_out_mbox_read(spe_data->ctx, out_messages, 1);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
164 deprintf(2, "[PS3->SPU] Got message from %s, message was %u\n", spe_data->program_name, out_messages[0]);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
165 if (out_messages[0] == msg)
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
166 return 0;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
167 else
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
168 return -1;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
169 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
170
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
171 /* Re-runnable invocation of the spe_context_run call */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
172 void SPE_RunContext(void *thread_argp)
3150
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
173 {
3144
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
174 /* argp is the pointer to argument to be passed to the SPE program */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
175 spu_data_t *args = (spu_data_t *) thread_argp;
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
176 deprintf(3, "[PS3->SPU] void* argp=0x%x\n", (unsigned int)args->argp);
3150
0cf7bff804ad Code reviewed and added SPE API documentation.
Martin Lowinski <martin@goldtopf.org>
parents: 3144
diff changeset
177
3144
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
178 /* Run it.. */
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
179 deprintf(2, "[PS3->SPU] Run SPE program: %s\n", args->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
180 if (spe_context_run
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
181 (args->ctx, &args->entry, 0, (void *)args->argp, NULL,
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
182 NULL) < 0) {
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
183 deprintf(2, "[PS3->SPU] Failed running SPE context: %s\n", args->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
184 SDL_SetError("[PS3->SPU] Failed running SPE context: %s", args->program_name);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
185 exit(1);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
186 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
187
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
188 pthread_exit(NULL);
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
189 }
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
190
0d8d1f870964 Moved SPE-functions to SDL_ps3spe.c.
Martin Lowinski <martin@goldtopf.org>
parents:
diff changeset
191 /* vi: set ts=4 sw=4 expandtab: */