Subversion Repositories Tewi

Rev

Rev 193 | Rev 200 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 193 Rev 197
Line 1... Line 1...
1
/* $Id: main.c 193 2024-09-29 05:55:18Z nishi $ */
1
/* $Id: main.c 197 2024-09-29 07:13:35Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "../config.h"
5
#include "../config.h"
6
 
6
 
Line 51... Line 51...
51
#include <rsx/rsx.h>
51
#include <rsx/rsx.h>
52
#include <sysutil/video.h>
52
#include <sysutil/video.h>
53
#include <malloc.h>
53
#include <malloc.h>
54
#include <sys/thread.h>
54
#include <sys/thread.h>
55
#include <stdarg.h>
55
#include <stdarg.h>
-
 
56
#include <png.h>
56
 
57
 
57
#define printf(...) tt_printf(__VA_ARGS__)
58
#define printf(...) tt_printf(__VA_ARGS__)
58
#define STDERR_LOG(...) tt_printf(__VA_ARGS__)
59
#define STDERR_LOG(...) tt_printf(__VA_ARGS__)
59
#else
60
#else
60
#define STDERR_LOG(...) fprintf(stderr, __VA_ARGS__)
61
#define STDERR_LOG(...) fprintf(stderr, __VA_ARGS__)
Line 327... Line 328...
327
				for(x = 0; x < tt_width; x++) {
328
				for(x = 0; x < tt_width; x++) {
328
					tvram[y * tt_width + x] = tvram[(y + 1) * tt_width + x];
329
					tvram[y * tt_width + x] = tvram[(y + 1) * tt_width + x];
329
				}
330
				}
330
			}
331
			}
331
			for(x = 0; x < tt_width; x++) {
332
			for(x = 0; x < tt_width; x++) {
332
				tvram[(tt_height - 1) * tt_width + x] = 0;
333
				tvram[(tt_height - 1) * tt_width + x] = 0x20;
333
			}
334
			}
334
		}
335
		}
335
	}
336
	}
336
}
337
}
337
 
338
 
338
void tt_putchar(struct rsx_buffer* buffer, int x, int y, uint8_t c) {
339
void tt_putchar(struct rsx_buffer* buffer, int x, int y, uint8_t c) {
339
	int i, j;
340
	int i, j;
-
 
341
	if(c == 0) return;
340
	if(c < 0x20) c = 0x20;
342
	if(c < 0x20) c = 0x20;
341
	if(c >= 0x7f) c = 0x20;
343
	if(c >= 0x7f) c = 0x20;
342
	for(i = 0; i < 7; i++) {
344
	for(i = 0; i < 8; i++) {
343
		uint8_t l = font[(c - 0x20) * 8 + i];
345
		uint8_t l = i == 7 ? 0 : font[(c - 0x20) * 8 + i];
344
		for(j = 0; j < 5; j++) {
346
		for(j = 0; j < 6; j++) {
345
			uint32_t c = 0;
347
			uint32_t col = 0;
346
			if(l & (1 << 7)) {
348
			if(l & (1 << 7)) {
347
				c = 0xffffff;
349
				col = 0xffffff;
348
			}
350
			}
349
			l = l << 1;
351
			l = l << 1;
350
			buffer->ptr[(y * 8 + i) * buffer->width + x * 6 + j] = c;
352
			buffer->ptr[(y * 8 + i) * buffer->width + x * 6 + j] = col;
351
		}
353
		}
352
	}
354
	}
353
}
355
}
354
 
356
 
355
void draw(struct rsx_buffer* buffer, int current) {
357
void draw(struct rsx_buffer* buffer, int current) {
Line 360... Line 362...
360
			tt_putchar(buffer, j, i, c);
362
			tt_putchar(buffer, j, i, c);
361
		}
363
		}
362
	}
364
	}
363
}
365
}
364
 
366
 
365
#define BUFFERS 2
367
#define BUFFERS 1
366
gcmContextData* ctx;
368
gcmContextData* ctx;
367
struct rsx_buffer buffers[BUFFERS];
369
struct rsx_buffer buffers[BUFFERS];
368
 
370
 
369
void text_thread(void* arg) {
371
void text_thread(void* arg) {
370
	int current = 0;
372
	int current = 0;
Line 411... Line 413...
411
	}
413
	}
412
	va_end(va);
414
	va_end(va);
413
	tt_putstr(log);
415
	tt_putstr(log);
414
}
416
}
415
 
417
 
-
 
418
void show_png(void) {
-
 
419
	FILE* f = fopen(PREFIX "/pbtewi.png", "rb");
-
 
420
	if(f == NULL) {
-
 
421
		f = fopen(PREFIX "/../ICON0.PNG", "rb");
-
 
422
	}
-
 
423
	if(f == NULL) return;
-
 
424
	png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
-
 
425
	png_infop info = png_create_info_struct(png);
-
 
426
	if(setjmp(png_jmpbuf(png))) {
-
 
427
		png_destroy_read_struct(&png, &info, NULL);
-
 
428
		fclose(f);
-
 
429
		return;
-
 
430
	}
-
 
431
 
-
 
432
	png_init_io(png, f);
-
 
433
	png_read_info(png, info);
-
 
434
 
-
 
435
	int width = png_get_image_width(png, info);
-
 
436
	int height = png_get_image_height(png, info);
-
 
437
	int depth = png_get_bit_depth(png, info);
-
 
438
	int type = png_get_color_type(png, info);
-
 
439
 
-
 
440
	if(depth == 16) png_set_strip_16(png);
-
 
441
	if(type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png);
-
 
442
	if(type == PNG_COLOR_TYPE_GRAY && depth < 8) png_set_expand_gray_1_2_4_to_8(png);
-
 
443
	if(png_get_valid(png, info, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png);
-
 
444
	if(type == PNG_COLOR_TYPE_RGB || type == PNG_COLOR_TYPE_GRAY || type == PNG_COLOR_TYPE_PALETTE) png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
-
 
445
	if(type == PNG_COLOR_TYPE_GRAY || type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb(png);
-
 
446
	png_read_update_info(png, info);
-
 
447
	png_bytep* rows = (png_bytep*)malloc(sizeof(*rows) * (height));
-
 
448
 
-
 
449
	int i;
-
 
450
 
-
 
451
	for(i = 0; i < height; i++) {
-
 
452
		rows[i] = (png_byte*)malloc(png_get_rowbytes(png, info));
-
 
453
	}
-
 
454
 
-
 
455
	png_read_image(png, rows);
-
 
456
 
-
 
457
	for(i = 0; i < height; i++) {
-
 
458
		int j;
-
 
459
		for(j = 0; j < width; j++) {
-
 
460
			png_bytep byte = &(rows[i][j * 4]);
-
 
461
			uint32_t col = (byte[0] << 16) | (byte[1] << 8) | (byte[2]);
-
 
462
			int k;
-
 
463
			for(k = 0; k < BUFFERS; k++) {
-
 
464
				buffers[k].ptr[buffers[k].width * i - width + j] = col;
-
 
465
			}
-
 
466
		}
-
 
467
	}
-
 
468
 
-
 
469
	png_destroy_read_struct(&png, &info, NULL);
-
 
470
	fclose(f);
-
 
471
 
-
 
472
	for(i = 0; i < height; i++) {
-
 
473
		free(rows[i]);
-
 
474
	}
-
 
475
	free(rows);
-
 
476
}
-
 
477
 
416
#endif
478
#endif
417
 
479
 
418
int main(int argc, char** argv) {
480
int main(int argc, char** argv) {
419
	logfile = stderr;
481
	logfile = stderr;
420
#ifdef SERVICE
482
#ifdef SERVICE
Line 558... Line 620...
558
	for(i = 0; i < BUFFERS; i++) make_buffer(&buffers[i], i);
620
	for(i = 0; i < BUFFERS; i++) make_buffer(&buffers[i], i);
559
	flip(ctx, BUFFERS - 1);
621
	flip(ctx, BUFFERS - 1);
560
	sys_ppu_thread_t id;
622
	sys_ppu_thread_t id;
561
	sysThreadCreate(&id, text_thread, NULL, 1500, 0x1000, THREAD_JOINABLE, "TextThread");
623
	sysThreadCreate(&id, text_thread, NULL, 1500, 0x1000, THREAD_JOINABLE, "TextThread");
562
	printf("PS3 Bootstrap, Tewi/%s\n", tw_get_version());
624
	printf("PS3 Bootstrap, Tewi/%s\n", tw_get_version());
-
 
625
	show_png();
563
	netInitialize();
626
	netInitialize();
564
#elif defined(__ps2sdk__)
627
#elif defined(__ps2sdk__)
565
	SifInitRpc(0);
628
	SifInitRpc(0);
566
	init_scr();
629
	init_scr();
567
	scr_printf("PS2 Bootstrap, Tewi/%s\n", tw_get_version());
630
	scr_printf("PS2 Bootstrap, Tewi/%s\n", tw_get_version());