- Timestamp:
- Sep 29, 2024, 2:11:20 PM (7 weeks ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/log.c
r182 r191 16 16 #endif 17 17 18 #ifdef __PPU__ 19 extern void tt_printf(const char* tmpl, ...); 20 #endif 21 18 22 FILE* logfile; 19 23 … … 29 33 #ifdef _PSP 30 34 pspDebugScreenPrintf("[%s] %s\n", date, log); 35 #elif defined(__PPU__) 36 tt_printf("[%s] %s\n", date, log); 31 37 #else 32 38 fprintf(logfile, "[%s] %s\n", date, log); … … 79 85 #ifdef _PSP 80 86 pspDebugScreenPrintf("%s %s\n", namebuf, result); 87 #elif defined(__PPU__) 88 tt_printf("%s %s\n", namebuf, result); 81 89 #else 82 90 fprintf(logfile, "%s %s\n", namebuf, result); -
trunk/Platform/ps3.mk
r187 r191 7 7 CFLAGS = -g -DPREFIX=\"$(PREFIX)\" -I $(PWD)/Common -I /usr/local/ps3dev/ppu/include 8 8 LDFLAGS = -L /usr/local/ps3dev/ppu/lib 9 LIBS = -lnet -lsysmodule -lsysutil -lrt -llv2 9 LIBS = -lnet -lsysmodule -lsysutil -lrt -llv2 -lrsx -lgcm_sys 10 10 EXEC = .elf 11 11 LIB = .so -
trunk/Server/Makefile
r189 r191 6 6 .SUFFIXES: .c .o 7 7 8 OBJS = main.o version.o config.o server.o http.o module.o strptime.o $(EXTOBJS) $(PREOBJS)8 OBJS = main.o version.o config.o server.o http.o module.o strptime.o font.o $(EXTOBJS) $(PREOBJS) 9 9 10 10 all: tewi$(EXEC) $(TARGET) -
trunk/Server/main.c
r189 r191 47 47 #define printf(...) scr_printf(__VA_ARGS__) 48 48 #define STDERR_LOG(...) scr_printf(__VA_ARGS__) 49 #elif defined(__PPU__) 50 #include <rsx/gcm_sys.h> 51 #include <rsx/rsx.h> 52 #include <sysutil/video.h> 53 #include <malloc.h> 54 #include <sys/thread.h> 55 #include <stdarg.h> 56 57 #define printf(...) tt_printf(__VA_ARGS__) 58 #define STDERR_LOG(...) tt_printf(__VA_ARGS__) 49 59 #else 50 60 #define STDERR_LOG(...) fprintf(stderr, __VA_ARGS__) … … 114 124 return 0; 115 125 } 126 #endif 127 128 #ifdef __PPU__ 129 uint32_t depth_pitch; 130 uint32_t depth_offset; 131 uint32_t* depth_buffer; 132 133 #define CB_SIZE 0x100000 134 #define HOST_SIZE (32 * 1024 * 1024) 135 136 struct rsx_buffer { 137 int width, height, id; 138 uint32_t* ptr; 139 uint32_t offset; 140 }; 141 142 void wait_rsx(gcmContextData* ctx, uint32_t label) { 143 rsxSetWriteBackendLabel(ctx, GCM_INDEX_TYPE_32B, label); 144 145 rsxFlushBuffer(ctx); 146 147 while(*(uint32_t*)gcmGetLabelAddress(GCM_INDEX_TYPE_32B) != label) usleep(50); 148 149 label++; 150 } 151 152 void wait_rsx_until_idle(gcmContextData* ctx) { 153 uint32_t label = 1; 154 rsxSetWriteBackendLabel(ctx, GCM_INDEX_TYPE_32B, label); 155 rsxSetWaitLabel(ctx, GCM_INDEX_TYPE_32B, label); 156 label++; 157 wait_rsx(ctx, label); 158 } 159 160 void get_resolution(int* width, int* height) { 161 videoState state; 162 videoResolution res; 163 if(videoGetState(0, 0, &state) != 0) { 164 return; 165 } 166 167 if(state.state != 0) { 168 return; 169 } 170 171 if(videoGetResolution(state.displayMode.resolution, &res) != 0) { 172 return; 173 } 174 *width = res.width; 175 *height = res.height; 176 } 177 178 void make_buffer(struct rsx_buffer* buffer, int id) { 179 int w, h; 180 get_resolution(&w, &h); 181 182 buffer->ptr = (uint32_t*)rsxMemalign(64, 4 * w * h); 183 if(buffer->ptr == NULL) return; 184 185 if(rsxAddressToOffset(buffer->ptr, &buffer->offset) != 0) return; 186 187 if(gcmSetDisplayBuffer(id, buffer->offset, 4 * w, w, h) != 0) return; 188 buffer->width = w; 189 buffer->height = h; 190 buffer->id = id; 191 } 192 193 gcmContextData* init_screen(void) { 194 void* host = memalign(1024 * 1024, HOST_SIZE); 195 gcmContextData* ctx = NULL; 196 videoState state; 197 videoConfiguration vconfig; 198 videoResolution res; 199 rsxInit(&ctx, CB_SIZE, HOST_SIZE, host); 200 if(ctx == NULL) { 201 free(host); 202 return NULL; 203 } 204 205 if(videoGetState(0, 0, &state) != 0) { 206 rsxFinish(ctx, 0); 207 free(host); 208 return NULL; 209 } 210 211 if(state.state != 0) { 212 rsxFinish(ctx, 0); 213 free(host); 214 return NULL; 215 } 216 217 if(videoGetResolution(state.displayMode.resolution, &res) != 0) { 218 rsxFinish(ctx, 0); 219 free(host); 220 return NULL; 221 } 222 223 memset(&vconfig, 0, sizeof(vconfig)); 224 vconfig.resolution = state.displayMode.resolution; 225 vconfig.format = VIDEO_BUFFER_FORMAT_XRGB; 226 vconfig.pitch = res.width * 4; 227 vconfig.aspect = state.displayMode.aspect; 228 229 wait_rsx_until_idle(ctx); 230 231 if(videoConfigure(0, &vconfig, NULL, 0) != 0) { 232 rsxFinish(ctx, 0); 233 free(host); 234 return NULL; 235 } 236 237 if(videoGetState(0, 0, &state) != 0) { 238 rsxFinish(ctx, 0); 239 free(host); 240 return NULL; 241 } 242 gcmSetFlipMode(GCM_FLIP_VSYNC); 243 244 depth_pitch = res.width * 4; 245 depth_buffer = (uint32_t*)rsxMemalign(64, (res.height * depth_pitch) * 2); 246 rsxAddressToOffset(depth_buffer, &depth_offset); 247 248 gcmResetFlipStatus(); 249 250 return ctx; 251 } 252 253 void set_render_target(gcmContextData* context, struct rsx_buffer* buffer) { 254 gcmSurface sf; 255 256 sf.colorFormat = GCM_SURFACE_X8R8G8B8; 257 sf.colorTarget = GCM_SURFACE_TARGET_0; 258 sf.colorLocation[0] = GCM_LOCATION_RSX; 259 sf.colorOffset[0] = buffer->offset; 260 sf.colorPitch[0] = depth_pitch; 261 262 sf.colorLocation[1] = GCM_LOCATION_RSX; 263 sf.colorLocation[2] = GCM_LOCATION_RSX; 264 sf.colorLocation[3] = GCM_LOCATION_RSX; 265 sf.colorOffset[1] = 0; 266 sf.colorOffset[2] = 0; 267 sf.colorOffset[3] = 0; 268 sf.colorPitch[1] = 64; 269 sf.colorPitch[2] = 64; 270 sf.colorPitch[3] = 64; 271 272 sf.depthFormat = GCM_SURFACE_ZETA_Z16; 273 sf.depthLocation = GCM_LOCATION_RSX; 274 sf.depthOffset = depth_offset; 275 sf.depthPitch = depth_pitch; 276 277 sf.type = GCM_TEXTURE_LINEAR; 278 sf.antiAlias = GCM_SURFACE_CENTER_1; 279 280 sf.width = buffer->width; 281 sf.height = buffer->height; 282 sf.x = 0; 283 sf.y = 0; 284 285 rsxSetSurface(context, &sf); 286 } 287 288 void wait_flip(void) { 289 while(gcmGetFlipStatus() != 0) usleep(200); 290 gcmResetFlipStatus(); 291 } 292 293 void flip(gcmContextData* ctx, uint32_t buffer) { 294 if(gcmSetFlip(ctx, buffer) == 0) { 295 rsxFlushBuffer(ctx); 296 gcmSetWaitFlip(ctx); 297 } 298 } 299 300 uint8_t* tvram; 301 302 extern uint8_t font[]; 303 304 int tt_x = 0; 305 int tt_y = 0; 306 int tt_width; 307 int tt_height; 308 309 void tt_putstr(const char* str) { 310 int i; 311 for(i = 0; str[i] != 0; i++){ 312 tvram[tt_y * tt_width + tt_x] = str[i]; 313 if(str[i] == '\n'){ 314 tt_x = 0; 315 tt_y++; 316 }else{ 317 tt_x++; 318 if(tt_x == tt_width){ 319 tt_x = 0; 320 tt_y++; 321 } 322 } 323 if(tt_y == tt_height){ 324 tt_y--; 325 int x, y; 326 for(y = 0; y < tt_height - 1; y++){ 327 for(x = 0; x < tt_width; x++){ 328 tvram[y * tt_width + x] = tvram[(y + 1) * tt_width + x]; 329 } 330 } 331 for(x = 0; x < tt_width; x++){ 332 tvram[(tt_height - 1) * tt_width + x] = 0; 333 } 334 } 335 } 336 } 337 338 void tt_putchar(struct rsx_buffer* buffer, int x, int y, uint8_t c){ 339 int i, j; 340 if(c < 0x20) c = 0x20; 341 if(c >= 0x7f) c = 0x20; 342 for(i = 0; i < 7; i++){ 343 uint8_t l = font[(c - 0x20) * 8 + i]; 344 for(j = 0; j < 5; j++){ 345 uint32_t c = 0; 346 if(l & (1 << 7)){ 347 c = 0xffffff; 348 } 349 l = l << 1; 350 buffer->ptr[(y * 8 + i) * buffer->width + x * 6 + j] = c; 351 } 352 } 353 } 354 355 void draw(struct rsx_buffer* buffer, int current) { 356 int i, j, c; 357 for(i = 0; i < buffer->height / 8; i++) { 358 for(j = 0; j < buffer->width / 6; j++) { 359 uint8_t c = tvram[i * (buffer->width / 6) + j]; 360 tt_putchar(buffer, j, i, c); 361 } 362 } 363 } 364 365 #define BUFFERS 2 366 gcmContextData* ctx; 367 struct rsx_buffer buffers[BUFFERS]; 368 369 void text_thread(void* arg) { 370 int current = 0; 371 while(1) { 372 wait_flip(); 373 draw(&buffers[current], current); 374 flip(ctx, buffers[current].id); 375 current++; 376 if(current >= BUFFERS) current = 0; 377 } 378 } 379 380 void tt_printf(const char* tmpl, ...) { 381 va_list va; 382 va_start(va, tmpl); 383 int i; 384 char cbuf[2]; 385 cbuf[1] = 0; 386 char* log = cm_strdup(""); 387 for(i = 0; tmpl[i] != 0; i++) { 388 if(tmpl[i] == '%') { 389 i++; 390 if(tmpl[i] == 's'){ 391 char* tmp = log; 392 log = cm_strcat(tmp, va_arg(va, char*)); 393 free(tmp); 394 }else if(tmpl[i] == 'd'){ 395 char buf[513]; 396 sprintf(buf, "%d", va_arg(va, int)); 397 char* tmp = log; 398 log = cm_strcat(tmp, buf); 399 free(tmp); 400 }else if(tmpl[i] == '%'){ 401 char* tmp = log; 402 log = cm_strcat(tmp, "%"); 403 free(tmp); 404 } 405 } else { 406 cbuf[0] = tmpl[i]; 407 char* tmp = log; 408 log = cm_strcat(tmp, cbuf); 409 free(tmp); 410 } 411 } 412 va_end(va); 413 tt_putstr(log); 414 } 415 116 416 #endif 117 417 … … 249 549 printf("Connected, My IP is %s\n", info.ip); 250 550 #elif defined(__PPU__) 551 int i; 552 ctx = init_screen(); 553 int w, h; 554 get_resolution(&w, &h); 555 tt_width = w / 6; 556 tt_height = h / 8; 557 tvram = malloc((w / 6) * (h / 8)); 558 for(i = 0; i < BUFFERS; i++) make_buffer(&buffers[i], i); 559 flip(ctx, BUFFERS - 1); 560 sys_ppu_thread_t id; 561 sysThreadCreate(&id, text_thread, NULL, 1500, 0x1000, THREAD_JOINABLE, "TextThread"); 251 562 printf("PS3 Bootstrap, Tewi/%s\n", tw_get_version()); 252 563 netInitialize(); … … 265 576 sceKernelExitGame(); 266 577 #else 578 #ifdef __PPU__ 579 printf("Error code %d\n", st); 580 while(1) 581 ; 582 #endif 267 583 return st; 268 584 #endif
Note:
See TracChangeset
for help on using the changeset viewer.