forked from ps2homebrew/wLaunchELF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.c
1320 lines (1150 loc) · 47.5 KB
/
draw.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
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//--------------------------------------------------------------
//File name: draw.c
//--------------------------------------------------------------
#include "launchelf.h"
GSGLOBAL *gsGlobal;
GSTEXTURE TexSkin, TexPreview, TexPicture, TexThumb[MAX_ENTRY], TexIcon[2];
int testskin, testsetskin, testjpg, testthumb;
int SCREEN_WIDTH = 640;
int SCREEN_HEIGHT = 448;
int SCREEN_X = 632;
int SCREEN_Y = 50;
//dlanor: values shown above are defaults for NTSC mode
u64 BrightColor;
int updateScr_1; //dlanor: flags screen updates for drawScr()
int updateScr_2; //dlanor: used for anti-flicker delay in drawScr()
u64 updateScr_t = 0; //dlanor: exit time of last drawScr()
int Old_Interlace;
char LastMessage[MAX_TEXT_LINE + 2];
int Menu_start_x = SCREEN_MARGIN + LINE_THICKNESS + FONT_WIDTH;
int Menu_title_y = SCREEN_MARGIN;
int Menu_message_y = SCREEN_MARGIN + FONT_HEIGHT;
int Frame_start_y = SCREEN_MARGIN + 2 * FONT_HEIGHT + 2; //First line of menu frame
int Menu_start_y = SCREEN_MARGIN + 2 * FONT_HEIGHT + LINE_THICKNESS + 5;
//dlanor: Menu_start_y is the 1st pixel line that may be used for main content of a menu
//dlanor: values below are only calculated when a rez is activated
int Menu_end_y; //Normal menu display should not use pixels at this line or beyond
int Frame_end_y; //first line of frame bottom
int Menu_tooltip_y; //Menus may also use this row for tooltips
//The font file ELISA100.FNT is needed to display MC save titles in japanese
//and the arrays defined here are needed to find correct data in that file
const u16 font404[] = {
0xA2AF, 11,
0xA2C2, 8,
0xA2D1, 11,
0xA2EB, 7,
0xA2FA, 4,
0xA3A1, 15,
0xA3BA, 7,
0xA3DB, 6,
0xA3FB, 4,
0xA4F4, 11,
0xA5F7, 8,
0xA6B9, 8,
0xA6D9, 38,
0xA7C2, 15,
0xA7F2, 13,
0xA8C1, 720,
0xCFD4, 43,
0xF4A5, 1030,
0, 0};
// ASCII‚ÆSJIS‚Ì•ÏŠ·—p”z—ñ
const unsigned char sjis_lookup_81[256] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x10
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x20
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x30
' ', ',', '.', ',', '.', 0xFF, ':', ';', '?', '!', 0xFF, 0xFF, '´', '`', 0xFF, '^', // 0x40
0xFF, '_', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, '0', 0xFF, '-', '-', 0xFF, 0xFF, // 0x50
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, '\'', '\'', '"', '"', '(', ')', 0xFF, 0xFF, '[', ']', '{', // 0x60
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, '+', '-', 0xFF, '*', 0xFF, // 0x70
'/', '=', 0xFF, '<', '>', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, '°', 0xFF, 0xFF, '°', 0xFF, // 0x80
'$', 0xFF, 0xFF, '%', '#', '&', '*', '@', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x90
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xA0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xB0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, '&', '|', '!', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xC0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xD0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xE0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xF0
};
const unsigned char sjis_lookup_82[256] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x00
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x10
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x20
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x30
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, '0', // 0x40
'1', '2', '3', '4', '5', '6', '7', '8', '9', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x50
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 0x60
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x70
0xFF, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', // 0x80
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x90
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xA0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xB0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xC0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xD0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xE0
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xF0
};
//--------------------------------------------------------------
int *CreateCoeffInt(int nLen, int nNewLen, int bShrink)
{
int nSum = 0;
int nSum2 = 0;
int *pRes = (int *)malloc(2 * nLen * sizeof(int));
int *pCoeff = pRes;
int nNorm = (bShrink) ? (nNewLen << 12) / nLen : 0x1000;
int nDenom = (bShrink) ? nLen : nNewLen;
int i;
memset(pRes, 0, 2 * nLen * sizeof(int));
for (i = 0; i < nLen; i++, pCoeff += 2) {
nSum2 = nSum + nNewLen;
if (nSum2 > nLen) {
*pCoeff = ((nLen - nSum) << 12) / nDenom;
pCoeff[1] = ((nSum2 - nLen) << 12) / nDenom;
nSum2 -= nLen;
} else {
*pCoeff = nNorm;
if (nSum2 == nLen) {
pCoeff[1] = -1;
nSum2 = 0;
} /* end if */
} /* end else */
nSum = nSum2;
} /* end for */
return pRes;
} /* CreateCoeffInt */
//--------------------------------------------------------------
int ShrinkData(u8 *pInBuff, u16 wWidth, u16 wHeight, u8 *pOutBuff, u16 wNewWidth, u16 wNewHeight)
{
u8 *pLine = pInBuff, *pPix;
u8 *pOutLine = pOutBuff;
u32 dwInLn = (3 * wWidth + 3) & ~3;
u32 dwOutLn = (3 * wNewWidth + 3) & ~3;
int x, y, i, ii;
int bCrossRow, bCrossCol;
int *pRowCoeff = CreateCoeffInt(wWidth, wNewWidth, 1);
int *pColCoeff = CreateCoeffInt(wHeight, wNewHeight, 1);
int *pXCoeff, *pYCoeff = pColCoeff;
u32 dwBuffLn = 3 * wNewWidth * sizeof(u32);
u32 *pdwBuff = (u32 *)malloc(6 * wNewWidth * sizeof(u32));
u32 *pdwCurrLn = pdwBuff;
u32 *pdwNextLn = pdwBuff + 3 * wNewWidth;
u32 *pdwCurrPix;
u32 dwTmp, *pdwNextPix;
memset(pdwBuff, 0, 2 * dwBuffLn);
y = 0;
while (y < wNewHeight) {
pPix = pLine;
pLine += dwInLn;
pdwCurrPix = pdwCurrLn;
pdwNextPix = pdwNextLn;
x = 0;
pXCoeff = pRowCoeff;
bCrossRow = pYCoeff[1] > 0;
while (x < wNewWidth) {
dwTmp = *pXCoeff * *pYCoeff;
for (i = 0; i < 3; i++)
pdwCurrPix[i] += dwTmp * pPix[i];
bCrossCol = pXCoeff[1] > 0;
if (bCrossCol) {
dwTmp = pXCoeff[1] * *pYCoeff;
for (i = 0, ii = 3; i < 3; i++, ii++)
pdwCurrPix[ii] += dwTmp * pPix[i];
} /* end if */
if (bCrossRow) {
dwTmp = *pXCoeff * pYCoeff[1];
for (i = 0; i < 3; i++)
pdwNextPix[i] += dwTmp * pPix[i];
if (bCrossCol) {
dwTmp = pXCoeff[1] * pYCoeff[1];
for (i = 0, ii = 3; i < 3; i++, ii++)
pdwNextPix[ii] += dwTmp * pPix[i];
} /* end if */
} /* end if */
if (pXCoeff[1]) {
x++;
pdwCurrPix += 3;
pdwNextPix += 3;
} /* end if */
pXCoeff += 2;
pPix += 3;
} /* end while */
if (pYCoeff[1]) {
// set result line
pdwCurrPix = pdwCurrLn;
pPix = pOutLine;
for (i = 3 * wNewWidth; i > 0; i--, pdwCurrPix++, pPix++)
*pPix = ((u8 *)pdwCurrPix)[3];
// prepare line buffers
pdwCurrPix = pdwNextLn;
pdwNextLn = pdwCurrLn;
pdwCurrLn = pdwCurrPix;
memset(pdwNextLn, 0, dwBuffLn);
y++;
pOutLine += dwOutLn;
} /* end if */
pYCoeff += 2;
} /* end while */
free(pRowCoeff);
free(pColCoeff);
free(pdwBuff);
return 1;
} /* end ShrinkData */
//--------------------------------------------------------------
int EnlargeData(u8 *pInBuff, u16 wWidth, u16 wHeight, u8 *pOutBuff, u16 wNewWidth, u16 wNewHeight)
{
u8 *pLine = pInBuff,
*pPix = pLine,
*pPixOld,
*pUpPix,
*pUpPixOld;
u8 *pOutLine = pOutBuff, *pOutPix;
u32 dwInLn = (3 * wWidth + 3) & ~3;
u32 dwOutLn = (3 * wNewWidth + 3) & ~3;
int x, y, i;
int bCrossRow, bCrossCol;
int *pRowCoeff = CreateCoeffInt(wNewWidth, wWidth, 0);
int *pColCoeff = CreateCoeffInt(wNewHeight, wHeight, 0);
int *pXCoeff, *pYCoeff = pColCoeff;
u32 dwTmp, dwPtTmp[3];
y = 0;
while (y < wHeight) {
bCrossRow = pYCoeff[1] > 0;
x = 0;
pXCoeff = pRowCoeff;
pOutPix = pOutLine;
pOutLine += dwOutLn;
pUpPix = pLine;
if (pYCoeff[1]) {
y++;
pLine += dwInLn;
pPix = pLine;
} /* end if */
while (x < wWidth) {
bCrossCol = pXCoeff[1] > 0;
pUpPixOld = pUpPix;
pPixOld = pPix;
if (pXCoeff[1]) {
x++;
pUpPix += 3;
pPix += 3;
} /* end if */
dwTmp = *pXCoeff * *pYCoeff;
for (i = 0; i < 3; i++)
dwPtTmp[i] = dwTmp * pUpPixOld[i];
if (bCrossCol) {
dwTmp = pXCoeff[1] * *pYCoeff;
for (i = 0; i < 3; i++)
dwPtTmp[i] += dwTmp * pUpPix[i];
} /* end if */
if (bCrossRow) {
dwTmp = *pXCoeff * pYCoeff[1];
for (i = 0; i < 3; i++)
dwPtTmp[i] += dwTmp * pPixOld[i];
if (bCrossCol) {
dwTmp = pXCoeff[1] * pYCoeff[1];
for (i = 0; i < 3; i++)
dwPtTmp[i] += dwTmp * pPix[i];
} /* end if */
} /* end if */
for (i = 0; i < 3; i++, pOutPix++)
*pOutPix = ((u8 *)(dwPtTmp + i))[3];
pXCoeff += 2;
} /* end while */
pYCoeff += 2;
} /* end while */
free(pRowCoeff);
free(pColCoeff);
return 1;
} /* end EnlargeData */
//--------------------------------------------------------------
int ScaleBitmap(u8 *pInBuff, u16 wWidth, u16 wHeight, u8 **pOutBuff, u16 wNewWidth, u16 wNewHeight)
{
int lRet;
// check for valid size
if ((wWidth > wNewWidth && wHeight < wNewHeight) ||
(wHeight > wNewHeight && wWidth < wNewWidth))
return 0;
// allocate memory
*pOutBuff = (u8 *)memalign(128, ((3 * wNewWidth + 3) & ~3) * wNewHeight);
if (!*pOutBuff)
return 0;
if (wWidth >= wNewWidth && wHeight >= wNewHeight)
lRet = ShrinkData(pInBuff, wWidth, wHeight, *pOutBuff, wNewWidth, wNewHeight);
else
lRet = EnlargeData(pInBuff, wWidth, wHeight, *pOutBuff, wNewWidth, wNewHeight);
return lRet;
} /* end ScaleBitmap */
//--------------------------------------------------------------
void RotateBitmap(u8 *InBuff, u16 Width, u16 Height, u8 *OutBuff, int Way)
{
int i, j, k, l;
int Byte;
u8 pixels[Width][Height][3];
u8 newpixels[Height][Width][3];
Byte = 0;
for (i = 0; i < Height; i++) {
for (j = 0; j < Width; j++) {
pixels[j][i][0] = InBuff[Byte];
pixels[j][i][1] = InBuff[Byte + 1];
pixels[j][i][2] = InBuff[Byte + 2];
Byte += 3;
}
}
if (Way == 1) { // +90°
for (i = 0, l = 0; i < Width; i++, l++) {
for (j = 0, k = Height - 1; j < Height; j++, k--) {
newpixels[j][i][0] = pixels[l][k][0];
newpixels[j][i][1] = pixels[l][k][1];
newpixels[j][i][2] = pixels[l][k][2];
}
}
} else if (Way == 3) { // -90°
for (i = 0, l = Width - 1; i < Width; i++, l--) {
for (j = 0, k = 0; j < Height; j++, k++) {
newpixels[j][i][0] = pixels[l][k][0];
newpixels[j][i][1] = pixels[l][k][1];
newpixels[j][i][2] = pixels[l][k][2];
}
}
} /* end if */
Byte = 0;
for (i = 0; i < Width; i++) {
for (j = 0; j < Height; j++) {
OutBuff[Byte] = newpixels[j][i][0];
OutBuff[Byte + 1] = newpixels[j][i][1];
OutBuff[Byte + 2] = newpixels[j][i][2];
Byte += 3;
}
}
free(pixels);
free(newpixels);
} /* end RotateBitmap */
//--------------------------------------------------------------
void setScrTmp(const char *msg0, const char *msg1)
{
int x, y;
char temp_txt[64];
x = SCREEN_MARGIN;
y = Menu_title_y;
printXY(setting->Menu_Title, x, y, setting->color[3], TRUE, 0);
sprintf(temp_txt, " ÿ4 LaunchELF %s ÿ4", ULE_VERSION);
printXY(temp_txt, SCREEN_WIDTH - SCREEN_MARGIN - FONT_WIDTH * strlen(temp_txt), y,
setting->color[1], TRUE, 0);
strncpy(LastMessage, msg0, MAX_TEXT_LINE);
LastMessage[MAX_TEXT_LINE] = '\0';
printXY(msg0, x, Menu_message_y, setting->color[2], TRUE, 0);
if (setting->Menu_Frame)
drawFrame(SCREEN_MARGIN, Frame_start_y,
SCREEN_WIDTH - SCREEN_MARGIN, Frame_end_y, setting->color[1]);
printXY(msg1, x, Menu_tooltip_y, setting->color[2], TRUE, 0);
}
//--------------------------------------------------------------
void drawSprite(u64 color, int x1, int y1, int x2, int y2)
{
int y_off = (setting->interlace) ? 0 : (y1 & 1);
y1 -= y_off;
y2 -= y_off;
if (testskin == 1) {
setBrightness(setting->Brightness);
gsKit_prim_sprite_texture(gsGlobal, &TexSkin, x1, y1, x1, y1, x2, y2, x2, y2, 0, BrightColor);
setBrightness(50);
} else {
gsKit_prim_sprite(gsGlobal, x1, y1, x2, y2, 0, color);
}
}
//--------------------------------------------------------------
void drawPopSprite(u64 color, int x1, int y1, int x2, int y2)
{
int y_off = (setting->interlace) ? 0 : (y1 & 1);
y1 -= y_off;
y2 -= y_off;
if (testskin == 1 && !setting->Popup_Opaque) {
setBrightness(setting->Brightness);
gsKit_prim_sprite_texture(gsGlobal, &TexSkin, x1, y1, x1, y1, x2, y2, x2, y2, 0, BrightColor);
setBrightness(50);
} else {
gsKit_prim_sprite(gsGlobal, x1, y1, x2, y2, 0, color);
}
}
//--------------------------------------------------------------
//drawOpSprite exists only to eliminate the use of primitive sprite functions
//that are specific to the graphics lib used (currently gsKit). So normally
//it will merely be a 'wrapper' function for one of the lib calls, except
//that it will also perform any coordinate adjustments (if any)implemented for
//the functions drawSprite and drawPopSprite, to keep all of them compatible.
//
void drawOpSprite(u64 color, int x1, int y1, int x2, int y2)
{
int y_off = (setting->interlace) ? 0 : (y1 & 1);
y1 -= y_off;
y2 -= y_off;
gsKit_prim_sprite(gsGlobal, x1, y1, x2, y2, 0, color);
}
//--------------------------------------------------------------
void drawMsg(const char *msg)
{
strncpy(LastMessage, msg, MAX_TEXT_LINE);
LastMessage[MAX_TEXT_LINE] = '\0';
drawSprite(setting->color[0], 0, Menu_message_y - 1,
SCREEN_WIDTH, Frame_start_y);
printXY(msg, SCREEN_MARGIN, Menu_message_y, setting->color[2], TRUE, 0);
drawScr();
}
//--------------------------------------------------------------
void drawLastMsg(void)
{
drawSprite(setting->color[0], 0, Menu_message_y - 1,
SCREEN_WIDTH, Frame_start_y);
printXY(LastMessage, SCREEN_MARGIN, Menu_message_y, setting->color[2], TRUE, 0);
drawScr();
}
//--------------------------------------------------------------
void setupGS(int gs_vmode)
{
// GS Init
gsGlobal = gsKit_init_global_custom(
GS_RENDER_QUEUE_OS_POOLSIZE + GS_RENDER_QUEUE_OS_POOLSIZE / 2, //eliminates overflow
GS_RENDER_QUEUE_PER_POOLSIZE);
// GS video mode
gsGlobal->Mode = gs_vmode;
// Screen size and Interlace Init
gsGlobal->Width = SCREEN_WIDTH;
if (setting->interlace) {
gsGlobal->Height = SCREEN_HEIGHT;
gsGlobal->Interlace = GS_INTERLACED;
gsGlobal->Field = GS_FIELD;
gsGlobal->MagV = 0;
} else {
gsGlobal->Height = SCREEN_HEIGHT / 2;
gsGlobal->Interlace = GS_NONINTERLACED;
gsGlobal->Field = GS_FRAME;
gsGlobal->MagV = 0;
}
Old_Interlace = setting->interlace;
// Clear Screen
gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x00, 0x00, 0x00, 0x00, 0x00));
// Screen Position Init
gsGlobal->StartX = setting->screen_x;
gsGlobal->StartY = setting->screen_y;
// Buffer Init
gsGlobal->PrimAAEnable = GS_SETTING_ON;
gsGlobal->DoubleBuffering = GS_SETTING_OFF;
gsGlobal->ZBuffering = GS_SETTING_OFF;
// DMAC Init
dmaKit_init(D_CTRL_RELE_OFF, D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC, D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
dmaKit_chan_init(DMA_CHANNEL_GIF);
dmaKit_chan_init(DMA_CHANNEL_FROMSPR);
dmaKit_chan_init(DMA_CHANNEL_TOSPR);
// Screen Init
gsKit_init_screen(gsGlobal);
gsKit_mode_switch(gsGlobal, GS_ONESHOT);
gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x00, 0x00, 0x00, 0x00, 0x00));
}
//--------------------------------------------------------------
void updateScreenMode(int adapt_XY)
{
int setGS_flag = 0;
int New_TV_mode = setting->TV_mode;
if ((New_TV_mode != TV_mode_NTSC) && (New_TV_mode != TV_mode_PAL) && (New_TV_mode != TV_mode_VGA)) { //If no forced request
New_TV_mode = uLE_detect_TV_mode(); //Let console region decide TV_mode
}
if (New_TV_mode != TV_mode) {
setGS_flag = 1;
TV_mode = New_TV_mode;
if (TV_mode == TV_mode_NTSC) { //else use NTSC mode (forced or auto)
gsGlobal->Mode = GS_MODE_NTSC;
SCREEN_WIDTH = 640;
SCREEN_HEIGHT = 448;
if (adapt_XY) {
setting->screen_x += 362;
if (setting->interlace)
setting->screen_y += 0;
else
setting->screen_y -= 24;
}
Menu_end_y = Menu_start_y + 22 * FONT_HEIGHT;
} else if (TV_mode == TV_mode_PAL) { //Use PAL mode if chosen (forced or auto)
gsGlobal->Mode = GS_MODE_PAL;
SCREEN_WIDTH = 640;
SCREEN_HEIGHT = 512;
if (adapt_XY) {
setting->screen_x += 20;
if (setting->interlace)
setting->screen_y += 22;
else
setting->screen_y += 11;
}
Menu_end_y = Menu_start_y + 26 * FONT_HEIGHT;
} else { //Use VGA mode if chosen (forced)
gsGlobal->Mode = GS_MODE_VGA_640_60;
SCREEN_WIDTH = 640;
SCREEN_HEIGHT = 448;
if (adapt_XY) {
setting->screen_x -= 382;
if (setting->interlace)
setting->screen_y -= 22;
else
setting->screen_y += 13;
}
Menu_end_y = Menu_start_y + 22 * FONT_HEIGHT;
} /* end else */
Frame_end_y = Menu_end_y + 3;
Menu_tooltip_y = Frame_end_y + LINE_THICKNESS + 2;
} // end TV_Mode change
if (setting->interlace != Old_Interlace) {
setGS_flag = 1;
Old_Interlace = setting->interlace;
// Interlace Init
if (setting->interlace) {
gsGlobal->Interlace = GS_INTERLACED;
gsGlobal->Field = GS_FIELD;
if ((adapt_XY) && (TV_mode != TV_mode_VGA)) {
setting->screen_y = (setting->screen_y - 1) * 2;
}
} else {
gsGlobal->Interlace = GS_NONINTERLACED;
gsGlobal->Field = GS_FRAME;
if ((adapt_XY) && (TV_mode != TV_mode_VGA)) {
setting->screen_y = setting->screen_y / 2 + 1;
}
}
} // end Interlace change
// Init screen size
gsGlobal->Width = SCREEN_WIDTH;
gsGlobal->MagH = (TV_mode == TV_mode_VGA) ? 1 : 3;
if (setting->interlace) {
gsGlobal->Height = SCREEN_HEIGHT;
gsGlobal->MagV = 0;
} else {
gsGlobal->Height = SCREEN_HEIGHT / ((TV_mode == TV_mode_VGA) ? 1 : 2);
gsGlobal->MagV = 0;
}
// Init screen position
gsGlobal->StartX = setting->screen_x;
gsGlobal->StartY = setting->screen_y;
if (setGS_flag) {
// Clear screen before setting GS
gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x00, 0x00, 0x00, 0x00, 0x00));
// Init screen modes
SetGsCrt(gsGlobal->Interlace, gsGlobal->Mode, gsGlobal->Field);
}
GS_SET_DISPLAY1(gsGlobal->StartX, // X position in the display area (in VCK unit
gsGlobal->StartY, // Y position in the display area (in Raster u
gsGlobal->MagH, // Horizontal Magnification
gsGlobal->MagV, // Vertical Magnification
(gsGlobal->Width * 4) - 1, // Display area width
(gsGlobal->Height - 1)); // Display area height
GS_SET_DISPLAY2(gsGlobal->StartX, // X position in the display area (in VCK units)
gsGlobal->StartY, // Y position in the display area (in Raster units)
gsGlobal->MagH, // Horizontal Magnification
gsGlobal->MagV, // Vertical Magnification
(gsGlobal->Width * 4) - 1, // Display area width
(gsGlobal->Height - 1)); // Display area height
}
//--------------------------------------------------------------
void loadSkin(int Picture, char *Path, int ThumbNum)
{
char tmpPath[MAX_PATH], skinpath[MAX_PATH];
strcpy(tmpPath, "\0");
if (Picture == BACKGROUND_PIC) {
if (GUI_active == 1) {
strcpy(tmpPath, setting->GUI_skin);
} else {
strcpy(tmpPath, setting->skin);
}
testskin = 0;
} else if (Picture == PREVIEW_PIC) {
strcpy(tmpPath, setting->skin);
testsetskin = 0;
} else if (Picture == JPG_PIC) {
strcpy(tmpPath, Path);
testjpg = 0;
} else if (Picture == THUMB_PIC) {
strcpy(tmpPath, Path);
testthumb = 0;
} else if (Picture == PREVIEW_GUI) {
strcpy(tmpPath, setting->GUI_skin);
testsetskin = 0;
}
genFixPath(tmpPath, skinpath);
FILE *File = fopen(skinpath, "r");
PicW = 0, PicH = 0, PicCoeff = 0;
if (File != NULL) {
jpgData *Jpg;
u8 *ImgData, *ImgData1, *ImgData2;
int W = 0;
if ((Jpg = jpgOpenFILE(File, JPG_WIDTH_FIX)) > 0) {
if ((ImgData = malloc(Jpg->width * Jpg->height * (Jpg->bpp / 8))) > 0) {
if ((jpgReadImage(Jpg, ImgData)) != -1) {
if (Picture == BACKGROUND_PIC) {
if ((ScaleBitmap(ImgData, Jpg->width, Jpg->height, (void *)&TexSkin.Mem, SCREEN_WIDTH, SCREEN_HEIGHT)) != 0) {
TexSkin.PSM = GS_PSM_CT24;
TexSkin.VramClut = 0;
TexSkin.Clut = NULL;
TexSkin.Width = SCREEN_WIDTH;
TexSkin.Height = SCREEN_HEIGHT;
TexSkin.Filter = GS_FILTER_NEAREST;
gsGlobal->CurrentPointer = 0x140000;
TexSkin.Vram = gsKit_vram_alloc(gsGlobal,
gsKit_texture_size(TexSkin.Width, TexSkin.Height, TexSkin.PSM),
GSKIT_ALLOC_USERBUFFER);
gsKit_texture_upload(gsGlobal, &TexSkin);
free(TexSkin.Mem);
testskin = 1;
} /* end if */
} else if ((Picture == PREVIEW_PIC) || (Picture == PREVIEW_GUI)) {
if ((ScaleBitmap(ImgData, Jpg->width, Jpg->height, (void *)&TexPreview.Mem, SCREEN_WIDTH, SCREEN_HEIGHT)) != 0) {
TexPreview.PSM = GS_PSM_CT24;
TexPreview.VramClut = 0;
TexPreview.Clut = NULL;
TexPreview.Width = SCREEN_WIDTH;
TexPreview.Height = SCREEN_HEIGHT;
TexPreview.Filter = GS_FILTER_NEAREST;
gsGlobal->CurrentPointer = 0x280000;
TexPreview.Vram = gsKit_vram_alloc(gsGlobal,
gsKit_texture_size(TexPreview.Width, TexPreview.Height, TexPreview.PSM),
GSKIT_ALLOC_USERBUFFER);
gsKit_texture_upload(gsGlobal, &TexPreview);
free(TexPreview.Mem);
testsetskin = 1;
} /* end if */
} else if (Picture == JPG_PIC) {
PicW = Jpg->width;
PicH = Jpg->height;
if ((TV_mode == TV_mode_NTSC) || (TV_mode == TV_mode_VGA))
PicCoeff = (PicW / PicH) + (1.0f / 10.5f);
else if (TV_mode == TV_mode_PAL)
PicCoeff = (PicW / PicH) - (1.0f / 12.0f);
if (FullScreen) {
if (Jpg->width > Jpg->height) {
PicWidth = 928;
PicHeight = 696;
} else {
PicHeight = 928;
PicWidth = 696;
}
} else {
if (Jpg->width > Jpg->height) {
PicWidth = 640;
PicHeight = 512;
} else {
PicHeight = 640;
PicWidth = 512;
}
}
if ((ScaleBitmap(ImgData, Jpg->width, Jpg->height, &ImgData1, (int)PicWidth, Jpg->height)) != 0) {
if ((ScaleBitmap(ImgData1, (int)PicWidth, Jpg->height, &ImgData2, (int)PicWidth, (int)PicHeight)) != 0) {
if ((PicRotate == 1) || (PicRotate == 3)) { // Rotate picture
(void *)TexPicture.Mem = malloc(((int)PicWidth * (int)PicHeight * 3) + 1);
RotateBitmap(ImgData2, (int)PicWidth, (int)PicHeight, (void *)TexPicture.Mem, PicRotate);
W = PicW;
PicW = PicH;
PicH = W;
if ((TV_mode == TV_mode_NTSC) || (TV_mode == TV_mode_VGA))
PicCoeff = (PicW / PicH) + (1.0f / 10.5f);
else if (TV_mode == TV_mode_PAL)
PicCoeff = (PicW / PicH) - (1.0f / 12.0f);
W = PicWidth;
PicWidth = PicHeight;
PicHeight = W;
} else {
memcpy((void *)&TexPicture.Mem, &ImgData2, sizeof(ImgData2));
}
TexPicture.PSM = GS_PSM_CT24;
TexPicture.VramClut = 0;
TexPicture.Clut = NULL;
TexPicture.Filter = GS_FILTER_NEAREST;
TexPicture.Width = PicWidth;
TexPicture.Height = PicHeight;
if (FullScreen)
gsGlobal->CurrentPointer = 0x140000;
else
gsGlobal->CurrentPointer = 0x288000;
TexPicture.Vram = gsKit_vram_alloc(gsGlobal,
gsKit_texture_size(TexPicture.Width, TexPicture.Height, TexPicture.PSM),
GSKIT_ALLOC_USERBUFFER);
gsKit_texture_upload(gsGlobal, &TexPicture);
free(TexPicture.Mem);
testjpg = 1;
} /* end if */
} /* end if */
} else if (Picture == THUMB_PIC) {
if ((ScaleBitmap(ImgData, Jpg->width, Jpg->height, (void *)&TexThumb[ThumbNum].Mem, 64, 32)) != 0) {
TexThumb[ThumbNum].PSM = GS_PSM_CT24;
TexThumb[ThumbNum].VramClut = 0;
TexThumb[ThumbNum].Clut = NULL;
TexThumb[ThumbNum].Width = 64;
TexThumb[ThumbNum].Height = 32;
TexThumb[ThumbNum].Filter = GS_FILTER_NEAREST;
TexThumb[ThumbNum].Vram = gsKit_vram_alloc(gsGlobal,
gsKit_texture_size(TexThumb[ThumbNum].Width,
TexThumb[ThumbNum].Height, TexThumb[ThumbNum].PSM),
GSKIT_ALLOC_USERBUFFER);
gsKit_texture_upload(gsGlobal, &TexThumb[ThumbNum]);
free(TexThumb[ThumbNum].Mem);
testthumb = 1;
} /* end if */
} /* end else */
jpgClose(Jpg); //This really should be moved, but jpg funcs may object
} /* end if((jpgReadImage(...)) != -1) */
free(ImgData);
free(ImgData1);
free(ImgData2);
} /* end if( (ImgData = malloc(...)) > 0 ) */
} /* end if( (Jpg=jpgOpenRAW(...)) > 0 ) */
fclose(File);
} /* end if( File != NULL ) */
if (!strncmp(tmpPath, "cdfs", 4)) {
CDVD_Stop();
sceCdSync(0);
}
if (!strncmp(tmpPath, "hdd0:/", 6))
unmountParty(0);
}
//--------------------------------------------------------------
void loadIcon(void)
{
TexIcon[0].Width = 16;
TexIcon[0].Height = 16;
TexIcon[0].PSM = GS_PSM_CT32;
TexIcon[0].Mem = (void *)icon_folder;
gsGlobal->CurrentPointer = 0x280000;
TexIcon[0].Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(TexIcon[0].Width, TexIcon[0].Height, TexIcon[0].PSM), GSKIT_ALLOC_USERBUFFER);
TexIcon[0].Filter = GS_FILTER_LINEAR;
gsKit_texture_upload(gsGlobal, &TexIcon[0]);
free(TexIcon[0].Mem);
TexIcon[1].Width = 16;
TexIcon[1].Height = 16;
TexIcon[1].PSM = GS_PSM_CT32;
TexIcon[1].Mem = (void *)icon_warning;
gsGlobal->CurrentPointer = 0x284000;
TexIcon[1].Vram = gsKit_vram_alloc(gsGlobal, gsKit_texture_size(TexIcon[0].Width, TexIcon[0].Height, TexIcon[0].PSM), GSKIT_ALLOC_USERBUFFER);
TexIcon[1].Filter = GS_FILTER_LINEAR;
gsKit_texture_upload(gsGlobal, &TexIcon[1]);
free(TexIcon[1].Mem);
}
//--------------------------------------------------------------
int loadFont(char *path_arg)
{
int fd;
if (strlen(path_arg) != 0) {
char FntPath[MAX_PATH];
genFixPath(path_arg, FntPath);
fd = genOpen(FntPath, O_RDONLY);
if (fd < 0) {
genClose(fd);
goto use_default;
} // end if failed open file
genLseek(fd, 0, SEEK_SET);
if (genLseek(fd, 0, SEEK_END) > 4700) {
genClose(fd);
goto use_default;
}
genLseek(fd, 0, SEEK_SET);
u8 FontHeader[100];
genRead(fd, FontHeader, 100);
if ((FontHeader[0] == 0x00) &&
(FontHeader[1] == 0x02) &&
(FontHeader[70] == 0x60) &&
(FontHeader[72] == 0x60) &&
(FontHeader[83] == 0x90)) {
genLseek(fd, 1018, SEEK_SET);
memset(FontBuffer, 0, 32 * 16);
genRead(fd, FontBuffer + 32 * 16, 224 * 16); //.fnt files skip 1st 32 chars
genClose(fd);
return 1;
} else { // end if good fnt file
genClose(fd);
goto use_default;
} // end else bad fnt file
} else { // end if external font file
use_default:
memcpy(FontBuffer, &font_uLE, 4096);
} // end else build-in font
return 0;
}
//------------------------------
//endfunc loadFont
//--------------------------------------------------------------
// Set Skin Brightness
void setBrightness(int Brightness)
{
float adjustBright = 128.0F;
if (Brightness == 50)
adjustBright = 128.0F;
else
adjustBright = (((256.0F / 100.0F) * Brightness) + (32.0F * ((50.0F - Brightness) / 50)));
if (adjustBright <= 16.0F)
adjustBright = 16.0F;
if (adjustBright >= 240.0F)
adjustBright = 240.0F;
BrightColor = GS_SETREG_RGBAQ(adjustBright, adjustBright, adjustBright, 0x80, 0x00);
}
//--------------------------------------------------------------
void clrScr(u64 color)
{
if (testskin == 1) {
setBrightness(setting->Brightness);
gsKit_clear(gsGlobal, GS_SETREG_RGBAQ(0x00, 0x00, 0x00, 0x00, 0x00));
gsKit_prim_sprite_texture(gsGlobal,
&TexSkin, 0, 0, 0, 0,
SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT,
0, BrightColor);
setBrightness(50);
} else {
gsKit_prim_sprite(gsGlobal, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, color);
} /* end else */
}
//--------------------------------------------------------------
void drawScr(void)
{
if (updateScr_2) { //Did we render anything last time
while (Timer() < updateScr_t + 5)
; //if so, delay to complete rendering
}
gsKit_sync_flip(gsGlobal); //Await sync and flip buffers
gsKit_queue_exec(gsGlobal); //Start rendering recent transfers for NEXT time
updateScr_t = Timer(); //Note the time when the rendering started
updateScr_2 = updateScr_1; //Note if this rendering had expected updates
updateScr_1 = 0; //Note that we've nothing expected for next time
} //NB: Apparently the GS keeps rendering while we continue with other work
//--------------------------------------------------------------
void drawFrame(int x1, int y1, int x2, int y2, u64 color)
{
int y_off = (setting->interlace) ? 0 : (y1 & 1);
y1 -= y_off;
y2 -= y_off;
updateScr_1 = 1;
//Top horizontal edge
gsKit_prim_sprite(gsGlobal, x1, y1, x2, y1 + LINE_THICKNESS - 1, 1, color);
//Bottom horizontal
gsKit_prim_sprite(gsGlobal, x1, y2 - LINE_THICKNESS + 1, x2, y2, 1, color);
//Left vertical edge
gsKit_prim_sprite(gsGlobal, x1, y1, x1 + LINE_THICKNESS - 1, y2, 1, color);
//Right vertical edge
gsKit_prim_sprite(gsGlobal, x2 - LINE_THICKNESS + 1, y1, x2, y2, 1, color);
}
//--------------------------------------------------------------
// draw a char using the system font (16x16)
void drawChar(unsigned int c, int x, int y, u64 colour)
{
int i, j, pixBase, pixMask;
u8 *cm;
updateScr_1 = 1;
if (!setting->interlace) {
y = y & -2;
}
if (c >= FONT_COUNT)
c = '_';
if (c > 0xFF) //if char is beyond normal ascii range
cm = &font_uLE[c * 16]; // cm points to special char def in default font
else //else char is inside normal ascii range