-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpg.c
executable file
·1174 lines (1038 loc) · 26.7 KB
/
pg.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
// primitive graphics for Hello World sce
#include <stdio.h>
#include <stdarg.h>
//#include "syscall.h"
#include "main.h"
#include "pg.h"
#include "gbcore/gb.h"
#include "font.c"
#include "fontNaga10.c"
#include "rewind.h"
static unsigned int *GEcmd = (unsigned int *)0x441CC000;
static short *ScreenVertex = (short *)0x441CC100;
static int gecbid = -1;
//variables
#define pg_vramtop ((char *)0x04000000)
long pg_screenmode;
long pg_showframe;
long pg_drawframe;
unsigned long pgc_csr_x[2], pgc_csr_y[2];
unsigned long pgc_fgcolor[2], pgc_bgcolor[2];
char pgc_fgdraw[2], pgc_bgdraw[2];
char pgc_mag[2];
void pgWaitVn(unsigned long count)
{
for (; count>0; --count) {
sceDisplayWaitVblankStart();
}
}
void pgWaitV()
{
sceDisplayWaitVblankStart();
}
char *pgGetVramAddr(unsigned long x,unsigned long y)
{
return pg_vramtop+(pg_drawframe?FRAMESIZE:0)+x*PIXELSIZE*2+y*LINESIZE*2+0x40000000;
// return pg_vramtop+(pg_drawframe?FRAMESIZE:0)+x*PIXELSIZE*2+y*LINESIZE*2;//+0x40000000; //変わらないらしい
}
void pgPrint_drawbg(unsigned long x, unsigned long y, unsigned long color, unsigned long bgcolor, const char *str)
{
while (*str!=0 && x<CMAX_X && y<CMAX_Y) {
pgPutChar(x*8,y*8,color,bgcolor,*str,1,1,1);
str++;
x++;
if (x>=CMAX_X) {
x=0;
y++;
}
}
}
void pgPrintf(unsigned long x,unsigned long y,unsigned long color,const char *str, ...)
{
va_list ap;
char szBuf[512];
va_start(ap, str);
vsprintf(szBuf, str, ap);
va_end(ap);
pgPrint(x,y,color,szBuf);
}
void pgPrint(unsigned long x,unsigned long y,unsigned long color,const char *str)
{
while (*str!=0 && x<CMAX_X && y<CMAX_Y) {
pgPutChar(x*8,y*8,color,0,*str,1,0,1);
str++;
x++;
if (x>=CMAX_X) {
x=0;
y++;
}
}
}
void pgPrint2(unsigned long x,unsigned long y,unsigned long color,const char *str)
{
while (*str!=0 && x<CMAX2_X && y<CMAX2_Y) {
pgPutChar(x*16,y*16,color,0,*str,1,0,2);
str++;
x++;
if (x>=CMAX2_X) {
x=0;
y++;
}
}
}
void pgPrint4(unsigned long x,unsigned long y,unsigned long color,const char *str)
{
while (*str!=0 && x<CMAX4_X && y<CMAX4_Y) {
pgPutChar(x*32,y*32,color,0,*str,1,0,4);
str++;
x++;
if (x>=CMAX4_X) {
x=0;
y++;
}
}
}
void pgDrawFrame(unsigned long x1, unsigned long y1, unsigned long x2, unsigned long y2, unsigned long color)
{
unsigned char *vptr0; //pointer to vram
unsigned long i;
vptr0=(unsigned char *)pgGetVramAddr(0,0);
for(i=x1; i<=x2; i++){
((unsigned short *)vptr0)[i*PIXELSIZE + y1*LINESIZE] = color;
((unsigned short *)vptr0)[i*PIXELSIZE + y2*LINESIZE] = color;
}
for(i=y1; i<=y2; i++){
((unsigned short *)vptr0)[x1*PIXELSIZE + i*LINESIZE] = color;
((unsigned short *)vptr0)[x2*PIXELSIZE + i*LINESIZE] = color;
}
}
void pgFillBox(unsigned long x1, unsigned long y1, unsigned long x2, unsigned long y2, unsigned long color)
{
unsigned char *vptr0; //pointer to vram
unsigned long i, j, tmp;
if (x1 > x2){
tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2){
tmp = y1;
y1 = y2;
y2 = tmp;
}
vptr0=(unsigned char *)pgGetVramAddr(0,0);
for(i=y1; i<=y2; i++){
for(j=x1; j<=x2; j++){
((unsigned short *)vptr0)[j*PIXELSIZE + i*LINESIZE] = color;
}
}
}
void pgFillvram(unsigned long color)
{
unsigned char *vptr0; //pointer to vram
unsigned long i;
vptr0=(unsigned char *)pgGetVramAddr(0,0);
for (i=0; i<FRAMESIZE/2; i++) {
*(unsigned short *)vptr0=color;
vptr0+=PIXELSIZE*2;
}
}
void pgBitBlt(unsigned long x,unsigned long y,unsigned long w,unsigned long h,unsigned long mag,const unsigned short *d)
{
unsigned char *vptr0; //pointer to vram
unsigned char *vptr; //pointer to vram
unsigned long xx,yy,mx,my;
const unsigned short *dd;
vptr0=(unsigned char *)pgGetVramAddr(x,y);
for (yy=0; yy<h; yy++) {
for (my=0; my<mag; my++) {
vptr=vptr0;
dd=d;
for (xx=0; xx<w; xx++) {
for (mx=0; mx<mag; mx++) {
*(unsigned short *)vptr=*dd;
vptr+=PIXELSIZE*2;
}
dd++;
}
vptr0+=LINESIZE*2;
}
d+=w;
}
}
void pgBitBltSgb(unsigned long x,unsigned long y,unsigned long *d)
{
unsigned long *v0; //pointer to vram
unsigned long yy;
v0=(unsigned long *)pgGetVramAddr(x,y);
for (yy=0; yy<224; yy++) {
__memcpy4(v0,d,256/2);
v0+=256/2;
d+=256/2;
v0+=(LINESIZE/2-256/2);
}
}
//ちょい早いx1 - LCK
void pgBitBltN1(unsigned long x,unsigned long y,unsigned long *d)
{
unsigned long *v0; //pointer to vram
unsigned long yy;
v0=(unsigned long *)pgGetVramAddr(x,y);
d+=GUARD_LINE/2;
for (yy=0; yy<144; yy++) {
__memcpy4(v0,d,80);
d+=80;
v0+=80;
v0+=(LINESIZE/2-80);
d+=GUARD_LINE;
}
}
//あんまり変わらないx1.5 -LCK
void pgBitBltN15(unsigned long x,unsigned long y,unsigned long *d)
{
unsigned short *vptr0; //pointer to vram
unsigned short *vptr; //pointer to vram
unsigned long xx,yy;
vptr0=(unsigned short *)pgGetVramAddr(x,y);
d+=GUARD_LINE/2;
for (yy=0; yy<72; yy++) {
unsigned long *d0=d+(yy*2)*SIZE_LINE/2;
vptr=vptr0;
for (xx=0; xx<80; xx++) {
unsigned long dd1,dd2,dd3,dd4;
unsigned long dw;
dw=d0[0];
dd1=((vptr[0] =((dw) & 0x739c))) ;
dd2=((vptr[2] =((dw>>16) & 0x739c))) ;
dw=d0[SIZE_LINE/2];
dd3=((vptr[0+LINESIZE*2]=((dw) & 0x739c))) ;
dd4=((vptr[2+LINESIZE*2]=((dw>>16) & 0x739c))) ;
vptr++;
*vptr=(dd1+dd2) >> 1;
vptr+=(LINESIZE-1);
*vptr=(dd1+dd3) >> 1;
vptr++;
*vptr=(dd1+dd2+dd3+dd4) >> 2;
vptr++;
*vptr=(dd2+dd4) >> 1;
vptr+=(LINESIZE-1);
*vptr=(dd3+dd4) >> 1;
vptr+=(2-LINESIZE*2);
d0+=1;
}
vptr0+=LINESIZE*3;
}
}
//よくわかんないx2 - LCK
void pgBitBltN2(unsigned long x,unsigned long y,unsigned long h,unsigned long *d)
{
unsigned long *v0; //pointer to vram
unsigned long xx,yy;
unsigned long dx,dl[2];
v0=(unsigned long *)pgGetVramAddr(x,y);
d+=(SIZE_LINE*4+GUARD_LINE)/2;
for (yy=h; yy>0; --yy) {
for (xx=80; xx>0; --xx) {
dx=*(d++);
// dl[0]=( (dx&0x0000ffff)|((dx&0x0000ffff)<<16) );
// dl[1]=( (dx&0xffff0000)|((dx&0xffff0000)>>16) );
cpy2x(dl,dx);
v0[LINESIZE/2]=dl[0];
v0[LINESIZE/2+1]=dl[1];
*(v0++)=dl[0];
*(v0++)=dl[1];
}
v0+=(LINESIZE-160);
d+=GUARD_LINE;
}
}
//by z-rwt
void pgBitBltStScan(unsigned long x,unsigned long y,unsigned long h,unsigned long *d)
{
unsigned long *v0; //pointer to vram
unsigned long xx,yy;
unsigned long dx;
v0=(unsigned long *)pgGetVramAddr(x,y);
d+=(SIZE_LINE*4+GUARD_LINE)/2;
for (yy=h; yy>0; --yy) {
for (xx=80; xx>0; --xx) {
dx=*(d++);
// d0=( (dx&0x0000ffff)|((dx&0x0000ffff)<<16) );
// d1=( (dx&0xffff0000)|((dx&0xffff0000)>>16) );
// *(v0++)=d0;
// *(v0++)=d1;
cpy2x(v0,dx);
v0+=2;
}
v0+=(LINESIZE-160);
d+=GUARD_LINE;
}
}
//by z-rwt
void pgBitBltSt2wotop(unsigned long x,unsigned long y,unsigned long h,unsigned long *d)
{
unsigned long *v0; //pointer to vram
unsigned long xx,yy;
unsigned long dx,dl[2];
v0=(unsigned long *)pgGetVramAddr(x,y);
d+=GUARD_LINE/2;
for (yy=0; yy<16; yy++){
for (xx=80; xx>0; --xx) {
dx=*(d++);
// d0=( (dx&0x0000ffff)|((dx&0x0000ffff)<<16) );
// d1=( (dx&0xffff0000)|((dx&0xffff0000)>>16) );
// *(v0++)=d0;
// *(v0++)=d1;
cpy2x(v0,dx);
v0+=2;
}
v0+=(LINESIZE/2-160);
d+=GUARD_LINE;
}
for (; yy<h; yy++) {
for (xx=80; xx>0; --xx) {
dx=*(d++);
// dl[0]=( (dx&0x0000ffff)|((dx&0x0000ffff)<<16) );
// dl[1]=( (dx&0xffff0000)|((dx&0xffff0000)>>16) );
cpy2x(dl,dx);
v0[LINESIZE/2]=dl[0];
v0[LINESIZE/2+1]=dl[1];
*(v0++)=dl[0];
*(v0++)=dl[1];
}
v0+=(LINESIZE-160);
d+=GUARD_LINE;
}
}
//by z-rwt
void pgBitBltSt2wobot(unsigned long x,unsigned long y,unsigned long h,unsigned long *d)
{
unsigned long *v0; //pointer to vram
unsigned long xx,yy;
unsigned long dx,dl[2];
v0=(unsigned long *)pgGetVramAddr(x,y);
d+=GUARD_LINE/2;
for (yy=0; yy<h-16; yy++){
for (xx=80; xx>0; --xx) {
dx=*(d++);
// dl[0]=( (dx&0x0000ffff)|((dx&0x0000ffff)<<16) );
// dl[1]=( (dx&0xffff0000)|((dx&0xffff0000)>>16) );
cpy2x(dl,dx);
v0[LINESIZE/2]=dl[0];
v0[LINESIZE/2+1]=dl[1];
*(v0++)=dl[0];
*(v0++)=dl[1];
}
v0+=(LINESIZE-160);
d+=GUARD_LINE;
}
for (; yy<h; yy++) {
for (xx=80; xx>0; --xx) {
dx=*(d++);
// d0=( (dx&0x0000ffff)|((dx&0x0000ffff)<<16) );
// d1=( (dx&0xffff0000)|((dx&0xffff0000)>>16) );
// *(v0++)=d0;
// *(v0++)=d1;
cpy2x(v0,dx);
v0+=2;
}
v0+=(LINESIZE/2-160);
d+=GUARD_LINE;
}
}
//Parallel blend
static inline unsigned long PBlend(unsigned long c0, unsigned long c1)
{
return (c0 & c1) + (((c0 ^ c1) & 0x7bde7bde) >> 1);
}
//2x Fit
void pgBitBltSt2Fix(unsigned long x,unsigned long y,unsigned long h,unsigned long mag,const unsigned short *d)
{
unsigned long *vptr0; //pointer to vram
unsigned long *vptr; //pointer to vram
unsigned long xx, yy;
unsigned short er, f, hf;
unsigned long *dl;
f = hf = 0;
er = SCREEN_HEIGHT;
vptr0 = (unsigned long*)pgGetVramAddr(x, 0);
d+=GUARD_LINE;
for(yy = 0; yy < SCREEN_HEIGHT; yy++) {
vptr = vptr0;
dl = (unsigned long *)d;
if(hf == 0) {
for(xx = 80; xx > 0; xx--) {
cpy2x(vptr, *dl++);
vptr+=2;
}
} else {
for(xx = 80; xx > 0; xx--) {
cpy2x(vptr, PBlend(*(dl-SIZE_LINE/2), *dl));
dl++;
vptr+=2;
}
hf = 0;
}
vptr0 += LINESIZE/2;
er += 15;
if(er > SCREEN_HEIGHT - 3 && f == 0) {
er -= SCREEN_HEIGHT - 2;
f++;
hf = 1;
}
f++;
if(f > 1) {
f -= 2;
d += SIZE_LINE;
}
}
}
//Full
void pgBitBltStFull(unsigned long x,unsigned long y,unsigned long h,unsigned long mag,const unsigned short *d)
{
unsigned long *vptr0; //pointer to vram
unsigned long xx, yy;
unsigned short er, f, hf;
unsigned long *dl;
f = hf = 0;
er = SCREEN_HEIGHT;
vptr0 = (unsigned long*)pgGetVramAddr(0, 0);
d+=GUARD_LINE;
for(yy = SCREEN_HEIGHT; yy > 0 ; yy--) {
dl = (unsigned long *)d;
if(hf == 0) {
for(xx = 80; xx > 0; xx--) {
cpy3x(vptr0, *dl++);
vptr0+=3;
}
} else {
for(xx = 80; xx > 0; xx--) {
cpy3x(vptr0, PBlend(*(dl-SIZE_LINE/2), *dl));
dl++;
vptr0+=3;
}
hf = 0;
}
vptr0 += (LINESIZE -160*3)/2;
er += 15;
if(er > SCREEN_HEIGHT - 3 && f == 0) {
er -= SCREEN_HEIGHT - 2;
f++;
hf = 1;
}
f++;
if(f > 1) {
f -= 2;
d += SIZE_LINE;
}
}
}
void pgBitBltGe(int x, int y, int w, int h, const unsigned short *d)
{
static int qid = -1;
ScreenVertex[2] = x;
ScreenVertex[3] = y;
ScreenVertex[7] = x+w-1;
ScreenVertex[8] = y+h-1;
GEcmd[ 0] = 0x9C000000UL | ((u32)(unsigned char *)pgGetVramAddr( 0, 0 ) & 0x00FFFFFF);
GEcmd[ 2] = 0xA0000000UL | ((u32)(unsigned char *)d & 0x00FFFFFF);
GEcmd[ 3] = 0xA8000000UL | (((u32)(unsigned char *)d & 0xFF000000) >> 8) | SIZE_LINE;
sceKernelDcacheWritebackAll();
qid = sceGeListEnQueue(&GEcmd[0], &GEcmd[14], gecbid, NULL);
if (qid >= 0) sceGeListSync(qid, 0);
}
void pgPutChar(unsigned long x,unsigned long y,unsigned long color,unsigned long bgcolor,unsigned char ch,char drawfg,char drawbg,char mag)
{
unsigned char *vptr0; //pointer to vram
unsigned char *vptr; //pointer to vram
const unsigned char *cfont; //pointer to font
unsigned long cx,cy;
unsigned long b;
char mx,my;
cfont=font+ch*8;
vptr0=(unsigned char *)pgGetVramAddr(x,y);
for (cy=0; cy<8; cy++) {
for (my=0; my<mag; my++) {
vptr=vptr0;
b=0x80;
for (cx=0; cx<8; cx++) {
for (mx=0; mx<mag; mx++) {
if ((*cfont&b)!=0) {
if (drawfg) *(unsigned short *)vptr=color;
} else {
if (drawbg) *(unsigned short *)vptr=bgcolor;
}
vptr+=PIXELSIZE*2;
}
b=b>>1;
}
vptr0+=LINESIZE*2;
}
cfont++;
}
}
void pgScreenFrame(long mode,long frame)
{
pg_screenmode=mode;
frame=(frame?1:0);
pg_showframe=frame;
if (mode==0) {
//screen off
pg_drawframe=frame;
sceDisplaySetFrameBuf(0,0,0,1);
} else if (mode==1) {
//show/draw same
pg_drawframe=frame;
sceDisplaySetFrameBuf(pg_vramtop+(pg_showframe?FRAMESIZE:0),LINESIZE,PIXELSIZE,1);
} else if (mode==2) {
//show/draw different
pg_drawframe=(frame?0:1);
sceDisplaySetFrameBuf(pg_vramtop+(pg_showframe?FRAMESIZE:0),LINESIZE,PIXELSIZE,1);
}
}
void pgScreenFlip()
{
#ifdef MAX_MEMORY_ESTIMATION
test_available_memory();
#endif
pg_showframe=(pg_showframe?0:1);
pg_drawframe=(pg_drawframe?0:1);
sceDisplaySetFrameBuf(pg_vramtop+(pg_showframe?FRAMESIZE:0),LINESIZE,PIXELSIZE,0);
}
void pgScreenFlipV()
{
pgWaitV();
pgScreenFlip();
}
// by kwn
void Draw_Char_Hankaku(int x,int y,const unsigned char c,int col) {
unsigned short *vr;
unsigned char *fnt;
unsigned char pt;
unsigned char ch;
int x1,y1;
ch = c;
// mapping
if (ch<0x20)
ch = 0;
else if (ch<0x80)
ch -= 0x20;
else if (ch<0xa0)
ch = 0;
else
ch -= 0x40;
fnt = (unsigned char *)&hankaku_font10[ch*10];
// draw
vr = (unsigned short *)pgGetVramAddr(x,y);
for(y1=0;y1<10;y1++) {
pt = *fnt++;
for(x1=0;x1<5;x1++) {
if (pt & 1)
*vr = col;
vr++;
pt = pt >> 1;
}
vr += LINESIZE-5;
}
}
// by kwn
void Draw_Char_Zenkaku(int x,int y,const unsigned char u,unsigned char d,int col) {
// ELISA100.FNTに存在しない文字
const unsigned short 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
};
unsigned short *vr;
unsigned short *fnt;
unsigned short pt;
int x1,y1;
unsigned long n;
unsigned short code;
int i;
// SJISコードの生成
code = u;
code = (code<<8) + d;
// SJISからEUCに変換
if(code >= 0xE000) code-=0x4000;
code = ((((code>>8)&0xFF)-0x81)<<9) + (code&0x00FF);
if((code & 0x00FF) >= 0x80) code--;
if((code & 0x00FF) >= 0x9E) code+=0x62;
else code-=0x40;
code += 0x2121 + 0x8080;
// EUCから恵梨沙フォントの番号を生成
n = (((code>>8)&0xFF)-0xA1)*(0xFF-0xA1)
+ (code&0xFF)-0xA1;
i=0;
while(font404[i]) {
if(code >= font404[i]) {
if(code <= font404[i]+font404[i+1]-1) {
n = -1;
break;
} else {
n-=font404[i+1];
}
}
i+=2;
}
fnt = (unsigned short *)&zenkaku_font10[n*10];
// draw
vr = (unsigned short *)pgGetVramAddr(x,y);
for(y1=0;y1<10;y1++) {
pt = *fnt++;
for(x1=0;x1<10;x1++) {
if (pt & 1)
*vr = col;
vr++;
pt = pt >> 1;
}
vr += LINESIZE-10;
}
}
// by kwn
void mh_print(int x,int y,const char *msg,int col) {
int xx = x;
unsigned char ch = 0,bef = 0, *str=(unsigned char*)msg;
while(*str != 0) {
ch = *str++;
if (bef!=0) {
Draw_Char_Zenkaku(x,y,bef,ch,col);
x+=10;
bef=0;
} else {
if (((ch>=0x80) && (ch<0xa0)) || (ch>=0xe0)) {
bef = ch;
} else {
if (ch=='\n'){
x=xx;
y+=10;
}else{
Draw_Char_Hankaku(x,y,ch,col);
x+=5;
}
}
}
if (x>=480) break;
}
}
u32 new_pad;
u32 old_pad;
u32 now_pad;
ctrl_data_t paddata;
void readpad(void)
{
static int n=0;
ctrl_data_t paddata;
sceCtrlReadBufferPositive(&paddata, 1);
// kmg
// Analog pad state
if (paddata.analog[CTRL_ANALOG_Y] == 0xff) paddata.buttons=CTRL_DOWN; // DOWN
if (paddata.analog[CTRL_ANALOG_Y] == 0x00) paddata.buttons=CTRL_UP; // UP
if (paddata.analog[CTRL_ANALOG_X] == 0x00) paddata.buttons=CTRL_LEFT; // LEFT
if (paddata.analog[CTRL_ANALOG_X] == 0xff) paddata.buttons=CTRL_RIGHT; // RIGHT
now_pad = paddata.buttons;
new_pad = now_pad & ~old_pad;
if(old_pad==now_pad){
n++;
if(n>=25){
new_pad=now_pad;
n = 20;
}
}else{
n=0;
old_pad = now_pad;
}
}
/******************************************************************************/
void pgcLocate(unsigned long x, unsigned long y)
{
if (x>=CMAX_X) x=0;
if (y>=CMAX_Y) y=0;
pgc_csr_x[pg_drawframe?1:0]=x;
pgc_csr_y[pg_drawframe?1:0]=y;
}
void pgcColor(unsigned long fg, unsigned long bg)
{
pgc_fgcolor[pg_drawframe?1:0]=fg;
pgc_bgcolor[pg_drawframe?1:0]=bg;
}
void pgcDraw(char drawfg, char drawbg)
{
pgc_fgdraw[pg_drawframe?1:0]=drawfg;
pgc_bgdraw[pg_drawframe?1:0]=drawbg;
}
void pgcSetmag(char mag)
{
pgc_mag[pg_drawframe?1:0]=mag;
}
void pgcCls()
{
pgFillvram(pgc_bgcolor[pg_drawframe]);
pgcLocate(0,0);
}
void pgcPutchar_nocontrol(const char ch)
{
pgPutChar(pgc_csr_x[pg_drawframe]*8, pgc_csr_y[pg_drawframe]*8, pgc_fgcolor[pg_drawframe], pgc_bgcolor[pg_drawframe], ch, pgc_fgdraw[pg_drawframe], pgc_bgdraw[pg_drawframe], pgc_mag[pg_drawframe]);
pgc_csr_x[pg_drawframe]+=pgc_mag[pg_drawframe];
if (pgc_csr_x[pg_drawframe]>CMAX_X-pgc_mag[pg_drawframe]) {
pgc_csr_x[pg_drawframe]=0;
pgc_csr_y[pg_drawframe]+=pgc_mag[pg_drawframe];
if (pgc_csr_y[pg_drawframe]>CMAX_Y-pgc_mag[pg_drawframe]) {
pgc_csr_y[pg_drawframe]=CMAX_Y-pgc_mag[pg_drawframe];
// pgMoverect(0,pgc_mag[pg_drawframe]*8,SCREEN_WIDTH,SCREEN_HEIGHT-pgc_mag[pg_drawframe]*8,0,0);
}
}
}
void pgcPutchar(const char ch)
{
if (ch==0x0d) {
pgc_csr_x[pg_drawframe]=0;
return;
}
if (ch==0x0a) {
if ((++pgc_csr_y[pg_drawframe])>=CMAX_Y) {
pgc_csr_y[pg_drawframe]=CMAX_Y-1;
// pgMoverect(0,8,SCREEN_WIDTH,SCREEN_HEIGHT-8,0,0);
}
return;
}
pgcPutchar_nocontrol(ch);
}
void pgcPuthex2(const unsigned long s)
{
char ch;
ch=((s>>4)&0x0f);
pgcPutchar((ch<10)?(ch+0x30):(ch+0x40-9));
ch=(s&0x0f);
pgcPutchar((ch<10)?(ch+0x30):(ch+0x40-9));
}
void pgcPuthex8(const unsigned long s)
{
pgcPuthex2(s>>24);
pgcPuthex2(s>>16);
pgcPuthex2(s>>8);
pgcPuthex2(s);
}
/******************************************************************************/
void pgiInit()
{
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(1);
}
/******************************************************************************/
int pgaOutBlocking(unsigned long channel,unsigned long vol1,unsigned long vol2,void *buf);
#define PGA_CHANNELS 1
#define PGA_SAMPLES 256
#define MAXVOLUME 0x8000
int pga_ready=0;
int pga_handle[PGA_CHANNELS];
short pga_sndbuf[PGA_CHANNELS][2][PGA_SAMPLES][2];
void (*pga_channel_callback[PGA_CHANNELS])(void *buf, unsigned long reqn);
int pga_threadhandle[PGA_CHANNELS];
volatile int pga_terminate=0;
static int pga_channel_thread(int args, void *argp)
{
volatile int bufidx=0;
int channel=*(int *)argp;
while (pga_terminate==0) {
void *bufptr=&pga_sndbuf[channel][bufidx];
void (*callback)(void *buf, unsigned long reqn);
callback=pga_channel_callback[channel];
if (callback) {
callback(bufptr,PGA_SAMPLES);
} else {
unsigned long *ptr=bufptr;
int i;
for (i=0; i<PGA_SAMPLES; ++i) *(ptr++)=0;
}
pgaOutBlocking(channel,0x8000,0x8000,bufptr);
bufidx=(bufidx?0:1);
}
sceKernelExitThread(0);
return 0;
}
/*
void pga_channel_thread_callback(int channel, void *buf, unsigned long reqn)
{
void (*callback)(void *buf, unsigned long reqn);
callback=pga_channel_callback[channel];
}
*/
void pgaSetChannelCallback(int channel, void *callback)
{
pga_channel_callback[channel]=callback;
}
/******************************************************************************/
int pgaInit()
{
int i,ret;
int failed=0;
char str[32];
pga_terminate=0;
pga_ready=0;
for (i=0; i<PGA_CHANNELS; i++) {
pga_handle[i]=-1;
pga_threadhandle[i]=-1;
pga_channel_callback[i]=0;
}
for (i=0; i<PGA_CHANNELS; i++) {
if ((pga_handle[i]=sceAudioChReserve(-1,PGA_SAMPLES,0))<0) failed=1;
}
if (failed) {
for (i=0; i<PGA_CHANNELS; i++) {
if (pga_handle[i]!=-1) sceAudioChRelease(pga_handle[i]);
pga_handle[i]=-1;
}
return -1;
}
pga_ready=1;
strcpy(str,"pgasnd0");
for (i=0; i<PGA_CHANNELS; i++) {
str[6]='0'+i;
pga_threadhandle[i]=sceKernelCreateThread(str,(SceKernelThreadEntry)&pga_channel_thread,0x12,0x10000,0,NULL);
if (pga_threadhandle[i]<0) {
pga_threadhandle[i]=-1;
failed=1;
break;
}
ret=sceKernelStartThread(pga_threadhandle[i],sizeof(i),&i);
if (ret!=0) {
failed=1;
break;
}
}
if (failed) {
pga_terminate=1;
for (i=0; i<PGA_CHANNELS; i++) {
if (pga_threadhandle[i]!=-1) {
sceKernelWaitThreadEnd(pga_threadhandle[i],NULL);
sceKernelDeleteThread(pga_threadhandle[i]);
}
pga_threadhandle[i]=-1;
}
pga_ready=0;
return -1;
}
return 0;
}
void pgaTermPre()
{
pga_ready=0;
pga_terminate=1;
}
void pgaTerm()
{
int i;
pga_ready=0;
pga_terminate=1;
for (i=0; i<PGA_CHANNELS; i++) {
if (pga_threadhandle[i]!=-1) {
sceKernelWaitThreadEnd(pga_threadhandle[i],NULL);
sceKernelDeleteThread(pga_threadhandle[i]);
}
pga_threadhandle[i]=-1;
}
for (i=0; i<PGA_CHANNELS; i++) {
if (pga_handle[i]!=-1) {
sceAudioChRelease(pga_handle[i]);
pga_handle[i]=-1;
}
}
}
int pgaOutBlocking(unsigned long channel,unsigned long vol1,unsigned long vol2,void *buf)
{
if (!pga_ready) return -1;
if (channel>=PGA_CHANNELS) return -1;
if (vol1>MAXVOLUME) vol1=MAXVOLUME;
if (vol2>MAXVOLUME) vol2=MAXVOLUME;
return sceAudioOutputPannedBlocking(pga_handle[channel],vol1,vol2,buf);
}
//バッファは64バイト境界じゃなくても大丈夫みたい
//[0]が左、[1]が右
//サンプル速度は44100
//vol1が左
/******************************************************************************/
#ifdef USE_GPU
void Ge_Finish_Callback(int id, void *arg)
{