-
Notifications
You must be signed in to change notification settings - Fork 0
/
yar_NY.c
2869 lines (1797 loc) · 60.4 KB
/
yar_NY.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
/*
*
PUBLIC DOMAIN 2022
THIS CODE IS A HACKY MESS - READ IT AT YOUR OWN RISK!
https://github.com/gwald/yarmico
*
*/
#include "yar_NY.h"
#include "yar_API.h"
#define RAND_RAM_START 0xBFC7F000 //0xBFC00000 // start of BIOS area
volatile u8 *g_random = (volatile u8 *)RAND_RAM_START; //RAND_RAM_START; //0xBFC7FF32; // 0x1F801000; // move point 1 char per inc.
void LoadTexture(u32 address);
void RenderFinish( void);
// #define CODEWORRIOR_DEBUGGING 1
#ifdef CODEWORRIOR_DEBUGGING // used for debugging
#ifdef __MWERKS__ // CodeWarrior for NY precompile define
#define __FUNCTION__ "CW NOT SUPPORTED"
#endif // CodeWarrior for NY
#endif //CODEWORRIOR_DEBUGGING
#include <strings.h>
// from: https://stackoverflow.com/questions/6127503/shuffle-array-in-c
// PSX RANDOM
// fixed to NTSC resolutions, HW will control FPS and 2010+ TV's will display what is output
#define YARMICO_SCREEN_border_COLOUR 0,0,0
#define NATIVE_SCREEN_WIDTH_BORDER_START_240X240_256X240 8
#define NATIVE_SCREEN_HEIGHT_BORDER_START_240X240_256X240 0
#define NATIVE_SCREEN_WIDTH_BORDER_START_320X240_256X240 0
#define NATIVE_SCREEN_HEIGHT_BORDER_START_320X240_256X240 0
#define NATIVE_SCREEN_WIDTH_BORDER_START_160X120_256X240 48
#define NATIVE_SCREEN_HEIGHT_BORDER_START_160X120_256X240 60
#define NATIVE_SCREEN_WIDTH_BORDER_START_120X120_256X240 68
#define NATIVE_SCREEN_HEIGHT_BORDER_START_120X120_256X240 60
#if YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_320X240_640X480 //320x240 up scaled
#define NATIVE_SCREEN_WIDTH 640
#define NATIVE_SCREEN_HEIGHT 480
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_320X240 // 320x240 no up scaling
#define NATIVE_SCREEN_WIDTH 320
#define NATIVE_SCREEN_HEIGHT 240
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_240x240 // 240x240 boarded widths
#define NATIVE_SCREEN_WIDTH 256
#define NATIVE_SCREEN_HEIGHT 240
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_160x120 // 160x120 boarded widths and heights
#define NATIVE_SCREEN_WIDTH 256
#define NATIVE_SCREEN_HEIGHT 240
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_120x120 // 120x120 boarded widths and heights
#define NATIVE_SCREEN_WIDTH 256
#define NATIVE_SCREEN_HEIGHT 240
#endif
#define PSX_ANALOG_CENTER 125
#define TRUE 1
#define FALSE 0
#define ORDERING_TABLE_LENGTH 16
#define MAX_NO_PACKETS 64000
long g_CurrentBuffer;
GsOT g_TableHeader [2];
GsOT_TAG TableArray [2][1<<ORDERING_TABLE_LENGTH];
PACKET Packet_Memory [2][MAX_NO_PACKETS];
//rem not needed volatile u_long PAD,PADBUFFER;
volatile u_char *bb0,*bb1;
#ifdef _DEBUG_
#undef YARMICO_PLAY_BGM
#define YARMICO_PLAY_BGM 0 // 1 YES 0 NO
#endif
// PSX DEFINE's
#ifdef _RELEASE_
#define LOG_RAND_ADD // printf
#define LOG_TIMS // printf
#define LOG_DEL // printf
#define LOG_DISP // printf
#define LOG_FUNC // printf
#define LOG_PAD // printf
#define LOG_CDAUDIO // printf
#define LOG_DATA // printf
#define LOG_MAIN //printf
#else
#define LOG_DATA // printf
#define LOG_RAND_ADD // printf
#define LOG_RAND // printf
#define LOG_TIMS // printf
#define LOG_DEL // printf
#define LOG_DISP // printf
#define LOG_FUNC // printf
#define LOG_PAD // printf
#define LOG_CDAUDIO // printf
#define LOG_MAIN printf
#endif
//from SCEI NY card example code
// file: cardio.h
// Copyright (C) 1994,1995 by Sony Computer Entertainment Inc.
typedef struct {
int fileEntry;
char fileName[15][64];
} _FINF;
typedef struct {
char Magic[2];
char Type;
char BlockEntry;
char Title[64];
char reserve[28];
char Clut[32];
char Icon[3][128];
} _CARD;
//from SCEI NY card example code
//NOTE: CW doesn't like TestCard and halts
// #define TestCard 1;//
#define CDAUDIO_MAX 100
#define CDAUDIO_MIN 80
// reverse PSX OT draw order (painters algo) so it's similar to 32blit
#define OT_POS_RECT 6000
#define OT_POS_SPRITE 2000
u32 g_OT_POS_CNT;
#ifdef USE_TPAGE00
GsSPRITE g_TPAGE00;
#endif
#ifdef USE_TPAGE01
GsSPRITE g_TPAGE01;
#endif
#ifdef USE_TPAGE02
GsSPRITE g_TPAGE02;
#endif
#ifdef USE_TPAGE03
GsSPRITE g_TPAGE03;
#endif
#ifdef USE_TPAGE04
GsSPRITE g_TPAGE04;
#endif
#ifdef USE_TPAGE05
GsSPRITE g_TPAGE05;
#endif
GsBOXF g_box={0};
#define SAVE_CHECK_STRING_START YARMICO_PROJECT_TITLE
#define SAVE_CHECK_STRING_END YARMICO_PROJECT_TITLE
//memcard code from SCEI NY card example code
#define MEMCARD_DEVNAME "bu10:"
char *g_memcard_filename=MEMCARD_DEVNAME YARMICO_PROJECT_CODE_STRING;
void exit_to_siocons(void);
// doesn't work
#if 0
#ifndef _RELEASE_
#include <stdarg.h>
u32 yarmico_debugf( char *format, ...)
{
u32 result;
va_list args;
va_start(args, format);
printf(format, args );
va_end(args);
return result;
}
#else // release no debug out
u32 yarmico_debugf( const char *format, ...) {}
#endif
#endif
void _error()
{
printf("memcard error no. _get_errno:%d\n", _get_errno());
// see #include "sys/errno.h"
}
u32 yarmico_save_data( char *data, u32 size)
{
#ifndef __MWERKS__
// struct DIRENTRY d;
long chan;
long n=10;
u_long flag=0;
char buf[512+128]; //_CARD + t_save_data
s32 fd;
//, ret;
_CARD *card;
//long i;
/* 4bit 16x16 ball pattern */
u32 ball16x16[] = {
0x00000000,0x00000000,0x21000000,0x00000332,
0x42110000,0x00055554,0x54321000,0x00677665,
0x65432100,0x07888776,0x76543100,0x09998887,
0x77654210,0x9aa99988,0x87765420,0xabbbaa99,
0x98765420,0xbcccbba9,0x98876530,0xcddddcba,
0xa9876530,0xdeeeddcb,0xa9887500,0x0effeddb,
0xb9987500,0x0efffedc,0xba986000,0x00fffedc,
0xba970000,0x000eeedc,0xa9000000,0x00000dcb
};
u32 ballcolor[8] = {
0x80860000,0x80c980c8,0x812c810a,0x816e814d,
0x81b18190,0x81f481d3,0x821581f4,0x82378216
};
// try to read new bigger new format first, it will fail if it's the old smaller format
#ifndef __MWERKS__
fd = TestCard(1); // slot 2
#else
fd = 0; // slot 2
#endif
/*
0: Card missing
1: Card present
2: New card detected
4: Uninitialized card detected
*/
if(fd == 0)
{
LOG_DATA(" _create() failed TestCard - Card missing\n");
return 0; // failed 0: Card missing
}
// try formating it first
if(fd > 1)
{
char name[32];
LOG_DATA(" amico_load_data() TestCard 2 or 4 - Card needs formating\n");
fd = format(MEMCARD_DEVNAME);
if(fd == 0)
{
LOG_DATA("formating failed on %s format(DevName)\n", MEMCARD_DEVNAME);
return 0;// failed
}
else
{
LOG_DATA("formating OK %s format(DevName)\n", MEMCARD_DEVNAME);
}
}
memcpy( &buf[512],data,128);
fd = open(g_memcard_filename, O_CREAT|(1<<16));
if(fd<0)
{
LOG_DATA("%s just do WO opening\n", g_memcard_filename);
fd = open(g_memcard_filename, O_WRONLY );
if(fd<0)
{
LOG_DATA(" g_memcard_FD _error %s \n", g_memcard_filename);
_error();
return 0;
}
}
LOG_DATA("%s closing\n", g_memcard_filename);
close(fd);
LOG_DATA("%s WO opening\n", g_memcard_filename);
fd = open(g_memcard_filename, O_WRONLY);
LOG_DATA("create file\n\n", g_memcard_filename);
//LOG_DATA("DIRENTRY 40 size - %d\n\n", sizeof(struct DIRENTRY) ); // not used CBS maintaining directories
LOG_DATA("_CARD 512 size - %d\n\n", sizeof(_CARD) );
LOG_DATA("g_saved_data 128 size - %d\n\n", size );
LOG_DATA("create new %s\n", g_memcard_filename);
// assumed card/file already opened and working!
LOG_DATA("%s lseek(fd,0,SEEK_SET);\n", g_memcard_filename);
lseek(fd,0,SEEK_SET);
card=(_CARD *)buf;
card->Magic[0]='S';
card->Magic[1]='C';
card->Type=0x11;
card->BlockEntry=1;
strcpy(card->Title, YARMICO_PROJECT_CODE_STRING);
//strcat(card->Title, file_no);
memcpy(card->Clut,ballcolor,32);
memcpy(card->Icon[0],ball16x16,128);
memcpy(card->Icon[1],ball16x16,128);
write(fd,buf,512+128);
return close(fd);
#else
return 0;
#endif
}
// assumed card already open and file created
u32 yarmico_load_data(char *data, u32 size)
{
#ifndef __MWERKS__
// struct DIRENTRY d;
char buf[512+128]; //_CARD + t_save_data
s32 fd;//, ret;
//_CARD *card;
long i;
//LOG_DATA("DIRENTRY 40 size - %d\n\n", sizeof(struct DIRENTRY) ); // not used CBS maintaining directories
LOG_DATA("g_memcard_filename %s\n\n", g_memcard_filename );
LOG_DATA("g_saved_data 128 size - %d\n\n", size );
// try to read new bigger new format first, it will fail if it's the old smaller format
#ifndef __MWERKS__
fd = TestCard(1); // slot 2
#else
fd = 0; // slot 2
#endif
/*
0: Card missing
1: Card present
2: New card detected
4: Uninitialized card detected
*/
if(fd != 1)
{
LOG_DATA(" amico_load_data() failed TestCard\n");
return 0; // card missing or not formated etc
}
// fd = open(g_memcard_filename, O_CREAT|(1<<16));
fd = open(g_memcard_filename, O_RDONLY );
if(fd<0)
{
LOG_DATA(" g_memcard_FD _error %d \n", fd);
_error();
return 0;
}
LOG_DATA("g_memcard_FD %d lseek(fd,0,SEEK_SET);\n", fd);
lseek(fd,0,SEEK_SET);
i = read(fd,buf,512+128);
LOG_DATA("%d = read(fd,buf,512+128);\n", i);
memcpy( data,&buf[512], 128);
// no closing close(g_memcard_FD);
return close(fd);
#else
return 0;
#endif
}
u32 yarmico_delete_data(u32 slot)
{
#ifndef __MWERKS__
u32 ret = TestCard(1); // slot 2
if(ret == 1)
return delete( g_memcard_filename );
#else
#endif
return 1;
}
// Spirit loading, display res and rendering code mostly 'borrowed' from:
// lib2dh.c
// Hi-res version
// Complete 2D development library
// High performance macros & functions
// Compiled by Harvey Cotton
volatile u_char *bb0,*bb1;
void InitSprite(GsSPRITE *sprite, u32 address, u32 x1, u32 y1)
{
u_long depth1,depth2;
GsIMAGE tim;
printf("InitSprite %#010x\n", address);
LoadTexture(address);
printf("InitSprite GsGetTimInfo %#010x\n", address);
GsGetTimInfo((u_long *)(address+4),&tim);
depth2=4>>(depth1=tim.pmode&3);
printf("InitSprite depth2 %d \n", depth2);
printf("InitSprite tim.pw %d \n", tim.pw);
printf("InitSprite tim.ph %d \n", tim.ph);
sprite->attribute=depth1<<24;
sprite->x=x1;
sprite->y=y1;
sprite->w=tim.pw*depth2;
sprite->h=tim.ph;
sprite->tpage=GetTPage(depth1,0,tim.px,tim.py);
sprite->u=tim.px%64;
sprite->v=tim.py%256;
if (depth1!=2)
{
sprite->cx=tim.cx;
sprite->cy=tim.cy;
}
sprite->r=sprite->g=sprite->b=127;
sprite->mx=(tim.pw*depth2)>>1;
sprite->my=tim.ph>>1;
sprite->scalex=sprite->scaley=ONE;
sprite->rotate=0;
printf("\n end InitSprite \n");
}
// Called before everything is drawn
void RenderPrepare ()
{
LOG_PAD("\n g_CurrentBuffer %d \n", g_CurrentBuffer);
//g_CurrentBuffer=GsGetActiveBuff();
g_CurrentBuffer=!g_CurrentBuffer;
LOG_PAD("\n GsGetActiveBuff %d \n", g_CurrentBuffer);
GsSetWorkBase((PACKET*)Packet_Memory[g_CurrentBuffer]);
LOG_PAD("\n GsSetWorkBase %d \n", g_CurrentBuffer);
GsClearOt(0,0,&g_TableHeader[g_CurrentBuffer]);
LOG_PAD("\n GsClearOt %d \n", g_CurrentBuffer);
#if YARMICO_NATIVE_DISPLAY == YARMICO_NATIVE_DISPLAY_120x120 || YARMICO_NATIVE_DISPLAY == YARMICO_NATIVE_DISPLAY_160x120
#ifdef YARMICO_PICO_SHOW_SIDES
if(g_yarmico_lores_upscale[0] == 0) //do boarders
{
g_box.r = 0;
g_box.g = 0;
g_box.b = 0;
g_box.y = g_box.x = 0;
g_box.w = g_yarmico_lores_upscale[1]; // width
g_box.h = 240;
GsSortBoxFill(&g_box, &g_TableHeader[g_CurrentBuffer], 1000);
g_box.x = 256-g_yarmico_lores_upscale[1]; // width
GsSortBoxFill(&g_box, &g_TableHeader[g_CurrentBuffer], 1000);
g_box.x =0;
g_box.w = 256;
g_box.h = g_yarmico_lores_upscale[2]; // hight
GsSortBoxFill(&g_box, &g_TableHeader[g_CurrentBuffer], 1000);
g_box.y = 240-g_yarmico_lores_upscale[2]; // width
GsSortBoxFill(&g_box, &g_TableHeader[g_CurrentBuffer], 1000);
}
#endif //#ifdef YARMICO_PICO_HIDE_SIDES
#endif //#if YARMICO_NATIVE_DISPLAY == YARMICO_NATIVE_DISPLAY_120x120 || YARMICO_NATIVE_DISPLAY == YARMICO_NATIVE_DISPLAY_160x120
}
// display code borrowed from lib2dh
// Hi-res version
// Complete 2D development library
// High performance macros & functions
// Compiled by Harvey Cotton
// Initialises everything
void InitialiseGraphics (void)
{
// Setup graphics mode
//RenderClear();
// SetVideoMode(VIDEO_MODE); // moved into main()
LOG_MAIN("\n InitialiseGraphics NATIVE_SCREEN_WIDTH %d NATIVE_SCREEN_HEIGHT %d \n", NATIVE_SCREEN_WIDTH, NATIVE_SCREEN_HEIGHT);
printf("\n BIOS found: [%s]", PLAYSTATION_BIOS_INFO() );
printf("\n Using hardware region: %c\n", PLAYSTATION_REGION_CHECK() );
if( PLAYSTATION_REGION_CHECK() == 'E') // if true, it's PAL
{
SetVideoMode(MODE_PAL); // 1=PAL/50Hz with NTSC res
StartRCnt(0); // restart counter to cnter make smaller
printf("*WARNING*\n");
printf("PAL PSX detected, using PAL (50Hz) with NTSC resolution!!\n\n");
}
else
{
// slow down to get new seed
SetVideoMode(MODE_NTSC); // 0=NTSC/60Hz
// SetVideoMode(MODE_PAL); // force PAL mode // 1=PAL/50Hz with NTSC res
printf("NTSC PSX detected.\n");
VSync(0);
DrawSync(0);
}
#if YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_320X240_640X480
GsInitGraph(NATIVE_SCREEN_WIDTH,NATIVE_SCREEN_HEIGHT,GsINTER+GsOFSGPU,0,0);
GsDRAWENV.isbg=1;
GsDRAWENV.dfe=0;
GsDISPENV.isinter=1;
GsDISPENV.isrgb24=0;
#else
GsInitGraph(NATIVE_SCREEN_WIDTH,NATIVE_SCREEN_HEIGHT,GsOFSGPU,1,0);
GsDefDispBuff(0, 0, 0, NATIVE_SCREEN_HEIGHT);
#endif
g_yarmico_lores_upscale[0] = YARMICO_DEFAULT_DISPLAY_UPSCALE;
if(YARMICO_SCREEN_HEIGHT == 120)
{
if(g_yarmico_lores_upscale[0]) // if scale up to 256X240
{
if(YARMICO_SCREEN_WIDTH == 160) // 160 to 256 width
{
g_yarmico_lores_upscale[0] = 6553; //fixed point scale factor 160* 1.6 = 256 so 1.6 * ONE = 6553.6
g_yarmico_lores_upscale[1] = 0;
g_yarmico_lores_upscale[2] = 0;
}
else //120 to 256 width
{
g_yarmico_lores_upscale[0] = 8704; //fixed point scale factor 120×2.133333 =255.99996 4096×2.133333 = 8738.131968 - 8704%32=0
g_yarmico_lores_upscale[1] = 0;
g_yarmico_lores_upscale[2] = 0;
}
}
else // use big borders
{
if(YARMICO_SCREEN_WIDTH == 160)
{
g_yarmico_lores_upscale[1] = NATIVE_SCREEN_WIDTH_BORDER_START_160X120_256X240;
g_yarmico_lores_upscale[2] = NATIVE_SCREEN_HEIGHT_BORDER_START_160X120_256X240;
}
else //120
{
g_yarmico_lores_upscale[1] = NATIVE_SCREEN_WIDTH_BORDER_START_120X120_256X240;
g_yarmico_lores_upscale[2] = NATIVE_SCREEN_HEIGHT_BORDER_START_120X120_256X240;
}
}
}
// g_yarmico_background_color_red = g_yarmico_background_color_green = g_yarmico_background_color_blue = 0;
GsDRAWENV.r0=g_yarmico_background_color_red;
GsDRAWENV.g0=g_yarmico_background_color_green;
GsDRAWENV.b0=g_yarmico_background_color_blue;
/*
GsDRAWENV.clip.x=0;
GsDRAWENV.clip.y=0;
GsDRAWENV.clip.w=NATIVE_SCREEN_WIDTH;
GsDRAWENV.clip.h=NATIVE_SCREEN_HEIGHT;
GsDRAWENV.r0=BG_RED;
GsDRAWENV.g0=BG_GREEN;
GsDRAWENV.b0=BG_BLUE;
GsDRAWENV.isbg=1;
GsDRAWENV.dfe=0;
GsDISPENV.disp.x=0;
GsDISPENV.disp.y=0;
GsDISPENV.disp.w=NATIVE_SCREEN_WIDTH;
GsDISPENV.disp.h=NATIVE_SCREEN_HEIGHT;
GsDISPENV.screen.x=5;
GsDISPENV.screen.w=HALF_WIDTH;
GsDISPENV.screen.h=HALF_HEIGHT;
GsDISPENV.isinter=1;
GsDISPENV.isrgb24=0;
*/
// Initialise ordering table
g_TableHeader[0].length=ORDERING_TABLE_LENGTH;
g_TableHeader[1].length=ORDERING_TABLE_LENGTH;
g_TableHeader[0].org=TableArray[0];
g_TableHeader[1].org=TableArray[1];
// Initialise font - not used
//FntLoad(960,256);
// Initialise control pads
// GetPadBuf(&bb0,&bb1); // moved into main()
}
// Transfer a texture from memory to video ram
void LoadTexture(u32 address)
{
GsIMAGE tim;
RECT rect;
printf("LoadTexture %#010x\n", address);
printf("GsGetTimInfo *(address+4) = %#010x\n", *(u32 *)(address+4) );
DrawSync(0);
GsGetTimInfo((u_long *)(address+4),&tim);
rect.x=tim.px;
rect.y=tim.py;
rect.w=tim.pw;
rect.h=tim.ph;
printf("LoadImage %#010x\n", address);
LoadImage(&rect,tim.pixel);
printf("DrawSync %#010x\n", address);
DrawSync(0);
if ((tim.pmode>>3)&0x01)
{
rect.x=tim.cx;
rect.y=tim.cy;
rect.w=tim.cw;
rect.h=tim.ch;
printf("LoadImage clut %#010x\n", address);
LoadImage(&rect,tim.clut);
printf("DrawSync %#010x\n", address);
DrawSync(0);
}
printf("DrawSync %#010x\n", address);
//DrawSync(0);
printf("LoadTexture exit %#010x\n", address);
}
// Wipes screen and ordering tables
void RenderClear ()
{
RECT temp={0,0,NATIVE_SCREEN_WIDTH,NATIVE_SCREEN_HEIGHT};
GsDRAWENV.r0=0;
GsDRAWENV.g0=0;
GsDRAWENV.b0=0;
ClearImage(&temp,g_yarmico_background_color_red,g_yarmico_background_color_green,g_yarmico_background_color_blue);
GsClearOt(0,0,&g_TableHeader[0]);
GsClearOt(0,0,&g_TableHeader[1]);
GsSortClear(g_yarmico_background_color_red,g_yarmico_background_color_green,g_yarmico_background_color_blue,&g_TableHeader[0]);
GsSortClear(g_yarmico_background_color_red,g_yarmico_background_color_green,g_yarmico_background_color_blue,&g_TableHeader[1]);
DrawSync(0);
//ResetGraph(0);
RenderFinish();
ClearImage(&temp,g_yarmico_background_color_red,g_yarmico_background_color_green,g_yarmico_background_color_blue);
GsClearOt(0,0,&g_TableHeader[0]);
GsClearOt(0,0,&g_TableHeader[1]);
GsSortClear(g_yarmico_background_color_red,g_yarmico_background_color_green,g_yarmico_background_color_blue,&g_TableHeader[0]);
GsSortClear(g_yarmico_background_color_red,g_yarmico_background_color_green,g_yarmico_background_color_blue,&g_TableHeader[1]);
// DrawSync(0);
//issues with the pad data?
// bb0 = bb1 = (volatile u_char *) NULL;
// GetPadBuf(&bb0,&bb1);
}
// Called after everything is drawn
void RenderFinish( void)
{
//FntPrint(0, "\n VSYNC:%d\n",VSync(0));
#if NATIVE_SCREEN_WIDTH != 640
VSync(0);
DrawSync(0);
#endif
//ResetGraph(1);
GsSwapDispBuff();
//clear automatically done via GsDRAWENV
#if NATIVE_SCREEN_WIDTH != 640
GsSortClear(g_yarmico_background_color_red,g_yarmico_background_color_green,g_yarmico_background_color_blue,&g_TableHeader[g_CurrentBuffer]);
#endif
GsDrawOt(&g_TableHeader[g_CurrentBuffer]);
// FntFlush(-1);
g_OT_POS_CNT=0;
}
// save to:
void yarmico_rectangle(u8 r, u8 g, u8 b, u32 screen_posX, u32 screen_posY, u32 w, u32 h )
{
g_box.r = r;
g_box.g = g;
g_box.b = b;
{ // SCREEN RES / SCALING
#if YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_320X240_640X480 // up scaling
g_box.x = screen_posX << 1; //times 2 for hi res
g_box.y = screen_posY << 1; //times 2 for hi res
g_box.w = w << 1; //times 2 for hi res
g_box.h = h << 1; //times 2 for hi res
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_320X240// no scaling
tim->x = screen_posX;
tim->y = screen_posY;
g_box.w = w;
g_box.h = h;
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_240x240// no scaling with borders
g_box.x = screen_posX ;
g_box.y = screen_posY;
g_box.x +=NATIVE_SCREEN_WIDTH_BORDER_START_240X240_256X240;
g_box.y +=NATIVE_SCREEN_HEIGHT_BORDER_START_240X240_256X240;
g_box.w = w;
g_box.h = h;
#else
if(g_yarmico_lores_upscale[0]==0)// no scaling up
{
g_box.x = screen_posX;
g_box.y = screen_posY;
g_box.x +=g_yarmico_lores_upscale[1];
g_box.y +=g_yarmico_lores_upscale[2];
g_box.w = w;
g_box.h = h;
}
else
{
g_box.x = (screen_posX *g_yarmico_lores_upscale[0])/ONE;//(screen_posX *g_yarmico_lores_upscale[0]); //times to 256 W
g_box.y = screen_posY << 1; //times 2 to 240
// g_box.w = (w *g_yarmico_lores_upscale[0]); //times 2 for hi res
g_box.w = (w *g_yarmico_lores_upscale[0])>>12; // /ONE; //times 2 for hi res
g_box.h = (h << 1) ; //times 2 for hi res
}
#endif
} // SCREEN RES / SCALING
#if 0 //old
//g_yarmico_scale
#if YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_320X240_640X480// up scaling
g_box.x = screen_posX << 1; //times 2 for hi res
g_box.y = screen_posY << 1; //times 2 for hi res
g_box.w = w << 1; //times 2 for hi res
g_box.h = h << 1; //times 2 for hi res
#else
g_box.x = screen_posX ; //times 2 for hi res
g_box.y = screen_posY; //times 2 for hi res
g_box.w = w ; //times 2 for hi res
g_box.h = h ; //times 2 for hi res
#if DISPLAY_TARGET > YARMICO_HIRES1 // boarded
g_box.x +=NATIVE_SCREEN_WIDTH_START;
g_box.y +=NATIVE_SCREEN_HEIGHT_START;
#endif
#endif //old
#endif
GsSortBoxFill(&g_box, &g_TableHeader[g_CurrentBuffer], OT_POS_RECT-g_OT_POS_CNT);
g_OT_POS_CNT++;
LOG_DISP("\n GsSortBoxFill yarmico_rectangle yarmico_rectangle yarmico_rectangle %d \n",!(w&1));
}
void yarmico_sprite(u8 tpage, u32 texture_u, u32 texture_v, u32 texture_w, u32 texture_h, s32 posX, s32 posY, s32 scale , u8 h_flip, u8 v_flip)
{
GsSPRITE *tim;
u32 scale_flip;
LOG_DISP("yarmico_sprite func: TPAGE %d texture_u %d texture_v %d texture_w %d texture_h %d posX %d posY %d scale %d \n", tpage, texture_u, texture_v , texture_w , texture_h , posX , posY , scale );
//scale *=2;
//scale -= 100;