-
Notifications
You must be signed in to change notification settings - Fork 13
/
graphics.c
906 lines (684 loc) · 22.7 KB
/
graphics.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
/*
* Copyright (C) 2010 drizzt
*
* Authors:
* drizzt <[email protected]>
* Jurai
* The original OpenBM author
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <sys/timer.h>
#include <cell/gcm.h>
#include <sysutil/sysutil_sysparam.h>
#include "i18n.h"
#include "graphics.h"
#include <cell/cell_fs.h>
#include <netex/libnetctl.h>
// JAPANESE PATCH
#include "fnt_print.h"
extern fnt_t font;
extern u8* fnt_buffer;
CellDbgFontConsoleId consoleID = CELL_DBGFONT_STDOUT_ID;
#define ROUNDUP(x, a) (((x)+((a)-1))&(~((a)-1)))
static u32 frame_index = 0;
typedef struct {
float x, y, z;
u32 color;
} vtx_color;
typedef struct {
float x, y, z;
float tx, ty;
} vtx_texture;
u32 screen_width;
u32 screen_height;
float screen_aspect;
u32 color_pitch;
u32 depth_pitch;
u32 color_offset[2];
u32 depth_offset;
uint32_t blockSize;
uint64_t freeSize;
float freeSpace;
extern u32 _binary_vpshader_vpo_start;
extern u32 _binary_vpshader_vpo_end;
extern u32 _binary_fpshader_fpo_start;
extern u32 _binary_fpshader_fpo_end;
static unsigned char *vertex_program_ptr = (unsigned char *) &_binary_vpshader_vpo_start;
static unsigned char *fragment_program_ptr = (unsigned char *) &_binary_fpshader_fpo_start;
static CGprogram vertex_program;
static CGprogram fragment_program;
extern struct _CGprogram _binary_vpshader2_vpo_start;
extern struct _CGprogram _binary_fpshader2_fpo_start;
static void *vertex_program_ucode;
static void *fragment_program_ucode;
static u32 fragment_offset;
static void *text_vertex_prg_ucode;
static void *text_fragment_prg_ucode;
static u32 text_fragment_offset;
static u32 vertex_offset[2];
static u32 color_index;
static u32 position_index;
static vtx_color *vertex_color;
static int vert_indx = 0;
static int vert_texture_indx = 0;
static u32 text_width;
static u32 text_height;
static u32 text_colorp;
static u32 text_depthp;
static vtx_texture *vertex_text;
static u32 vertex_text_offset;
static u32 text_obj_coord_indx;
static u32 text_tex_coord_indx;
static CGresource tindex;
static CGprogram vertex_prg;
static CGprogram fragment_prg;
static CellGcmTexture text_param;
static u32 local_heap = 0;
extern const char VERSION[];
static void *localAlloc(const u32 size)
{
u32 align = (size + 1023) & (~1023);
u32 base = local_heap;
local_heap += align;
return (void *) base;
}
static void *localAllocAlign(const u32 alignment, const u32 size)
{
local_heap = (local_heap + alignment - 1) & (~(alignment - 1));
return (void *) localAlloc(size);
}
void draw_square(float x, float y, float w, float h, float z, u32 color)
{
vertex_color[vert_indx].x = x;
vertex_color[vert_indx].y = y;
vertex_color[vert_indx].z = z;
vertex_color[vert_indx].color = color;
vertex_color[vert_indx + 1].x = x + w;
vertex_color[vert_indx + 1].y = y;
vertex_color[vert_indx + 1].z = z;
vertex_color[vert_indx + 1].color = color;
vertex_color[vert_indx + 2].x = x + w;
vertex_color[vert_indx + 2].y = y - h;
vertex_color[vert_indx + 2].z = z;
vertex_color[vert_indx + 2].color = color;
vertex_color[vert_indx + 3].x = x;
vertex_color[vert_indx + 3].y = y - h;
vertex_color[vert_indx + 3].z = z;
vertex_color[vert_indx + 3].color = color;
cellGcmSetDrawArrays(gCellGcmCurrentContext, CELL_GCM_PRIMITIVE_QUADS, vert_indx, 4);
vert_indx += 4;
}
void setRenderTarget(void)
{
CellGcmSurface surface;
surface.colorFormat = CELL_GCM_SURFACE_A8R8G8B8;
surface.colorTarget = CELL_GCM_SURFACE_TARGET_0;
surface.colorLocation[0] = CELL_GCM_LOCATION_LOCAL;
surface.colorOffset[0] = color_offset[frame_index];
surface.colorPitch[0] = color_pitch;
surface.colorLocation[1] = CELL_GCM_LOCATION_LOCAL;
surface.colorLocation[2] = CELL_GCM_LOCATION_LOCAL;
surface.colorLocation[3] = CELL_GCM_LOCATION_LOCAL;
surface.colorOffset[1] = 0;
surface.colorOffset[2] = 0;
surface.colorOffset[3] = 0;
surface.colorPitch[1] = 64;
surface.colorPitch[2] = 64;
surface.colorPitch[3] = 64;
surface.depthFormat = CELL_GCM_SURFACE_Z24S8;
surface.depthLocation = CELL_GCM_LOCATION_LOCAL;
surface.depthOffset = depth_offset;
surface.depthPitch = depth_pitch;
surface.type = CELL_GCM_SURFACE_PITCH;
surface.antialias = CELL_GCM_SURFACE_CENTER_1;
surface.width = screen_width;
surface.height = screen_height;
surface.x = 0;
surface.y = 0;
cellGcmSetSurface(gCellGcmCurrentContext, &surface);
}
static void waitFlip(void)
{
while (cellGcmGetFlipStatus() != 0)
sys_timer_usleep(500);
cellGcmResetFlipStatus();
}
void flip(void)
{
static int one = 1;
if (one != 1)
waitFlip();
else
cellGcmResetFlipStatus();
if (cellGcmSetFlip(gCellGcmCurrentContext, frame_index) != CELL_OK)
return;
one = 0;
cellGcmFlush(gCellGcmCurrentContext);
setDrawEnv();
setRenderColor();
cellGcmSetWaitFlip(gCellGcmCurrentContext);
frame_index = (frame_index + 1) & 1;
setRenderTarget();
vert_indx = 0; // reset the vertex index
vert_texture_indx = 0;
}
void initShader(void)
{
vertex_program = (CGprogram) vertex_program_ptr;
fragment_program = (CGprogram) fragment_program_ptr;
cellGcmCgInitProgram(vertex_program);
cellGcmCgInitProgram(fragment_program);
u32 ucode_size;
void *ucode;
cellGcmCgGetUCode(fragment_program, &ucode, &ucode_size);
void *ret = localAllocAlign(64, ucode_size);
fragment_program_ucode = ret;
memcpy(fragment_program_ucode, ucode, ucode_size);
cellGcmCgGetUCode(vertex_program, &ucode, &ucode_size);
vertex_program_ucode = ucode;
}
int text_create(u32 xsize, u32 ysize);
int initDisplay(void)
{
int ret, i;
u32 color_size, depth_size, color_depth = 4, z_depth = 4;
void *color_base_addr, *depth_base_addr, *color_addr[2];
CellVideoOutResolution resolution;
CellVideoOutState videoState;
cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &videoState);
ret = cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &videoState);
if (ret != CELL_OK)
return -1;
cellVideoOutGetResolution(videoState.displayMode.resolutionId, &resolution);
screen_width = resolution.width;
screen_height = resolution.height;
color_pitch = screen_width * color_depth;
depth_pitch = screen_width * z_depth;
color_size = color_pitch * screen_height;
depth_size = depth_pitch * screen_height;
switch (videoState.displayMode.aspect) {
case CELL_VIDEO_OUT_ASPECT_4_3:
screen_aspect = 4.0f / 3.0f;
break;
case CELL_VIDEO_OUT_ASPECT_16_9:
screen_aspect = 16.0f / 9.0f;
break;
default:
screen_aspect = 16.0f / 9.0f;
}
CellVideoOutConfiguration videocfg;
memset(&videocfg, 0, sizeof(CellVideoOutConfiguration));
videocfg.resolutionId = videoState.displayMode.resolutionId;
videocfg.format = CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_X8R8G8B8;
videocfg.pitch = color_pitch;
ret = cellVideoOutConfigure(CELL_VIDEO_OUT_PRIMARY, &videocfg, NULL, 0);
if (ret != CELL_OK)
return -1;
cellGcmSetFlipMode(CELL_GCM_DISPLAY_VSYNC);
CellGcmConfig config;
cellGcmGetConfiguration(&config);
local_heap = (u32) config.localAddress;
color_base_addr = localAllocAlign(16, 2 * color_size);
for (i = 0; i < 2; i++) {
color_addr[i] = (void *) ((u32) color_base_addr + (i * color_size));
ret = cellGcmAddressToOffset(color_addr[i], &color_offset[i]);
if (ret != CELL_OK)
return -1;
ret = cellGcmSetDisplayBuffer(i, color_offset[i], color_pitch, screen_width, screen_height);
if (ret != CELL_OK)
return -1;
}
depth_base_addr = localAllocAlign(16, depth_size);
ret = cellGcmAddressToOffset(depth_base_addr, &depth_offset);
if (ret != CELL_OK)
return -1;
text_create(1920, 1080);
return 0;
}
void setDrawEnv(void)
{
u16 x, y, w, h;
float min, max;
float scale[4], offset[4];
x = 0;
y = 0;
w = screen_width;
h = screen_height;
min = 0.0f;
max = 1.0f;
scale[0] = w * 0.5f;
scale[1] = h * -0.5f;
scale[2] = (max - min) * 0.5f;
scale[3] = 0.0f;
offset[0] = x + scale[0];
offset[1] = h - y + scale[1];
offset[2] = (max + min) * 0.5f;
offset[3] = 0.0f;
cellGcmSetColorMask(gCellGcmCurrentContext,
CELL_GCM_COLOR_MASK_B | CELL_GCM_COLOR_MASK_G | CELL_GCM_COLOR_MASK_R | CELL_GCM_COLOR_MASK_A);
cellGcmSetColorMaskMrt(gCellGcmCurrentContext, 0);
cellGcmSetViewport(gCellGcmCurrentContext, x, y, w, h, min, max, scale, offset);
cellGcmSetClearColor(gCellGcmCurrentContext, 0xff000000);
// cellGcmSetDepthTestEnable(gCellGcmCurrentContext, CELL_GCM_TRUE);
// cellGcmSetDepthFunc(gCellGcmCurrentContext, CELL_GCM_LESS);
cellGcmSetBlendFunc(gCellGcmCurrentContext, CELL_GCM_SRC_ALPHA, CELL_GCM_ONE_MINUS_SRC_ALPHA, CELL_GCM_SRC_ALPHA,
CELL_GCM_ONE_MINUS_SRC_ALPHA);
cellGcmSetBlendEquation(gCellGcmCurrentContext, CELL_GCM_FUNC_ADD, CELL_GCM_FUNC_ADD);
cellGcmSetBlendEnable(gCellGcmCurrentContext, CELL_GCM_TRUE);
}
void setRenderColor(void)
{
cellGcmSetVertexProgram(gCellGcmCurrentContext, vertex_program, vertex_program_ucode);
cellGcmSetVertexDataArray(gCellGcmCurrentContext, position_index, 0, sizeof(vtx_color), 3, CELL_GCM_VERTEX_F,
CELL_GCM_LOCATION_LOCAL, (u32) vertex_offset[0]);
cellGcmSetVertexDataArray(gCellGcmCurrentContext, color_index, 0, sizeof(vtx_color), 4, CELL_GCM_VERTEX_UB,
CELL_GCM_LOCATION_LOCAL, (u32) vertex_offset[1]);
cellGcmSetFragmentProgram(gCellGcmCurrentContext, fragment_program, fragment_offset);
}
int setRenderObject(void)
{
vertex_color = (vtx_color *) localAllocAlign(128 * 1024, 1024 * sizeof(vtx_color));
CGparameter position = cellGcmCgGetNamedParameter(vertex_program, "position");
CGparameter color = cellGcmCgGetNamedParameter(vertex_program, "color");
position_index = cellGcmCgGetParameterResource(vertex_program, position) - CG_ATTR0;
color_index = cellGcmCgGetParameterResource(vertex_program, color) - CG_ATTR0;
if (cellGcmAddressToOffset(fragment_program_ucode, &fragment_offset) != CELL_OK)
return -1;
if (cellGcmAddressToOffset(&vertex_color->x, &vertex_offset[0]) != CELL_OK)
return -1;
if (cellGcmAddressToOffset(&vertex_color->color, &vertex_offset[1])
!= CELL_OK)
return -1;
return 0;
}
int initFont()
{
CellDbgFontConfigGcm config;
int size =
6 * (CELL_DBGFONT_FRAGMENT_SIZE + CELL_DBGFONT_VERTEX_SIZE * CONSOLE_WIDTH * CONSOLE_HEIGHT +
CELL_DBGFONT_TEXTURE_SIZE);
int ret = 0;
void *localmem = localAllocAlign(128, size);
if (localmem == NULL)
return -1;
memset(&config, 0, sizeof(CellDbgFontConfigGcm));
config.localBufAddr = (sys_addr_t) localmem;
config.localBufSize = size;
config.mainBufAddr = NULL;
config.mainBufSize = 0;
config.option = CELL_DBGFONT_VERTEX_LOCAL;
config.option |= CELL_DBGFONT_TEXTURE_LOCAL;
config.option |= CELL_DBGFONT_SYNC_ON;
ret = cellDbgFontInitGcm(&config);
if (ret < 0)
return ret;
return 0;
}
int initConsole()
{
CellDbgFontConsoleConfig config;
config.posLeft = 0.086f;
config.posTop = 0.16f;
config.cnsWidth = CONSOLE_WIDTH;
config.cnsHeight = CONSOLE_HEIGHT;
config.scale = 0.72f;
config.color = 0xffA0A0A0;
consoleID = cellDbgFontConsoleOpen(&config);
if (consoleID < 0)
return -1;
return 0;
}
int termConsole(void)
{
int ret;
ret = cellDbgFontConsoleClose(consoleID);
if (ret)
return -1;
consoleID = CELL_DBGFONT_STDOUT_ID;
return ret;
}
int termFont()
{
int ret;
ret = cellDbgFontExitGcm();
if (ret)
return -1;
return ret;
}
int DPrintf(const char *string, ...)
{
int ret;
va_list argp;
va_start(argp, string);
ret = cellDbgFontConsoleVprintf(consoleID, string, argp);
va_end(argp);
return ret;
}
#if 0
static void utf8_to_ansi(char *utf8, char *ansi, int len)
{
u8 *ch = (u8 *) utf8;
u8 c;
while (*ch != 0 && len > 0) {
// 3, 4 bytes utf-8 code
if (((*ch & 0xF1) == 0xF0 || (*ch & 0xF0) == 0xe0)
&& (*(ch + 1) & 0xc0) == 0x80) {
*ansi++ = ' '; // ignore
len--;
ch += 2 + 1 * ((*ch & 0xF1) == 0xF0);
} else
// 2 bytes utf-8 code
if ((*ch & 0xE0) == 0xc0 && (*(ch + 1) & 0xc0) == 0x80) {
c = (((*ch & 3) << 6) | (*(ch + 1) & 63));
if (c >= 0xC0 && c <= 0xC5)
c = 'A';
else if (c == 0xc7)
c = 'C';
else if (c >= 0xc8 && c <= 0xcb)
c = 'E';
else if (c >= 0xcc && c <= 0xcf)
c = 'I';
else if (c == 0xd1)
c = 'N';
else if (c >= 0xd2 && c <= 0xd6)
c = 'O';
else if (c >= 0xd9 && c <= 0xdc)
c = 'U';
else if (c == 0xdd)
c = 'Y';
else if (c >= 0xe0 && c <= 0xe5)
c = 'a';
else if (c == 0xe7)
c = 'c';
else if (c >= 0xe8 && c <= 0xeb)
c = 'e';
else if (c >= 0xec && c <= 0xef)
c = 'i';
else if (c == 0xf1)
c = 'n';
else if (c >= 0xf2 && c <= 0xf6)
c = 'o';
else if (c >= 0xf9 && c <= 0xfc)
c = 'u';
else if (c == 0xfd || c == 0xff)
c = 'y';
else if (c > 127)
c = *(++ch + 1); //' ';
*ansi++ = c;
len--;
ch++;
} else {
if (*ch < 32)
*ch = 32;
*ansi++ = *ch;
len--;
}
ch++;
}
while (len > 0) {
*ansi++ = 0;
len--;
}
}
#endif
static void draw_text_stroke(float x, float y, float size, u32 color, const char *str)
{
cellDbgFontPrintf(x - .001f, y + .001f, size, 0xff000000, str);
cellDbgFontPrintf(x - .001f, y - .001f, size, 0xff000000, str);
cellDbgFontPrintf(x + .001f, y + .001f, size, 0xff000000, str);
cellDbgFontPrintf(x + .001f, y - .001f, size, 0xff000000, str);
cellDbgFontPrintf(x + .002f, y + .002f, size, 0xff000000, str);
cellDbgFontPrintf(x, y, size, color, str);
}
static void draw_text_bool(float x, float y, float size, bool on)
{
u32 color = on ? 0xff00ff00 : 0xff0000ff;
cellDbgFontPrintf(x, y, size, color, on ? "ON" : "OFF");
}
void draw_device_list(u32 flags, int hermes, int payload_type, int direct_boot
#ifdef WITH_CFW
__attribute__ ((unused))
#endif
, int ftp)
{
float y = 0.84f;
char str[256];
int n, ok = 0;
float len;
float x = 0.06;
char sizer[255];
char path[255];
union CellNetCtlInfo info;
char ipaddr[sizeof(info.ip_address)];
for (n = 0; n < 12; n++) {
ok = 0;
if ((flags >> n) & 1)
ok = 1;
if (ok) {
switch (n) {
case 0:
sprintf(str, "%s", "hdd0");
sprintf(path, "/dev_hdd0/");
break;
case 11:
sprintf(str, "%s", "bdvd");
sprintf(path, "/dev_bdvd/");
break;
default:
sprintf(str, "usb%i", n - 1);
sprintf(path, "/dev_usb00%d/", n - 1);
break;
}
len = (float) 0.017 *strlen(str);
cellFsGetFreeSize(path, &blockSize, &freeSize);
freeSpace = (((uint64_t) blockSize * freeSize));
freeSpace = freeSpace / 1073741824.00;
sprintf(sizer, "%.2fGB", freeSpace);
draw_text_stroke(x, y + 0.064, 1.0f, ((flags >> (n + 16)) & 1) ? 0xff00ffff : 0xffffffff, str);
x += len - 0.01;
draw_text_stroke(x, y + 0.064, 1.0f, ((flags >> (n + 16)) & 1) ? 0xff999999 : 0xff999999, sizer);
len = (float) 0.017 *strlen(sizer);
x += len;
}
}
if (cellNetCtlGetInfo(CELL_NET_CTL_INFO_IP_ADDRESS, &info) < 0) {
strcpy(ipaddr, "DISCONNECTED");
} else {
char *p = info.ip_address;
size_t iplen = sizeof(info.ip_address);
while (*p == ' ') {
p++;
iplen--;
}
memcpy(ipaddr, p, iplen);
}
cellDbgFontPrintf(0.775, 0.432, 0.8, 0xffffffff, text_launch[region]);
// on GAME mode
if (((flags >> 31) & 1) == 0) {
cellDbgFontPrintf(0.775, 0.472, 0.8, 0xffffffff, text_download[region]);
cellDbgFontPrintf(0.775, 0.515, 0.8, 0xffffffff, text_copy[region]);
cellDbgFontPrintf(0.775, 0.555, 0.8, 0xffffffff, text_delete[region]);
cellDbgFontPrintf(0.775, 0.595, 0.8, 0xffffffff, text_refresh[region]);
cellDbgFontPrintf(0.775, 0.635, 0.8, 0xffffffff, text_check[region]);
cellDbgFontPrintf(0.775, 0.68, 0.8, 0xffffffff,
#ifdef WITH_CFW
text_discless[region]);
if (payload_type == 1)
draw_text_bool(0.895, 0.68, 0.8, hermes);
else
cellDbgFontPrintf(0.895, 0.68, 0.8, 0xffff0000, "N/A");
#else
payload_type == 1 ? text_discless[region] : text_mempatch[region]);
draw_text_bool(0.895, 0.68, 0.8, hermes);
cellDbgFontPrintf(0.775, 0.72, 0.8, 0xffffffff, text_directboot[region]);
draw_text_bool(0.895, 0.72, 0.8, direct_boot);
#endif
} else {
cellDbgFontPrintf(0.775, 0.472, 0.8, 0xffffffff, text_delete[region]);
cellDbgFontPrintf(0.775, 0.515, 0.8, 0xffffffff, text_refresh[region]);
}
cellDbgFontPrintf(0.775, 0.76, 0.8, 0xffffffff, text_ftpserver[region]);
draw_text_bool(0.895, 0.76, 0.8, ftp);
cellDbgFontPrintf(0.775, 0.80, 0.8, 0xffffffff, text_ommode[region]);
cellDbgFontPrintf(0.86, 0.80, 0.8, 0xffffffff, (flags >> 31) & 1 ? text_homebrew[region] : text_game[region]);
cellDbgFontPrintf(0.775, 0.84, 0.8, 0xffffffff, "IP");
cellDbgFontPrintf(0.80, 0.84, 0.8, 0xff00ffff, ipaddr);
//draw_text_stroke(0.36, 0.095, 0.8, 0xffdddddd, VERSION);
}
void draw_list(t_menu_list * menu, int menu_size, int selected)
{
float y = 0.145f;
int i = 0, c = 0;
char str[256];
char ansi[256];
u32 color;
int flagb = selected & 0x10000;
selected &= 0xffff;
if (selected > 15)
i = selected - 15;
while (selected < menu_size && c < 16) {
int grey = 0;
if (i < menu_size) {
// JAPANESE PATCH
//utf8_to_ansi(menu[i].title, ansi, 65);
memcpy(ansi, menu[i].title, 65);
ansi[65] = 0;
//sprintf(str, "%i) %s", i+1, ansi);
sprintf(str, "%s", ansi);
grey = (menu[i].title[0] == '_');
} else {
sprintf(str, " ");
}
color = 0x606060ff;
if (i == selected)
color = (flagb && i == 0) ? 0x00e0f0ff : ((grey == 0) ? 0xffff00ff : 0x808000ff);
else
color = (flagb && i == 0) ? 0x007080ff : ((grey == 0) ? 0xffffffff : 0x606060ff);
// JAPANESE PATCH
//draw_text_stroke(0.06f, y, 1.05f, color, str);
fnt_print_vram(&font, (u32 *)fnt_buffer, DISPLAY_WIDTH, (int)(0.06f * 1920), (int)(y * 1080), str, color, 0x00000000, (int)1.05f, (int)1.05f);
y += 0.0455f;
i++;
c++;
}
}
static void init_text_shader(void)
{
void *ucode;
u32 ucode_size;
vertex_prg = &_binary_vpshader2_vpo_start;
fragment_prg = &_binary_fpshader2_fpo_start;
cellGcmCgInitProgram(vertex_prg);
cellGcmCgInitProgram(fragment_prg);
cellGcmCgGetUCode(fragment_prg, &ucode, &ucode_size);
text_fragment_prg_ucode = localAllocAlign(64, ucode_size);
cellGcmAddressToOffset(text_fragment_prg_ucode, &text_fragment_offset);
memcpy(text_fragment_prg_ucode, ucode, ucode_size);
cellGcmCgGetUCode(vertex_prg, &text_vertex_prg_ucode, &ucode_size);
}
int text_create(u32 xsize, u32 ysize)
{
u32 buffer_width;
text_width = xsize;
text_height = ysize;
buffer_width = ROUNDUP(text_width, 64);
text_colorp = cellGcmGetTiledPitchSize(buffer_width * 4);
if (text_colorp == 0)
return -1;
text_depthp = cellGcmGetTiledPitchSize(buffer_width * 4);
if (text_depthp == 0)
return -1;
init_text_shader();
vertex_text = (vtx_texture *) localAllocAlign(128 * 1024, 1024 * sizeof(vtx_texture));
cellGcmAddressToOffset((void *) vertex_text, &vertex_text_offset);
text_param.format = CELL_GCM_TEXTURE_A8R8G8B8;
text_param.format |= CELL_GCM_TEXTURE_LN;
text_param.remap =
CELL_GCM_TEXTURE_REMAP_REMAP << 14 | CELL_GCM_TEXTURE_REMAP_REMAP << 12 | CELL_GCM_TEXTURE_REMAP_REMAP << 10 |
CELL_GCM_TEXTURE_REMAP_REMAP << 8 | CELL_GCM_TEXTURE_REMAP_FROM_G << 6 | CELL_GCM_TEXTURE_REMAP_FROM_R << 4 |
CELL_GCM_TEXTURE_REMAP_FROM_A << 2 | CELL_GCM_TEXTURE_REMAP_FROM_B;
text_param.mipmap = 1;
text_param.cubemap = CELL_GCM_FALSE;
text_param.dimension = CELL_GCM_TEXTURE_DIMENSION_2;
CGparameter objCoord = cellGcmCgGetNamedParameter(vertex_prg, "a2v.objCoord");
if (objCoord == 0)
return -1;
CGparameter texCoord = cellGcmCgGetNamedParameter(vertex_prg, "a2v.texCoord");
if (texCoord == 0)
return -1;
CGparameter texture = cellGcmCgGetNamedParameter(fragment_prg, "texture");
if (texture == 0)
return -1;
text_obj_coord_indx = cellGcmCgGetParameterResource(vertex_prg, objCoord) - CG_ATTR0;
text_tex_coord_indx = cellGcmCgGetParameterResource(vertex_prg, texCoord) - CG_ATTR0;
tindex = (CGresource) (cellGcmCgGetParameterResource(fragment_prg, texture) - CG_TEXUNIT0);
return 0;
}
int set_texture(u8 * buffer, u32 x_size, u32 y_size)
{
int ret;
u32 buf_offs;
ret = cellGcmAddressToOffset(buffer, &buf_offs);
if (CELL_OK != ret)
return ret;
text_param.depth = 1;
text_param.width = x_size;
text_param.height = y_size;
text_param.pitch = x_size * 4;
text_param.offset = buf_offs;
text_param.location = CELL_GCM_LOCATION_MAIN;
cellGcmSetTexture(gCellGcmCurrentContext, tindex, &text_param);
cellGcmSetTextureControl(gCellGcmCurrentContext, tindex, 1, 0, 15, 1);
cellGcmSetTextureAddress(gCellGcmCurrentContext, tindex, CELL_GCM_TEXTURE_CLAMP_TO_EDGE,
CELL_GCM_TEXTURE_CLAMP_TO_EDGE, CELL_GCM_TEXTURE_CLAMP_TO_EDGE,
CELL_GCM_TEXTURE_UNSIGNED_REMAP_NORMAL, CELL_GCM_TEXTURE_ZFUNC_LESS, 0);
cellGcmSetTextureFilter(gCellGcmCurrentContext, tindex, 0, CELL_GCM_TEXTURE_NEAREST, CELL_GCM_TEXTURE_NEAREST,
CELL_GCM_TEXTURE_CONVOLUTION_QUINCUNX);
return ret;
}
void setRenderTexture(void)
{
cellGcmSetVertexProgram(gCellGcmCurrentContext, vertex_prg, text_vertex_prg_ucode);
cellGcmSetFragmentProgram(gCellGcmCurrentContext, fragment_prg, text_fragment_offset);
cellGcmSetInvalidateTextureCache(gCellGcmCurrentContext, CELL_GCM_INVALIDATE_TEXTURE);
cellGcmSetVertexDataArray(gCellGcmCurrentContext, text_obj_coord_indx, 0, sizeof(vtx_texture), 3, CELL_GCM_VERTEX_F,
CELL_GCM_LOCATION_LOCAL, vertex_text_offset);
cellGcmSetVertexDataArray(gCellGcmCurrentContext, text_tex_coord_indx, 0, sizeof(vtx_texture), 2, CELL_GCM_VERTEX_F,
CELL_GCM_LOCATION_LOCAL, (vertex_text_offset + sizeof(float) * 3));
return;
}
//
// fixed by w4r10ck
//
void display_png(int x, int y, int width, int height, int tx, int ty)
{
vertex_text[vert_texture_indx].x = ((float) ((x) * 2)) / ((float) 1920) - 1.0f;
vertex_text[vert_texture_indx].y = ((float) ((y) * -2)) / ((float) 1080) + 1.0f;
vertex_text[vert_texture_indx].z = 0.0f;
vertex_text[vert_texture_indx].tx = 0.0f;
vertex_text[vert_texture_indx].ty = 0.0f;
vertex_text[vert_texture_indx + 1].x = ((float) ((x + width) * 2)) / ((float) 1920) - 1.0f;
vertex_text[vert_texture_indx + 1].y = ((float) ((y) * -2)) / ((float) 1080) + 1.0f;
vertex_text[vert_texture_indx + 1].z = 0.0f;
vertex_text[vert_texture_indx + 1].tx = ((float) tx) / 1920.0f;
vertex_text[vert_texture_indx + 1].ty = 0.0f;
vertex_text[vert_texture_indx + 2].x = ((float) ((x) * 2)) / ((float) 1920) - 1.0f;
vertex_text[vert_texture_indx + 2].y = ((float) ((y + height) * -2)) / ((float) 1080) + 1.0f;
vertex_text[vert_texture_indx + 2].z = 0.0f;
vertex_text[vert_texture_indx + 2].tx = 0.0f;
vertex_text[vert_texture_indx + 2].ty = ((float) ty) / 1080.0f;
vertex_text[vert_texture_indx + 3].x = ((float) ((x + width) * 2)) / ((float) 1920) - 1.0f;
vertex_text[vert_texture_indx + 3].y = ((float) ((y + height) * -2)) / ((float) 1080) + 1.0f;
vertex_text[vert_texture_indx + 3].z = 0.0f;
vertex_text[vert_texture_indx + 3].tx = ((float) tx) / 1920.0f;
vertex_text[vert_texture_indx + 3].ty = ((float) ty) / 1080.0f;
cellGcmSetDrawArrays(gCellGcmCurrentContext, CELL_GCM_PRIMITIVE_TRIANGLE_STRIP, vert_texture_indx, 4);
vert_texture_indx += 4;
}
/* vim: set ts=4 sw=4 sts=4 tw=120 */